Пример #1
0
def __create_or_update_event_with_location (form, user, event):
    "Creates or updates an Event from the submitted EventForm. If the given Event is None a new Event is created."
    if event == None:
        event = Event()
    
    event.title = form.cleaned_data['title']
    event.date_time_begin = form.cleaned_data['date_time_begin']
    event.date_time_end = form.cleaned_data['date_time_end']
    event.url = form.cleaned_data['url']
    event.description = form.cleaned_data['description']
    event.location = __get_and_update_or_create_location(form)
    
    # Only when a new event is created
    if event.id == None:
        # auto-publish for staff users
        event.published = user.is_staff
        # link event to user
        if user.is_authenticated():
            event.user = user
    
    # Event must be persisted before tags can be set (many-to-may relationship)
    if event.id == None:
        event.save()
    
    event.tags = form.cleaned_data['tags']
    event.save()
    
    return event
Пример #2
0
def save_event_from_json(event_as_json, user):
    ev = json.loads(event_as_json)
    
    event = Event()
    event.user = user
    if 'id' in ev:
        event.id = ev['id']
    
    event.title = ev['title']
    
    if 'date_time_begin' in ev:
        event.date_time_begin = __json_string_to_date_time(ev['date_time_begin'])
    if 'date_time_end' in ev:
        event.date_time_end = __json_string_to_date_time(ev['date_time_end'])

    if 'url' in ev:
        event.url = ev['url']
    if 'description' in ev:
        event.description = ev['description']
    if 'canceled' in ev:
        event.canceled = ev['canceled']

    event.save()

    if 'tags' in ev:
        tags = convert_to_event_tags(ev['tags'])
        event.tags = tags
        event.save()

    # TODO: location
    
    return event