@@ -0,0 +1,2794 @@
+from datetime import datetime, timedelta%0Afrom optparse import make_option%0A%0Afrom django.conf import settings%0Afrom django.core.management.base import BaseCommand, CommandError%0Afrom django.contrib.auth.models import User%0Afrom django.core.mail import EmailMessage%0A%0Aimport mezzanine_agenda.models as ma_models%0Aimport eve.models as eve_models%0A%0A%0Aclass Command(BaseCommand):%0A    %22%22%22Synchronize events from E-vement to mezzanine_agenda%22%22%22%0A%0A%0A    option_list = BaseCommand.option_list + (%0A          make_option('-m', '--meta_event',%0A            dest='meta_event',%0A            help='define eve meta_event'),%0A          )%0A%0A    default_user = User.objects.get(username='admin')%0A%0A    def cleanup(self):%0A        for event in ma_models.Event.objects.all():%0A            event.delete()%0A        for location in ma_models.EventLocation.objects.all():%0A            location.delete()%0A%0A    def handle(self, *args, **kwargs):%0A        self.cleanup()%0A        meta_event_name = kwargs.get('meta_event')%0A        meta_trans_all = eve_models.MetaEventTranslation.objects.all()%0A        for meta_trans in meta_trans_all:%0A            if meta_trans.name == meta_event_name:%0A                break%0A        eve_events = eve_models.Event.objects.filter(meta_event=meta_trans.id)%0A        for eve_event in eve_events:%0A            event_trans = eve_models.EventTranslation.objects.filter(id=eve_event, lang='fr')%5B0%5D%0A            manifestations = eve_event.manifestations.all().order_by('happens_at')%0A            first = True%0A            for manifestation in manifestations:%0A                events = ma_models.Event.objects.filter(external_id=manifestation.id)%0A                if not events:%0A                    event = ma_models.Event(external_id=manifestation.id)%0A                else:%0A                    event = events%5B0%5D%0A                event.start = manifestation.happens_at%0A                event.end = manifestation.happens_at + timedelta(seconds=manifestation.duration)%0A                event.title = event_trans.name%0A                event.user = self.default_user%0A                %0A                location, c = ma_models.EventLocation.objects.get_or_create(title=manifestation.location.name)%0A                address = '%5Cn'.join(%5Bmanifestation.location.address, manifestation.location.postalcode + ' ' + manifestation.location.city%5D)%0A                location.address = address%0A                location.clean()%0A                location.save()%0A                event.location = location%0A%0A                category, c = ma_models.EventCategory.objects.get_or_create(name=eve_event.event_category.name)%0A                event.category = category%0A%0A                if not first:%0A                    event.parent = parent%0A                else:%0A                    parent = event%0A                    first = False%0A%0A                event.save()%0A

add sync command