def edit(request, p, q): if request.method == 'POST': post = request.POST event = Event.objects.get(event_id = int(q)) if p == 'event' and post['password'] == 'YYAJGF^&T@UJEGKJLneffls': event.event_name = post['name'] event.club = Club.objects.get(club_id = post['club']) event.startdate_participant = post['startdate_participant'] event.deadline_participant = post['deadline_participant'] event.participant_year_cutoff = post['participant_year_cutoff'] event.event_type = post['event_type'] event.description = post['description'] event.on = post['on'] event.save() if post['team_event'] == 'yes': event.teamevent = True event.save(update_fields = ['teamevent']) try: team_event = Team_Event.objects.get(event = event) team_event.min_participants = post['min_participants'] team_event.max_participants = post['max_participants'] except ObjectDoesNotExist: team_event = Team_Event(event = event, min_participants = post['min_participants'], max_participants = post['max_participants']) team_event.save() else: event.teamevent = False event.save(update_fields = ['teamevent']) try: team_event = Team_Event.objects.get(event = event) team_event.delete() except ObjectDoesNotExist: pass if post['mentor_provided'] == 'yes': event.mentorevent = True event.save(update_fields = ['mentorevent']) try: mentor_event = Mentor_Event.objects.get(event = event) mentor_event.deadline_mentor = post['deadline_mentor'] mentor_event.mentor_year_cutoff = post['mentor_year_cutoff'] except ObjectDoesNotExist: mentor_event = Mentor_Event(event = event, deadline_mentor = post['deadline_mentor'], mentor_year_cutoff = post['mentor_year_cutoff']) mentor_event.save() else: event.mentorevent = False event.save(update_fields = ['mentorevent']) try: mentor_event = Mentor_Event.objects.get(event = event) mentor_event.delete() except ObjectDoesNotExist: pass return redirect('success') else: if 'logged_in' in request.session: if p == 'event': try: event = Event.objects.get(event_id = int(q)) except ObjectDoesNotExist: return redirect('error', 15) min_participants = 0 max_participants = 0 mentor_year_cutoff = 2 deadline_mentor = datetime.now() if event.teamevent: team_event = Team_Event.objects.get(event = event) min_participants = team_event.min_participants max_participants = team_event.max_participants if event.mentorevent: mentor_event = Mentor_Event.objects.get(event = event) mentor_year_cutoff = mentor_event.mentor_year_cutoff deadline_mentor = mentor_event.deadline_mentor clubs = Club.objects.all() return render(request, 'edit_event.html', {'name': event.event_name, 'on': event.on, 'teamevent': event.teamevent, 'mentor_year_cutoff': mentor_year_cutoff, 'participant_year_cutoff': event.participant_year_cutoff, 'club': event.club.club_id, 'mentorevent': event.mentorevent, 'description': event.description, 'max_participants': max_participants, 'min_participants': min_participants, 'startdate_participant': event.startdate_participant, 'deadline_participant': event.deadline_participant, 'deadline_mentor': deadline_mentor, 'clubs': clubs, 'event_type': event.event_type}) elif p == 'club': try: club = Club.objects.get(event_id = int(q)) except ObjectDoesNotExist: return redirect('error', 16) else: return redirect('error', 14) else: return redirect('index')