def add_classgroup_event(request): if request.POST: form = ClassgroupEventForm(user=request.user, data=request.POST, prefix="classgroup") when = form.save() j = when.to_fullcalendar_dict(lambda when:True, "classgroup") return HttpResponse(json.dumps(j)) else: return False
def update_event(request, when_id): form = None when = get_object_or_404(When, pk=when_id) event_type, who = when.event.get_type() data = {'name' : when.event.name, 'date' : when.date.strftime("%Y-%m-%d"), 'start_hour' : int(when.date.strftime("%H")), 'duration' : int(when.event.duration), 'place_text' : when.event.place_text, 'force_display' : when.event.force_display, } if event_type == 'classgroup' and\ request.user.get_profile().can_manage_classgroup(who.classgroup.id): data.update({'place' : when.event.places.get().id, 'classgroup' : who.classgroup.id, 'modality' : when.event.subject_modality.type, 'subject' : when.event.subject_modality.subject.id, }) if request.POST: form = ClassgroupEventForm(user=request.user, data=request.POST) else: form = ClassgroupEventForm(user=request.user, initial=data) elif event_type == 'user' and\ who.user == request.user: if request.POST: form = UserEventForm(data=request.POST) else: form = UserEventForm(initial=data) elif event_type == 'campus' and\ request.user.get_profile().can_manage_cursus(who.campus.id): try: place_id = when.event.places.get().id except ObjectDoesNotExist: place_id = None data.update({'place' : place_id, 'campus' : who.campus.id, }) if request.POST: form = CampusEventForm(data=request.POST, user=request.user) else: form = CampusEventForm(initial=data, user=request.user) if request.POST: if form.is_valid(): when = form.save(when) j = when.to_fullcalendar_dict(lambda when:True, "moved") return HttpResponse(json.dumps(j)) return render_to_response('edit_user_calendar.html', { 'form': form,}, request)