You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.2 KiB
91 lines
2.2 KiB
from service.models import Service
|
|
import calendar as python_calendar
|
|
|
|
class ExpoMixin(object):
|
|
|
|
def get_index_text(self):
|
|
names = [tr.name for tr in self.translations.all()]
|
|
return names
|
|
|
|
def get_logo(self):
|
|
|
|
logo = self.files.filter(purpose='logo')
|
|
if logo:
|
|
return logo[0]
|
|
return logo
|
|
|
|
def get_preview(self):
|
|
|
|
preview = self.files.filter(purpose='preview')
|
|
if preview:
|
|
return preview[0]
|
|
return preview
|
|
|
|
def get_photos(self):
|
|
photos = self.files.filter(purpose='photo')
|
|
return photos
|
|
|
|
|
|
class EventMixin(object):
|
|
def get_permanent_url(self):
|
|
url = '%sevent-%s'%(self.get_catalog_url(), self.url)
|
|
return url
|
|
|
|
def get_logo(self):
|
|
|
|
logo = self.files.filter(purpose='logo')
|
|
if logo:
|
|
return logo[0]
|
|
return logo
|
|
|
|
def get_preview(self):
|
|
|
|
preview = self.files.filter(purpose='preview')
|
|
if preview:
|
|
return preview[0]
|
|
return preview
|
|
|
|
def get_photos(self):
|
|
photos = self.files.filter(purpose='photo')
|
|
return photos
|
|
|
|
def on(self):
|
|
self.is_published = True
|
|
self.canceled_by_administrator = False
|
|
self.save()
|
|
|
|
def off(self):
|
|
self.is_published = False
|
|
self.canceled_by_administrator = True
|
|
self.save()
|
|
|
|
def cancel(self):
|
|
self.canceled_by_administrator = True
|
|
|
|
def get_services(self):
|
|
|
|
ids = [item for item, bool in self.country.services if bool==True]
|
|
return [Service.objects.get(url=id) for id in ids]
|
|
|
|
|
|
|
|
def duration_days(self, month=None):
|
|
if not month:
|
|
d = self.data_end - self.data_begin
|
|
return d.days+1
|
|
else:
|
|
if self.data_begin.month == month and self.data_end.month ==month:
|
|
d = self.data_end - self.data_begin
|
|
return d.days + 1
|
|
if self.data_begin.month == month:
|
|
last_day = python_calendar.monthrange(self.data_begin.year, month)[1]
|
|
return last_day - self.data_begin.day + 1
|
|
|
|
|
|
if self.data_end.month == month:
|
|
return self.data_end.day
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|