# -*- coding: utf-8 -*- from django.conf import settings from photologue.forms import PhotoForm from models import Organiser from theme.models import Tag from forms import OrganiserForm, OrganiserFilterForm from functions.admin_views import AdminListView, AdminView class OrganiserListView(AdminListView): template_name = 'admin/organiser/organiser_list.html' form_class = OrganiserFilterForm model = Organiser class OrganiserView(AdminView): form_class = OrganiserForm model = Organiser success_url = '/admin/organiser/all/' template_name = 'admin/organiser/organiser.html' def get_form(self, form_class): if self.request.POST: return super(OrganiserView, self).get_form(form_class) obj = self.set_obj() if obj: data = {'staff_number':obj.staff_number, 'address': obj.address, 'events_number':obj.events_number, 'phone':obj.phone, 'fax':obj.fax, 'web_page':obj.web_page, 'url':obj.url, 'email':obj.email, 'foundation': obj.foundation} if obj.country: data['country'] = obj.country_id if obj.city: data['city'] = obj.city_id data['theme'] = [item.id for item in obj.theme.all()] data['tag'] = ','.join(['%s:%s'%(item.id, item.name) for item in obj.tag.all()]) data['place_exposition'] = [item.id for item in obj.place_exposition.all()] data['place_conference'] = [item.id for item in obj.place_conference.all()] for code, name in settings.LANGUAGES: trans_obj = self.model._meta.translations_model.objects.get(language_code = code,master__id=obj.id) #access to translated fields data['name_%s' % code] = trans_obj.name data['description_%s' % code] = trans_obj.description data['specialization_%s' % code] = trans_obj.specialization data['address_inf_%s' % code] = trans_obj.address_inf data['representation_%s' % code] = trans_obj.representation data['title_%s' % code] = trans_obj.title data['keywords_%s' % code] = trans_obj.keywords data['descriptions_%s' % code] = trans_obj.descriptions form =form_class(initial=data) form.fields['city'].widget.attrs['data-init-text'] = obj.city.name form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] return form else: return form_class() def get_context_data(self, **kwargs): context = super(OrganiserView, self).get_context_data(**kwargs) context['photo_form'] = PhotoForm() return context