Initial commit.
This commit is contained in:
209
dav_events/models.py
Normal file
209
dav_events/models.py
Normal file
@@ -0,0 +1,209 @@
|
||||
import os
|
||||
from babel.dates import format_date
|
||||
from django.db import models
|
||||
from django.template.loader import get_template
|
||||
from django.utils.translation import get_language, ugettext_lazy as _
|
||||
|
||||
from . import choices
|
||||
from . import config
|
||||
|
||||
CHOICE_FIELD_MAX_LENGTH = 25
|
||||
|
||||
|
||||
class Event(models.Model):
|
||||
# Meta
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
approved = models.BooleanField(default=False)
|
||||
|
||||
# DescriptionForm
|
||||
title = models.CharField(max_length=config.TITLE_MAX_LENGTH)
|
||||
description = models.TextField()
|
||||
|
||||
# ModeForm
|
||||
mode = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||
choices=choices.MODE_CHOICES)
|
||||
sport = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||
choices=choices.SPORT_CHOICES)
|
||||
ski_lift = models.BooleanField(default=False)
|
||||
level = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||
choices=choices.LEVEL_CHOICES)
|
||||
first_day = models.DateField()
|
||||
alt_first_day = models.DateField(null=True)
|
||||
last_day = models.DateField(null=True)
|
||||
alt_last_day = models.DateField(null=True)
|
||||
|
||||
# TrainingForm
|
||||
course_topic_1 = models.TextField(blank=True)
|
||||
course_topic_2 = models.TextField(blank=True)
|
||||
course_topic_3 = models.TextField(blank=True)
|
||||
course_topic_4 = models.TextField(blank=True)
|
||||
course_topic_5 = models.TextField(blank=True)
|
||||
course_topic_6 = models.TextField(blank=True)
|
||||
course_goal_1 = models.TextField(blank=True)
|
||||
course_goal_2 = models.TextField(blank=True)
|
||||
course_goal_3 = models.TextField(blank=True)
|
||||
course_goal_4 = models.TextField(blank=True)
|
||||
course_goal_5 = models.TextField(blank=True)
|
||||
course_goal_6 = models.TextField(blank=True)
|
||||
|
||||
# LocationForm
|
||||
country = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||
choices=choices.COUNTRY_CHOICES)
|
||||
terrain = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||
choices=choices.TERRAIN_CHOICES)
|
||||
location = models.CharField(max_length=config.LOCATION_MAX_LENGTH)
|
||||
|
||||
# ApproachForm
|
||||
transport = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||
choices=choices.TRANSPORT_CHOICES)
|
||||
transport_other = models.CharField(max_length=config.TRANSPORT_OTHER_MAX_LENGTH,
|
||||
blank=True)
|
||||
meeting_point = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||
choices=choices.MEETING_POINT_CHOICES)
|
||||
meeting_point_other = models.CharField(max_length=config.MEETING_POINT_OTHER_MAX_LENGTH,
|
||||
blank=True)
|
||||
meeting_time = models.TimeField(null=True)
|
||||
arrival_previous_day = models.BooleanField(default=False)
|
||||
return_time = models.TimeField(null=True)
|
||||
|
||||
basecamp = models.CharField(max_length=config.BASECAMP_MAX_LENGTH,
|
||||
blank=True)
|
||||
|
||||
accommodation = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||
choices=choices.ACCOMMODATION_CHOICES)
|
||||
accommodation_other = models.CharField(max_length=config.ACCOMMODATION_OTHER_MAX_LENGTH,
|
||||
blank=True)
|
||||
meals = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||
choices=choices.MEALS_CHOICES)
|
||||
meals_other = models.CharField(max_length=config.MEALS_OTHER_MAX_LENGTH,
|
||||
blank=True)
|
||||
|
||||
# RequirementsForm
|
||||
requirements = models.TextField(blank=True)
|
||||
equipment = models.TextField(blank=True)
|
||||
pre_meeting_1 = models.DateTimeField(null=True)
|
||||
pre_meeting_2 = models.DateTimeField(null=True)
|
||||
|
||||
# RegistrationForm
|
||||
min_participants = models.IntegerField(default=0)
|
||||
max_participants = models.IntegerField(default=0)
|
||||
deadline = models.DateField(null=True)
|
||||
|
||||
# TrainerForm
|
||||
trainer_firstname = models.CharField(max_length=config.TRAINER_NAME_MAX_LENGTH,
|
||||
blank=True)
|
||||
trainer_familyname = models.CharField(max_length=config.TRAINER_NAME_MAX_LENGTH,
|
||||
blank=True)
|
||||
trainer_email = models.EmailField(blank=True)
|
||||
trainer_phone = models.CharField(max_length=config.PHONE_NUMBER_MAX_LENGTH,
|
||||
blank=True)
|
||||
trainer_2_fullname = models.CharField(max_length=config.TRAINER_NAME_MAX_LENGTH,
|
||||
blank=True)
|
||||
trainer_2_email = models.EmailField(blank=True)
|
||||
trainer_2_phone = models.CharField(max_length=config.PHONE_NUMBER_MAX_LENGTH,
|
||||
blank=True)
|
||||
trainer_3_fullname = models.CharField(max_length=config.TRAINER_NAME_MAX_LENGTH,
|
||||
blank=True)
|
||||
trainer_3_email = models.EmailField(blank=True)
|
||||
trainer_3_phone = models.CharField(max_length=config.PHONE_NUMBER_MAX_LENGTH,
|
||||
blank=True)
|
||||
|
||||
# ChargesForm
|
||||
charge = models.FloatField(default=0)
|
||||
additional_costs = models.CharField(max_length=config.ADDITIONAL_COSTS_MAX_LENGTH,
|
||||
blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'Veranstaltung')
|
||||
verbose_name_plural = _(u'Veranstaltungen')
|
||||
ordering = ['first_day']
|
||||
|
||||
def __unicode__(self):
|
||||
return u'{sport} - {title} ({first_day})'.format(title=self.title,
|
||||
sport=self.sport,
|
||||
first_day=self.first_day)
|
||||
|
||||
def get_short_date(self, begin_date=None, end_date=None):
|
||||
if begin_date is None:
|
||||
begin_date = self.first_day
|
||||
if end_date is None:
|
||||
end_date = self.last_day
|
||||
|
||||
lang = get_language()[0:2]
|
||||
|
||||
if not end_date:
|
||||
r = format_date(begin_date, 'EEEE, d. MMMM yyyy', locale=lang)
|
||||
else:
|
||||
end_format = 'EEEE, d. MMMM yyyy'
|
||||
begin_format = 'EEEE, d.'
|
||||
if begin_date.month != end_date.month:
|
||||
begin_format += ' MMMM'
|
||||
if begin_date.year != end_date.year:
|
||||
begin_format += ' yyyy'
|
||||
|
||||
begin = format_date(begin_date, begin_format, locale=lang)
|
||||
end = format_date(end_date, end_format, locale=lang)
|
||||
r = u'{begin} - {end}'.format(begin=begin, end=end)
|
||||
|
||||
return r
|
||||
|
||||
def get_alt_short_date(self):
|
||||
if self.alt_first_day:
|
||||
return self.get_short_date(self.alt_first_day, self.alt_last_day)
|
||||
else:
|
||||
return None
|
||||
|
||||
def render_as_html(self):
|
||||
context = {
|
||||
'mode': self.mode,
|
||||
'sport': self.sport,
|
||||
'title': self.title,
|
||||
'first_day': self.first_day,
|
||||
'last_day': self.last_day,
|
||||
'short_date': self.get_short_date(),
|
||||
'alt_first_day': self.alt_first_day,
|
||||
'alt_last_day': self.alt_last_day,
|
||||
'alt_short_date': self.get_alt_short_date(),
|
||||
'description': self.description,
|
||||
'course_topic_1': self.course_topic_1,
|
||||
'course_topic_2': self.course_topic_2,
|
||||
'course_topic_3': self.course_topic_3,
|
||||
'course_topic_4': self.course_topic_4,
|
||||
'course_topic_5': self.course_topic_5,
|
||||
'course_topic_6': self.course_topic_6,
|
||||
'course_goal_1': self.course_goal_1,
|
||||
'course_goal_2': self.course_goal_2,
|
||||
'course_goal_3': self.course_goal_3,
|
||||
'course_goal_4': self.course_goal_4,
|
||||
'course_goal_5': self.course_goal_5,
|
||||
'course_goal_6': self.course_goal_6,
|
||||
'requirements': self.requirements,
|
||||
'equipment': self.equipment,
|
||||
'location': self.location,
|
||||
'basecamp': self.basecamp,
|
||||
'accommodation': self.accommodation,
|
||||
'accommodation_other': self.accommodation_other,
|
||||
'meals': self.meals,
|
||||
'meals_other': self.meals_other,
|
||||
'transport': self.transport,
|
||||
'transport_other': self.transport_other,
|
||||
'meeting_time': self.meeting_time,
|
||||
'meeting_point': self.meeting_point,
|
||||
'meeting_point_other': self.meeting_point_other,
|
||||
'pre_meeting_1': self.pre_meeting_1,
|
||||
'pre_meeting_2': self.pre_meeting_2,
|
||||
'min_participants': self.min_participants,
|
||||
'max_participants': self.max_participants,
|
||||
'charge': self.charge,
|
||||
'additional_costs': self.additional_costs,
|
||||
'deadline': self.deadline,
|
||||
'trainer_firstname': self.trainer_firstname,
|
||||
'trainer_familyname': self.trainer_familyname,
|
||||
'trainer_email': self.trainer_email,
|
||||
'trainer_phone': self.trainer_phone,
|
||||
'trainer_2_fullname': self.trainer_2_fullname,
|
||||
'event': self,
|
||||
}
|
||||
template_name = os.path.join('dav_events', 'event.html')
|
||||
template = get_template(template_name)
|
||||
return template.render(context)
|
||||
Reference in New Issue
Block a user