diff --git a/accounts/models.py b/accounts/models.py index 5dee4e48..43125dcc 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -204,6 +204,11 @@ class User(AbstractBaseUser, PermissionsMixin): return '/%d/'%self.id #return self.catalog+str(self.id)+'/' + def get_translator_url(self): + if self.url: + return '/translators/%s/'%self.url + return '/translators/%d/'%self.id + def get_expos(self): """ return information about expos and them related data by 1 query diff --git a/city/admin.py b/city/admin.py index adf383e3..b2642e36 100644 --- a/city/admin.py +++ b/city/admin.py @@ -49,14 +49,14 @@ def city_change(request, url): return HttpResponseRedirect('/admin/city/all') if request.POST: - form = CityForm(request.POST) + form = CityForm(request.POST, request.FILES) if form.is_valid(): form.save(city_id) return HttpResponseRedirect('/admin/city/all') else: #fill form with data from database data = {'population' : c.population, 'phone_code' : c.phone_code, - 'city_id' : city_id, 'inflect':c.inflect} + 'city_id' : city_id, 'inflect':c.inflect, 'logo': c.logo} if c.country: data['country'] = c.country.id diff --git a/city/forms.py b/city/forms.py index 98cc5ce5..258b9877 100644 --- a/city/forms.py +++ b/city/forms.py @@ -34,6 +34,7 @@ class CityForm(forms.Form): 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) + logo = forms.ImageField(label='Logo', required=False) #field for comparing tmp files key = forms.CharField(required=False, widget=forms.HiddenInput()) # @@ -91,6 +92,11 @@ class CityForm(forms.Form): city.population = data.get('population') city.inflect = data['inflect'] + if data.get('logo'): + city.logo = data['logo'] + else: + city.logo = '' + if data.get('code_IATA'): city.code_IATA = Iata.objects.get(id=data['code_IATA'].id)# .id cause select uses queryset diff --git a/city/models.py b/city/models.py index 73d3cbf5..e02547f6 100644 --- a/city/models.py +++ b/city/models.py @@ -62,6 +62,7 @@ class City(TranslatableModel): # fields saves information about creating and changing model created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) + logo = models.ImageField(verbose_name='Logo', upload_to='city/logo/', blank=True, max_length=255) class Meta: ordering = ['translations__name'] diff --git a/country/admin.py b/country/admin.py index ede3a8cf..1ad06c86 100644 --- a/country/admin.py +++ b/country/admin.py @@ -63,7 +63,7 @@ def country_change(request, url): if request.POST: #country_id sending for saving capital field in __init__ - form = CountryForm(request.POST, country_id=country_id) + form = CountryForm(request.POST, request.FILES, country_id=country_id) if form.is_valid(): form.save(country_id) @@ -71,8 +71,9 @@ def country_change(request, url): else: #fill form with data from database data = {'population' : c.population, 'teritory' : c.teritory, #data from NOT translated fields - 'timezone' : c.timezone, 'country_id' : country_id, - 'phone_code' : c.phone_code, 'time_delivery' : c.time_delivery} + 'timezone' : c.timezone, 'country_id' : country_id, + 'phone_code' : c.phone_code, 'time_delivery' : c.time_delivery, + 'logo': c.logo} if c.capital: data['capital'] = c.capital.id diff --git a/country/forms.py b/country/forms.py index cdc0be8d..67193e43 100644 --- a/country/forms.py +++ b/country/forms.py @@ -55,6 +55,8 @@ class CountryForm(forms.Form): time_delivery = forms.CharField(label='Срок выдачи', required=False, widget=forms.TextInput(attrs={'placeholder':'Срок выдачи'})) + logo = forms.ImageField(label='Logo', required=False) + #services = forms.MultipleChoiceField(label='Сервисы', required=False, choices=); #field for comparing tmp files key = forms.CharField(required=False, widget=forms.HiddenInput()) @@ -136,6 +138,12 @@ class CountryForm(forms.Form): country.phone_code = data['phone_code'] country.time_delivery = data['time_delivery'] + if data.get('logo'): + country.logo = data['logo'] + else: + country.logo = '' + + if data.get('capital'): country.capital = City.objects.get(id=data['capital']) diff --git a/country/models.py b/country/models.py index 548d54c7..7508cbf1 100644 --- a/country/models.py +++ b/country/models.py @@ -102,6 +102,7 @@ class Country(TranslatableModel): descriptions = models.CharField(max_length=255), keywords = models.CharField(max_length=255), ) + logo = models.ImageField(verbose_name='Logo', upload_to='country/logo/', blank=True, max_length=255) class Meta: ordering = ['translations__name'] diff --git a/settings/templatetags/template_filters.py b/settings/templatetags/template_filters.py index 10c11444..ec5ede18 100644 --- a/settings/templatetags/template_filters.py +++ b/settings/templatetags/template_filters.py @@ -282,4 +282,13 @@ def generate_countries_list(value): - return ul1+ul2+ul3 \ No newline at end of file + return ul1+ul2+ul3 + +@register.filter +def how_many_years(value): + if not isinstance(value, datetime.date): + return '' + now = datetime.date.today() + delta = now - value + + return delta.days/365 diff --git a/templates/admin/city/city_add.html b/templates/admin/city/city_add.html index ff7aaec1..da12c2cc 100644 --- a/templates/admin/city/city_add.html +++ b/templates/admin/city/city_add.html @@ -17,7 +17,7 @@ {% block body %} {# Uses multilang.html template for translated fields #} -