def edit_event_group(request, event_group_slug): group = get_object_or_404(EventGroup, slug=event_group_slug) if not group.user_can_edit(request.user): raise PermissionDenied form = EventGroupForm(request.POST or None, instance=group) if request.method == 'POST': logging.debug("incoming post: %s", request.POST) if form.is_valid(): event_group = form.save() if request.user not in event_group.editor_set.all(): event_group.editor_set.add(request.user) event_group.save() try: eventgroup_updated.send(event_group.__class__, instance=event_group) except Timeout: messages.warning( request, "Timed out connecting to Old Talks. The series will not be updated on the old site." ) messages.success(request, "Series was updated") return redirect(event_group.get_absolute_url()) else: messages.warning(request, "Please correct errors below") context = { 'group_form': form, 'organiser_form': PersonQuickAdd(), 'event_group': group, 'is_editing': True } return render(request, 'contributors/event_group_form.html', context)
def create_event_group(request): form = EventGroupForm(request.POST or None) is_modal = request.GET.get('modal') status_code = 200 if request.method == 'POST': if form.is_valid(): event_group = form.save() if request.user not in event_group.editor_set.all(): event_group.editor_set.add(request.user) event_group.save() showTimeoutWarning = False try: eventgroup_updated.send(event_group.__class__, instance=event_group) except Timeout: showTimeoutWarning = True if is_modal: group_data = serializers.EventGroupSerializer(event_group).data if showTimeoutWarning: group_data['push_to_old_talks_error'] = 'Timeout' response = json.dumps(group_data) if showTimeoutWarning: # messages.warning(response, "Timed out connecting to Old Talks. This series will not appear on that site until it is edited again.") return HttpResponse(response, status=201, content_type='application/json') return HttpResponse(response, status=201, content_type='application/json') if showTimeoutWarning: messages.warning( request, "Timed out connecting to Old Talks. This series will not appear on that site until it is edited again." ) messages.success(request, "Series was created") return redirect(event_group.get_absolute_url()) else: status_code = 400 messages.warning(request, "Please correct errors below") context = { 'group_form': form, 'organiser_form': PersonQuickAdd(), 'modal_title': "Add a new series", 'is_editing': False } if is_modal: return render(request, 'contributors/event_group_modal_form.html', context, status=status_code) else: return render(request, 'contributors/event_group_form.html', context, status=status_code)
def edit_event(request, event_slug): event = get_object_or_404(Event, slug=event_slug) if not event.user_can_edit(request.user): raise PermissionDenied # providing data for topics/speakers as it is not straight from the Model initial = { 'topics': [t.uri for t in event.topics.all()], # uses GenericRelation 'speakers': event.speakers.all(), # different of person_set 'organisers': event.organisers.all(), 'hosts': event.hosts.all() } form = EventForm(request.POST or None, instance=event, initial=initial, prefix='event', user=request.user, request=request) context = { 'event': event, 'event_form': form, 'speaker_form': PersonQuickAdd(), 'organiser_form': PersonQuickAdd(), 'host_form': PersonQuickAdd(), 'is_editing': True, } if request.method == 'POST': if form.is_valid(): event = form.save() if request.user not in event.editor_set.all(): event.editor_set.add(request.user) event.save() try: event_updated.send(event.__class__, instance=event) except Timeout: messages.warning( request, "Timed out connecting to old talks. This update won't appear on the old talks website." ) messages.success(request, "Talk was updated") return redirect(event.get_absolute_url()) else: messages.warning(request, "Please correct errors below") return render(request, "contributors/event_form.html", context)
def create_event(request, group_slug=None): initial = None event_group = None logger.debug("group_id:%s", group_slug) if group_slug: event_group = get_object_or_404(EventGroup, slug=group_slug) organising_dept = event_group.department_organiser initial = { 'group': event_group, 'department_organiser': organising_dept, } PrefixedEventForm = partial(EventForm, prefix='event', initial=initial, user=request.user, request=request) if request.method == 'POST': context = { 'event_form': PrefixedEventForm(request.POST), 'speaker_form': PersonQuickAdd(), 'organiser_form': PersonQuickAdd(), 'host_form': PersonQuickAdd(), } forms_valid = context['event_form'].is_valid() if forms_valid: logging.debug("form is valid") event = context['event_form'].save() if request.user not in event.editor_set.all(): event.editor_set.add(request.user) event.save() try: event_updated.send(event.__class__, instance=event) except Timeout: messages.warning( request, "Timed out connecting to Old Talks. This talk won't appear on the old site" ) messages.success(request, "New talk has been created") if 'another' in request.POST: if event_group: logger.debug("redirecting to create-event-in-group") # Adding more events, redirect to the create event in existing group form return HttpResponseRedirect( reverse('create-event-in-group', args=(event_group.slug, ))) else: logger.debug("redirecting to create-event") return HttpResponseRedirect(reverse('create-event')) else: return HttpResponseRedirect( reverse('show-event', args=(event.slug, ))) else: logging.debug("form is NOT valid") messages.warning(request, "Please correct errors below") else: context = { 'event_form': PrefixedEventForm(), 'speaker_form': PersonQuickAdd(), 'organiser_form': PersonQuickAdd(), 'host_form': PersonQuickAdd, 'is_editing': False } return render(request, 'contributors/event_form.html', context)