def new_event_add_details(request, event_id): event = get_object_or_404(Event, id=event_id) if not request.user.profile.can_edit_event(event): messages.add_message( request, messages.WARNING, message=_("You can not make changes to this event."), ) return redirect(event.get_absolute_url()) if request.method == "GET": form = NewEventDetailsForm(instance=event) context = {"event": event, "team": event.team, "event_form": form} return render(request, "get_together/new_event/detail_event.html", context) elif request.method == "POST": form = NewEventDetailsForm(request.POST, instance=event) if form.is_valid: new_event = form.save() if form.cleaned_data.get("recurrences", None): new_series = EventSeries.from_event( new_event, recurrences=form.cleaned_data["recurrences"] ) new_series.save() new_event.series = new_series new_event.save() return redirect("new-event-add-team", new_event.id) else: context = {"event": event, "team": event.team, "event_form": form} return render(request, "get_together/new_event/detail_event.html", context) else: return redirect("home")
def create_event(request, team_id): team = get_object_or_404(Team, id=team_id) if not request.user.profile.can_create_event(team): messages.add_message( request, messages.WARNING, message=_('You can not create events for this team.')) return redirect('show-team', team_id=team.pk) new_event = Event(team=team, created_by=request.user.profile) if request.method == 'GET': if 'common' in request.GET and request.GET['common'] != '': new_event.parent = CommonEvent.objects.get( id=request.GET['common']) form = NewTeamEventForm(instance=new_event) context = { 'event': new_event, 'team': team, 'event_form': form, } return render(request, 'get_together/events/create_event.html', context) elif request.method == 'POST': if 'common' in request.POST and request.POST['common'] != '': new_event.parent = CommonEvent.objects.get( id=request.POST['common']) form = NewTeamEventForm(request.POST, instance=new_event) if form.is_valid: new_event = form.save() Attendee.objects.create(event=new_event, user=request.user.profile, role=Attendee.HOST, status=Attendee.YES) if form.cleaned_data.get('recurrences', None): new_series = EventSeries.from_event( new_event, recurrences=form.cleaned_data['recurrences']) new_series.save() new_event.series = new_series new_event.save() messages.add_message( request, messages.SUCCESS, message= _('Your event has been scheduled! Next, find a place for your event.' )) return redirect('add-place', new_event.id) else: context = { 'event': new_event, 'team': team, 'event_form': form, } return render(request, 'get_together/events/create_event.html', context) else: return redirect('home')
def edit_event(request, event_id): event = get_object_or_404(Event, id=event_id) if not request.user.profile.can_edit_event(event): messages.add_message( request, messages.WARNING, message=_("You can not make changes to this event."), ) return redirect(event.get_absolute_url()) if request.method == "GET": form = TeamEventForm(instance=event) if event.series is not None: form.initial["recurrences"] = event.series.recurrences context = {"team": event.team, "event": event, "event_form": form} return render(request, "get_together/events/edit_event.html", context) elif request.method == "POST": form = TeamEventForm(request.POST, instance=event) if form.is_valid: new_event = form.save() if form.cleaned_data.get("recurrences", None): if event.series is not None: event.series.recurrences = form.cleaned_data["recurrences"] event.series.save() else: new_series = EventSeries.from_event( new_event, recurrences=form.cleaned_data["recurrences"]) new_series.save() new_event.series = new_series new_event.save() else: if event.series is not None: old_series = event.series event.series = None event.save() if old_series.instances.count() < 1: old_series.delete() else: event.save() return redirect(new_event.get_absolute_url()) else: context = {"team": event.team, "event": event, "event_form": form} return render(request, "get_together/events/edit_event.html", context) else: return redirect("home")
def edit_event(request, event_id): event = get_object_or_404(Event, id=event_id) if not request.user.profile.can_edit_event(event): messages.add_message( request, messages.WARNING, message=_('You can not make changes to this event.')) return redirect(event.get_absolute_url()) if request.method == 'GET': form = TeamEventForm(instance=event) if event.series is not None: form.initial['recurrences'] = event.series.recurrences context = { 'team': event.team, 'event': event, 'event_form': form, } return render(request, 'get_together/events/edit_event.html', context) elif request.method == 'POST': form = TeamEventForm(request.POST, instance=event) if form.is_valid: new_event = form.save() if form.cleaned_data.get('recurrences', None): if event.series is not None: event.series.recurrences = form.cleaned_data['recurrences'] event.series.save() else: new_series = EventSeries.from_event( new_event, recurrences=form.cleaned_data['recurrences']) new_series.save() new_event.series = new_series new_event.save() return redirect(new_event.get_absolute_url()) else: context = { 'team': event.team, 'event': event, 'event_form': form, } return render(request, 'get_together/events/edit_event.html', context) else: return redirect('home')
def new_event_add_details(request, event_id): event = get_object_or_404(Event, id=event_id) if not request.user.profile.can_edit_event(event): messages.add_message(request, messages.WARNING, message=_('You can not make changes to this event.')) return redirect(event.get_absolute_url()) if request.method == 'GET': form = NewEventDetailsForm(instance=event) context = { 'event': event, 'team': event.team, 'event_form': form, } return render(request, 'get_together/new_event/detail_event.html', context) elif request.method == 'POST': form = NewEventDetailsForm(request.POST, instance=event) if form.is_valid: new_event = form.save() if form.cleaned_data.get('recurrences', None): new_series = EventSeries.from_event(new_event, recurrences=form.cleaned_data['recurrences']) new_series.save() new_event.series = new_series new_event.save() return redirect('new-event-add-team', new_event.id) else: context = { 'event': event, 'team': event.team, 'event_form': form, } return render(request, 'get_together/new_event/detail_event.html', context) else: return redirect('home')
def create_event(request, team_id): team = get_object_or_404(Team, id=team_id) if not request.user.profile.can_create_event(team): messages.add_message( request, messages.WARNING, message=_("You can not create events for this team."), ) return redirect("show-team-by-slug", team_slug=team.slug) new_event = Event(team=team, created_by=request.user.profile) if request.method == "GET": initial = {} if "common" in request.GET and request.GET["common"] != "": new_event.parent = CommonEvent.objects.get( id=request.GET["common"]) initial["name"] = new_event.parent.name initial["summary"] = new_event.parent.summary initial["start_time"] = new_event.parent.start_time initial["end_time"] = new_event.parent.end_time form = NewTeamEventForm(instance=new_event, initial=initial) context = {"event": new_event, "team": team, "event_form": form} return render(request, "get_together/events/create_event.html", context) elif request.method == "POST": if "common" in request.POST and request.POST["common"] != "": new_event.parent = CommonEvent.objects.get( id=request.POST["common"]) form = NewTeamEventForm(request.POST, instance=new_event) if form.is_valid: new_event = form.save() Attendee.objects.create( event=new_event, user=request.user.profile, role=Attendee.HOST, status=Attendee.YES, ) if form.cleaned_data.get("recurrences", None): new_series = EventSeries.from_event( new_event, recurrences=form.cleaned_data["recurrences"]) new_series.save() new_event.series = new_series new_event.save() messages.add_message( request, messages.SUCCESS, message= _("Your event has been scheduled! Next, find a place for your event." ), ) ga.add_event( request, action="new_event", category="activity", label=new_event.get_full_url(), ) return redirect("add-place", new_event.id) else: context = {"event": new_event, "team": team, "event_form": form} return render(request, "get_together/events/create_event.html", context) else: return redirect("home")