Пример #1
0
def EditEvent(request, eventid):
    ''' Show and update existing event. '''
    
    try:
        event = Event.objects.get(id = eventid)
    except(Event.DoesNotExist):
        raise Http404
    
    group = event.group
    
    bc = [{'title': 'Overview', 'url': reverse('MyPidge.Events.views.All')},
        {'title': event.title, 'url': reverse('MyPidge.Events.views.ViewEvent', args=[event.id])},
        {'title':'Edit'}]
    
    usr = User.objects.get(id = request.session['userid'])
    
    try:
        uga = Membership.objects.get(person = usr, group=group, assoctype='CTL')
    except(Membership.DoesNotExist):
        raise PermissionDenied
    
    if request.method == 'POST':
        editform = EventForm(request.POST, instance = event)
        if editform.is_valid():
            editform.save()
            return HttpResponseRedirect(reverse('MyPidge.Events.views.ViewEvent', args=[event.id]))
    else:
        editform = EventForm(instance = event)
    return render_to_response("events-edit", {'breadcrumb': bc, 'activetab': 'Events','event': event, 'editform': editform})
Пример #2
0
def AddToGroup(request, groupid):
    ''' Add an event to a specific group. '''
    
    usr = User.objects.get(id = request.session['userid'])
    
    try:
        group = Group.objects.get(id=groupid)
    except(Group.DoesNotExist):
        raise Http404

    bc = [{'title': 'Overview', 'url': reverse('MyPidge.Events.views.All')},
        {'title': 'Add Event', 'url': reverse('MyPidge.Events.views.Add')},
        {'title': group.official_name}]

    try:
        uga = Membership.objects.get(person = usr, group=group, assoctype='CTL')
    except Membership.DoesNotExist:
        raise PermissionDenied
    
    eventClone = None
    # Does the user want to clone an existing Event for this Group?
    if 'clone' in request.REQUEST:
        try:
            eventClone = Event.objects.get(id=request.REQUEST['clone'])
        except Event.DoesNotExist:
            raise Http404
        
    if request.method == 'POST':
        myevent = Event(group = group)
        aef = EventForm(request.POST, instance = myevent)
        if aef.is_valid():
            # Save new Event and get them to add EventTimes to it
            newevent = aef.save()
            return HttpResponseRedirect(reverse('MyPidge.Events.views.AddTime', args=[newevent.id]))
        
    else:
        if eventClone:
            aef = EventForm(instance = eventClone)
        else:
            aef = EventForm()
    
    return render_to_response("events-add-togroup", {'breadcrumb': bc, 'activetab': 'Events','group': group, 'aef': aef})