diff --git a/conference/admin.py b/conference/admin.py index f0f6a20d..af2f95c5 100644 --- a/conference/admin.py +++ b/conference/admin.py @@ -313,3 +313,14 @@ def search_conf(request): result = [{'id': item.pk, 'label': get_by_lang(item, 'name', lang)} for item in qs] return HttpResponse(json.dumps(result), content_type='application/json') + + +def conf_copy(request): + response = {'redirect': ''} + conf = Conference.objects.get(id=request.GET['id']) + duplicate = conf.copy(request.GET['url']) + if isinstance(duplicate, Conference): + response['redirect'] = '/admin/conference/%s/'%duplicate.url + else: + response['msg'] = duplicate + return HttpResponse(json.dumps(response), content_type='application/json') diff --git a/conference/admin_urls.py b/conference/admin_urls.py index 2b8cc0df..5abc9dd7 100644 --- a/conference/admin_urls.py +++ b/conference/admin_urls.py @@ -5,6 +5,7 @@ from admin import ConferenceListView, ConferenceView urlpatterns = patterns('conference.admin', url(r'^upload-photo/(?P.*)/$', 'upload_conference_photo'), url(r'^delete/(?P.*)$', 'conference_delete'), + url(r'^copy/$', 'conf_copy'), url(r'^all/$', ConferenceListView.as_view()), #url(r'^change/(?P.*)/$', 'conference_change'), diff --git a/exposition/admin.py b/exposition/admin.py index 3d1d2c3c..0345864a 100644 --- a/exposition/admin.py +++ b/exposition/admin.py @@ -404,3 +404,12 @@ class PaidView(FormView): +def expo_copy(request): + response = {'redirect': ''} + expo = Exposition.objects.get(id=request.GET['id']) + duplicate = expo.copy(request.GET['url']) + if isinstance(duplicate, Exposition): + response['redirect'] = '/admin/exposition/%s/'%duplicate.url + else: + response['msg'] = duplicate + return HttpResponse(json.dumps(response), content_type='application/json') diff --git a/exposition/admin_urls.py b/exposition/admin_urls.py index 096b5444..7b521cb3 100644 --- a/exposition/admin_urls.py +++ b/exposition/admin_urls.py @@ -4,6 +4,7 @@ from admin import ExpositionListView, ExpositionView, PaidView urlpatterns = patterns('exposition.admin', url(r'^upload-photo/(?P.*)/$', 'upload_exposition_photo'), + url(r'^copy/$', 'expo_copy'), url(r'^(?P.*)/paid/$', PaidView.as_view()), #url(r'^add.*/$', 'exposition_add'), diff --git a/functions/model_mixin.py b/functions/model_mixin.py index f56f145c..a96c53cc 100644 --- a/functions/model_mixin.py +++ b/functions/model_mixin.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +import copy import calendar as python_calendar from service.models import Service @@ -101,4 +103,43 @@ class EventMixin(object): if self.data_end.month == month: return self.data_end.day - return 0 \ No newline at end of file + return 0 + + def copy(self, url): + """ + Copy event with new url + :param url: new url for event + :return: event object + """ + # check url + Model = type(self) + try: + Model.objects.get(url=url) + return u'Событие с таким урлом уже существует' + except Model.DoesNotExist: + pass + + duplicate = copy.copy(self) + duplicate.url = url + # Setting pk to None. for Django its a new object. + duplicate.pk = None + # copy translations + ignore_fields = ['id', 'master', 'language_code'] + duplicate.translate('ru') + tr = self._meta.translations_model.objects.get(language_code='ru', master__id=self.pk) + for field in duplicate._translated_field_names: + if field in ignore_fields: + continue + + setattr(duplicate, field, getattr(tr, field)) + duplicate.is_published = False + duplicate.save() # save but lost all ManyToMany relations + + # copy relations + for field in self._meta.many_to_many: + source = getattr(self, field.attname) + destination = getattr(duplicate, field.attname) + for item in source.all(): + destination.add(item) + + return duplicate \ No newline at end of file diff --git a/service/forms.py b/service/forms.py index 16664611..946b0d64 100644 --- a/service/forms.py +++ b/service/forms.py @@ -129,15 +129,15 @@ from exposition.models import Exposition from conference.models import Conference class ServiceControlForm(forms.Form): - event = [{'verbose': 'Выставки', 'model': Exposition, 'id': 1}, - {'verbose': 'Конференции', 'model': Conference, 'id': 2}] + event = [{'verbose': 'Выставки', 'model': Exposition, 'id': 1, 'service_bit': 'expo'}, + {'verbose': 'Конференции', 'model': Conference, 'id': 2, 'service_bit': 'conference'}] region = forms.ChoiceField(required=False, label='Регион', choices=[('', '')]+[(item.id, item.name) for item in list(Area.objects.all())]) country = forms.MultipleChoiceField(required=False, label='Страны', choices=[('', '')]+[(item.id, item.name) for item in list(Country.objects.all())]) - country_all = forms.BooleanField() + country_all = forms.BooleanField(required=False) expositions = forms.CharField(label=u'Выставки', widget=forms.HiddenInput(), required=False) conferences = forms.CharField(label=u'Конференции', widget=forms.HiddenInput(), required=False) @@ -145,5 +145,5 @@ class ServiceControlForm(forms.Form): super(ServiceControlForm, self).__init__(*args, **kwargs) self.fields['event_type'] = forms.MultipleChoiceField(required=False, label = 'Тип события', widget=forms.CheckboxSelectMultiple(), - choices=[(item['id'], item['verbose']) + choices=[(item['service_bit'], item['verbose']) for item in self.event]) \ No newline at end of file diff --git a/service/models.py b/service/models.py index ae9d8196..d0d711f3 100644 --- a/service/models.py +++ b/service/models.py @@ -52,18 +52,56 @@ class Service(TranslatableModel): uses for control form :return: """ - state = {'event_type':[1, 2], - 'region': [], - 'country':[], - 'country_all': True, - 'expositions': [], - 'conferences': []} + from country.models import Country + country_all = False + country = [] + region = [] + expositions = [] + conferences = [] + service = self.url + event_type = [key for key, value in self.type.iteritems() if value] + if not event_type: + return {'event_type': event_type, + 'region': region, + 'country': country, + 'country_all': country_all, + 'expositions': expositions, + 'conferences': conferences} + + count1 = Country.objects.filter().count() + count2 = Country.objects.filter(services=getattr(Country.services, service)).count() + country_all = count1 == count2 + if not country_all: + from exposition.models import Exposition + from conference.models import Conference + from country.models import Area + from django.utils.translation import get_language + lang = get_language() + + countries = list(Country.objects.language(lang).filter(services=getattr(Country.services, service))) + + expositions = [(item.id, item.name) for item in Exposition.enable.upcoming().exclude(country__in=countries, services=getattr(Exposition.services, service))] + conferences = [(item.id, item.name) for item in Conference.enable.upcoming().exclude(country__in=countries, services=getattr(Conference.services, service))] + + region = [] + countries = set(countries) + for item in list(Area.objects.language(lang).all()): + print(item) + area_countries = item.countries() + if set(area_countries).issubset(countries): + region.append((item.id, item.name)) + countries = countries - set(area_countries) + + country = [(item.id, item.name) for item in list(countries)] + + state = {'event_type': event_type, + 'region': region, + 'country': country, + 'country_all': country_all, + 'expositions': expositions, + 'conferences': conferences} return state - - - - from django.db.models.signals import post_save from functions.signal_handlers import post_save_handler @@ -118,6 +156,7 @@ class Translation(AbstractOrder): languages = models.TextField(blank=True) themes = models.TextField(blank=True) + class Visit(AbstractOrder): fr = models.DateField() to = models.DateField() diff --git a/templates/admin/conference/conference_list.html b/templates/admin/conference/conference_list.html index 5bc54f8b..7d6fe645 100644 --- a/templates/admin/conference/conference_list.html +++ b/templates/admin/conference/conference_list.html @@ -1,11 +1,7 @@ {% extends 'admin_list.html' %} {% load static %} -{% block scripts %} - - -{% endblock %} {% block styles %} @@ -41,21 +37,25 @@ td a{
+ + + + - + {% for item in object_list %} - - + +
id Название Дата начала   
{{ item.id }} {{ item.name }}{{ item.data_begin }}{{ item.data_begin|date:"Y-m-d" }}Копировать @@ -87,4 +87,33 @@ td a{ {# pagination #} {% include 'admin/includes/admin_pagination.html' with page_obj=object_list %} + + + {% endblock %} \ No newline at end of file diff --git a/templates/admin/exposition/exposition_list.html b/templates/admin/exposition/exposition_list.html index 860300ca..b12c548f 100644 --- a/templates/admin/exposition/exposition_list.html +++ b/templates/admin/exposition/exposition_list.html @@ -34,21 +34,25 @@ td a{
+ + + + - + {% for item in object_list %} - - + +
id Название Дата начала   
{{ item.id }} {{ item.name }}{{ item.data_begin }}{{ item.data_begin|date:"Y-m-d" }}Копировать @@ -80,4 +84,33 @@ td a{ {# pagination #} {% include 'admin/includes/admin_pagination.html' with page_obj=object_list %} -{% endblock %} \ No newline at end of file + + + +{% endblock %} diff --git a/templates/admin/service/control.html b/templates/admin/service/control.html index 2826333b..99ed06b5 100644 --- a/templates/admin/service/control.html +++ b/templates/admin/service/control.html @@ -29,6 +29,14 @@ + {# country_all #} +
+ +
{{ form.country_all }} + {{ form.country_all.errors }} +
+
+ {# region #}
diff --git a/templates/client/includes/conference/conference_object.html b/templates/client/includes/conference/conference_object.html index 96128573..6fc8b293 100644 --- a/templates/client/includes/conference/conference_object.html +++ b/templates/client/includes/conference/conference_object.html @@ -58,6 +58,14 @@
+ {% else %} +
+
+
+ {{ event.country.name }}, {{ event.city.name }}{% if event.place_alt %} , {{ event.place_alt }}{% endif %} +
+
+
{% endif %}
@@ -165,12 +173,7 @@ {% endif %} {% endif %} - {% if not event.place %} -
{% trans 'Место проведения' %}:
-
- {{ event.country.name }} , {{ event.city.name }}{% if event.place_alt %} , {{ event.place_alt }}{% endif %} -
- {% endif %} + {% if event.web_page %}
{% trans 'Веб-сайт' %}:
diff --git a/templates/client/includes/exposition/exposition_object.html b/templates/client/includes/exposition/exposition_object.html index adccea4e..18d2a2c7 100644 --- a/templates/client/includes/exposition/exposition_object.html +++ b/templates/client/includes/exposition/exposition_object.html @@ -59,6 +59,15 @@
+ {% else %} +
+
+
+ {{ exposition.country.name }}, {{ exposition.city.name }}{% if exposition.place_alt %} , {{ exposition.place_alt }}{% endif %} +
+
+
+ {% endif %}
@@ -169,12 +178,6 @@ {% endif %} {% endif %} - {% if not exposition.place %} -
{% trans 'Место проведения' %}:
-
- {{ exposition.country.name }} , {{ exposition.city.name }}{% if exposition.place_alt %} , {{ exposition.place_alt }}{% endif %} -
- {% endif %} {% if exposition.web_page %}
{% trans 'Веб-сайт' %}: