from mezzanine.generic.models import AssignedKeyword, Keyword
import eve.models as eve_models
-
+import organization.agenda
class Command(BaseCommand):
"""Synchronize events from E-vement to mezzanine_agenda"""
location.delete()
for event_price in ma_models.EventPrice.objects.all():
event_price.delete()
+ for period in organization.agenda.models.EventPeriod.objects.all():
+ period.delete()
def handle(self, *args, **kwargs):
self.cleanup()
+
meta_event_name = kwargs.get('meta_event')
meta_trans_all = eve_models.MetaEventTranslation.objects.all()
for meta_trans in meta_trans_all:
if meta_trans.name == meta_event_name:
break
+
eve_events = eve_models.Event.objects.filter(meta_event=meta_trans.id)
+
for eve_event in eve_events:
- event_trans = eve_models.EventTranslation.objects.filter(id=eve_event, lang='fr')[0]
- manifestations = eve_event.manifestations.all().order_by('happens_at')
first = True
eve_locations = []
+ event_trans = eve_models.EventTranslation.objects.filter(id=eve_event, lang='fr')[0]
+ manifestations = eve_event.manifestations.all().order_by('happens_at')
+ events = ma_models.Event.objects.filter(external_id=eve_event.id)
+
+ if not events:
+ event = ma_models.Event(external_id=eve_event.id)
+ else:
+ event = events[0]
for manifestation in manifestations:
- events = ma_models.Event.objects.filter(external_id=manifestation.id)
- if not events:
- event = ma_models.Event(external_id=manifestation.id)
- else:
- event = events[0]
- event.start = manifestation.happens_at
- event.end = manifestation.happens_at + timedelta(seconds=manifestation.duration)
- event.title = event_trans.name
- event.user = self.default_user
-
- locations = ma_models.EventLocation.objects.filter(title=manifestation.location.name)
- if locations:
- location = locations[0]
- else:
- location = ma_models.EventLocation(title=manifestation.location.name)
- address = '\n'.join([manifestation.location.address, manifestation.location.postalcode + ' ' + manifestation.location.city])
- location.address = address
- location.external_id = manifestation.id
- location.clean()
- location.save()
- event.location = location
- event.save()
+ if first:
+ event.title = event_trans.name
+ event.user = self.default_user
+ locations = ma_models.EventLocation.objects.filter(title=manifestation.location.name)
+ if locations:
+ location = locations[0]
+ else:
+ location = ma_models.EventLocation(title=manifestation.location.name)
+ address = '\n'.join([manifestation.location.address, manifestation.location.postalcode + ' ' + manifestation.location.city])
+ location.address = address
+ location.external_id = manifestation.id
+ location.clean()
+ location.save()
+ event.location = location
+ event.start = manifestation.happens_at
+ event.save()
+ first = False
+
+ period = organization.agenda.models.EventPeriod(event=event)
+ period.date_from = manifestation.happens_at
+ period.date_to = manifestation.happens_at + timedelta(seconds=manifestation.duration)
+ period.save()
# keyword, c = Keyword.objects.get_or_create(title=eve_event.event_category.name)
# event.keywords.add(AssignedKeyword(keyword=keyword), bulk=False)
if not event_price in event.prices.all():
event.prices.add(event_price)
- if not first and not manifestation.location in eve_locations:
- event.parent = parent
- else:
- parent = event
- first = False
-
- event.status = 1
- event.save()
-
- if not manifestation.location in eve_locations:
- eve_locations.append(manifestation.location)
+ event.end = period.date_to
+ event.status = 1
+ event.save()
{{ event.start|date:"l j F" }}<br>
{% for period in event.periods.all %}
{% if period.date_to and period.date_to|date:"H:i" != "23:59" %}
- {{ period.date_from|date:"H\hi" }} - {{ period.date_to|date:"H\hi" }}<br>
+ {{ period.date_from|date:"H\hi" }}{% if period|period_is_more_than_hours:4 %} - {{ period.date_to|date:"H\hi" }}{% endif %}<br>
{% else %}
{% if forloop.last or event.periods.all|length == 2 %} {% trans "and"%} {% elif not forloop.first %}, {% endif %}
{{ period.date_from|date:"H\hi" }}
{% with event.periods.all|same_time_in_periods as same_time_in_periods %}
{% for period in event.periods.all %}
{% if period.date_to and period.date_to|date:"H:i" != "23:59" %}
- {{ period.date_from|date:"l j F" }} {% trans "from" %} {{ period.date_from|date:"H\hi" }} {% trans "to" %} {{ period.date_to|date:"H\hi" }}<br>
+ {{ period.date_from|date:"l j F" }}
+ {% if period|period_is_more_than_hours:4 %}
+ {% trans "from" %} {{ period.date_from|date:"H\hi" }} {% trans "to" %} {{ period.date_to|date:"H\hi" }}<br>
+ {% else %}
+ {{ period.date_from|date:"H\hi" }}<br>
+ {% endif %}
{% else %}
{% if event.periods.all|length > 1 and not forloop.last %}
{{ period.date_from|date:"l j" }}{% if event.periods.all|length == 2 %} {% trans "and" %} {% else %}, {% endif %}