From d64c068623ec777e73ca3739f7e235ed7e0faa72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80=20=D0=9A=D0=BE=D1=82=D1=8E?= =?UTF-8?q?=D0=BA?= Date: Thu, 5 Feb 2015 17:31:06 +0200 Subject: [PATCH] Calendar --- accounts/views.py | 24 ++++++++++++-- city/admin.py | 2 +- city/forms.py | 2 ++ conference/forms.py | 4 +-- exposition/admin_urls.py | 2 +- functions/admin_forms.py | 2 +- .../commands/organiser_from_old_db.py | 31 ++++++++++++------- .../management/commands/convert_logo.py | 8 +---- settings/templatetags/template_filters.py | 2 +- templates/admin/city/city_add.html | 7 +++++ .../includes/accounts/calendar_table.html | 6 ++-- 11 files changed, 60 insertions(+), 30 deletions(-) diff --git a/accounts/views.py b/accounts/views.py index 77765f08..138d5343 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import dateutil.relativedelta as rdelta import json, datetime import calendar as python_calendar from django.shortcuts import get_object_or_404 @@ -70,7 +71,7 @@ class CalendarView(TemplateView): number_of_days = python_calendar.monthrange(now.year, now.month)[1] # number of days in current month days = [timezone.make_aware(datetime.datetime(now.year, now.month, i+1), timezone.get_default_timezone()) for i in range(number_of_days)] - context['days'] = days + #context['days'] = days calendar = self.request.user.calendar # events in current month @@ -80,15 +81,32 @@ class CalendarView(TemplateView): number_of_days = python_calendar.monthrange(year, month)[1] days = [timezone.make_aware(datetime.datetime(year, month, i+1), timezone.get_default_timezone()) for i in range(number_of_days)] # number of days in current month - context['days'] = days + #context['days'] = days calendar = self.request.user.calendar now = now.replace(year=year, month=month, day=1) # events in current month context['events'] = calendar.events_by_month(now) + # add days from previous mondey to next sunday + + first_day = days[0] + if first_day.weekday() != 0: + past_monday = first_day + rdelta.relativedelta(days=-1, weekday=rdelta.MO(-1)) + a = [past_monday + datetime.timedelta(days=x) for x in range((first_day - past_monday).days)] + days = a + days + + + last_day = days[-1] + + if last_day != 6: + next_sunday = last_day + rdelta.relativedelta(days=1, weekday=rdelta.SU(+1)) + b = [last_day + datetime.timedelta(days=x+1) for x in range((next_sunday - last_day).days)] + days += b + events = context['events'] - days = context['days'] + context['days'] = days + #days = context['days'] event_in_day = False counter = 0 dates_with_events = [] diff --git a/city/admin.py b/city/admin.py index c09eec7c..adf383e3 100644 --- a/city/admin.py +++ b/city/admin.py @@ -56,7 +56,7 @@ def city_change(request, url): else: #fill form with data from database data = {'population' : c.population, 'phone_code' : c.phone_code, - 'city_id' : city_id} + 'city_id' : city_id, 'inflect':c.inflect} if c.country: data['country'] = c.country.id diff --git a/city/forms.py b/city/forms.py index d2f8ff62..86082213 100644 --- a/city/forms.py +++ b/city/forms.py @@ -33,6 +33,7 @@ class CityForm(forms.Form): phone_code = forms.CharField(label='Код города', required=False, widget=forms.TextInput(attrs={'placeholder':'Код города'})) code_IATA = forms.ModelChoiceField(label='Код IATA', queryset=Iata.objects.all(), empty_label=None, required=False) + inflect = forms.CharField(label='Inflect', required=False) #field for comparing tmp files key = forms.CharField(required=False, widget=forms.HiddenInput()) # @@ -85,6 +86,7 @@ class CityForm(forms.Form): city.phone_code = data['phone_code'] city.population = data.get('population') + city.inflect = data['inflect'] if data.get('code_IATA'): city.code_IATA = Iata.objects.get(id=data['code_IATA'].id)# .id cause select uses queryset diff --git a/conference/forms.py b/conference/forms.py index a70a3418..f635400d 100644 --- a/conference/forms.py +++ b/conference/forms.py @@ -36,12 +36,12 @@ class ConferenceCreateForm(forms.Form): data_begin = forms.DateField(label='Дата начала') data_end = forms.DateField(label='Дата окночания') - country = forms.ModelChoiceField(label='Страна', queryset=Country.objects.all(), empty_label=None) + country = forms.ChoiceField(label=u'Страна', choices=[(c.id, c.name) for c in Country.objects.all()]) theme = forms.ModelMultipleChoiceField(label='Тематики', queryset=Theme.objects.all()) place = forms.ModelChoiceField(label='Место проведения', queryset=PlaceConference.objects.all(), empty_label='', required=False) #creates select input with empty choices cause it will be filled with ajax - city = forms.ChoiceField(label='Город', choices=[('','')]) + city = forms.CharField(label=u'Город', widget=forms.HiddenInput()) tag = forms.MultipleChoiceField(label='Теги', required=False) web_page = forms.CharField(label='Веб страница', required=False) diff --git a/exposition/admin_urls.py b/exposition/admin_urls.py index 402dd4ed..5c8da315 100644 --- a/exposition/admin_urls.py +++ b/exposition/admin_urls.py @@ -6,7 +6,7 @@ urlpatterns = patterns('exposition.admin', url(r'^upload-photo/(?P.*)/$', 'upload_exposition_photo'), #url(r'^add.*/$', 'exposition_add'), - #url(r'^delete/(?P.*)/$', 'exposition_delete'), + url(r'^delete/(?P.*)/$', 'exposition_delete'), #url(r'^change/(?P.*)/$', 'exposition_change'), url(r'^all/$', ExpositionListView.as_view()), url(r'^switch/(?P.*)/(?P.*)$', 'exposition_switch'), diff --git a/functions/admin_forms.py b/functions/admin_forms.py index e1a78da9..d63db3f5 100644 --- a/functions/admin_forms.py +++ b/functions/admin_forms.py @@ -44,6 +44,6 @@ class AdminFilterForm(forms.Form): qs = model.objects.all() if name: - qs = qs.filter(translations__name__contains=name).distinct() + qs = qs.filter(translations__name__icontains=name).distinct() return qs \ No newline at end of file diff --git a/organiser/management/commands/organiser_from_old_db.py b/organiser/management/commands/organiser_from_old_db.py index ce0e2b19..43bdeb32 100644 --- a/organiser/management/commands/organiser_from_old_db.py +++ b/organiser/management/commands/organiser_from_old_db.py @@ -1,7 +1,9 @@ +# -*- coding: utf-8 -*- from django.core.management.base import BaseCommand, CommandError from organiser.models import Organiser from theme.models import Theme, Tag from functions.form_check import translit_with_separator +from accounts.models import User import MySQLdb from MySQLdb.cursors import DictCursor @@ -21,9 +23,9 @@ def convert_to_int(st): class Command(BaseCommand): def handle(self, *args, **options): db = MySQLdb.connect(host="localhost", - user="root", + user="kotzilla", passwd="qazedc", - db="expomap_ru", + db="old_expomap", charset='utf8', cursorclass=DictCursor) @@ -31,18 +33,18 @@ class Command(BaseCommand): - sql = """SELECT DISTINCT(customers_company) as name, specialize, otrasly as theme, tags, adress, - phone, fax, email, website, twitter, about, customers_company.url + sql = """SELECT DISTINCT(customers_company) as name, customers_email_address as user_email, specialize, otrasly as theme, tags, adress, + phone, fax, email, website, twitter, about, customers_company.url, company_last_modified as modified FROM customers LEFT JOIN customers_company - ON customers.customers_company=customers_company.title + ON customers.customers_id = customers_company.customers_id WHERE customers_status = 4 """ cursor.execute(sql) res = cursor.fetchall() - + print(res[0].get('user_email')) for o in res: if not o.get('name'): @@ -66,7 +68,7 @@ class Command(BaseCommand): organiser.description = o.get('about') if organiser.name: - print('not_saved: %s'%o['name']) + print('not_saved: %s'%o['name'].encode('utf8')) organiser.save() print('saved: %s'%str(organiser)) @@ -75,12 +77,10 @@ class Command(BaseCommand): if theme_id: try: theme = Theme.objects.get(id=theme_id) + organiser.theme.add(theme) except Theme.DoesNotExist: - continue - organiser.theme.add(theme) + pass - if not theme: - continue tags = o.get('tags') if tags: @@ -104,5 +104,14 @@ class Command(BaseCommand): organiser.save() print(organiser) + user_email = o.get('user_email') + if user_email: + try: + user = User.objects.get(username=user_email) + user.organiser = organiser + user.save() + except User.DoesNotExist: + print('no user with this email: %s'%user_email) + print('success') diff --git a/place_exposition/management/commands/convert_logo.py b/place_exposition/management/commands/convert_logo.py index 14f5e3e7..c37be278 100644 --- a/place_exposition/management/commands/convert_logo.py +++ b/place_exposition/management/commands/convert_logo.py @@ -27,15 +27,9 @@ def handle_place(place): place.save() - class Command(BaseCommand): def handle(self, *args, **options): - for place in PlaceExposition.objects.all('en'): - - if place.files.filter(purpose='logo').exists(): handle_place(place) - print(place) - - + print(place) \ No newline at end of file diff --git a/settings/templatetags/template_filters.py b/settings/templatetags/template_filters.py index 304ad610..4710925d 100644 --- a/settings/templatetags/template_filters.py +++ b/settings/templatetags/template_filters.py @@ -232,7 +232,7 @@ def next_monthes(value): @register.filter def get_rus_day(date): - days = {1: u'Пн', 2: u'Вт', 3: u'Ср', 4: u'Чт', 5: u'Пт', 6: u'Сб', 0: u'Вс',} + days = {0: u'Пн', 1: u'Вт', 2: u'Ср', 3: u'Чт', 4: u'Пт', 5: u'Сб', 6: u'Вс',} return days.get(date.weekday(), '') diff --git a/templates/admin/city/city_add.html b/templates/admin/city/city_add.html index 07139b34..ff7aaec1 100644 --- a/templates/admin/city/city_add.html +++ b/templates/admin/city/city_add.html @@ -35,6 +35,13 @@ {% with field='name' form=form languages=languages %} {% include 'admin/forms/multilang.html' %} {% endwith %} + {# population #} +
+ +
+ {{ form.inflect }} +
+
{# country #}
diff --git a/templates/client/includes/accounts/calendar_table.html b/templates/client/includes/accounts/calendar_table.html index fab0687d..93b2a9b0 100644 --- a/templates/client/includes/accounts/calendar_table.html +++ b/templates/client/includes/accounts/calendar_table.html @@ -9,9 +9,9 @@
- < -
{{ days.0|date:"F"}}’{{ days.0|date:"y"}}
- > + < +
{{ days.15|date:"F"}}’{{ days.15|date:"y"}}
+ >