Ejemplo n.º 1
0
def add(request, q):
    if request.method == 'POST':
        post = request.POST
        if q == 'event' and post['password'] == 'gadjgi87*y*(YKJhkjhkes':
            event = Event(event_name = post['name'], club = Club.objects.get(club_id = post['club']), startdate_participant = post['startdate_participant'], deadline_participant = post['deadline_participant'], participant_year_cutoff = post['participant_year_cutoff'], event_type = post['event_type'], description = post['description'], on = post['on'])
            event.save()
            if post['team_event'] == 'yes':
                event.teamevent = True
                event.save(update_fields = ['teamevent'])
                team_event = Team_Event(event = event, min_participants = post['min_participants'], max_participants = post['max_participants'])
                team_event.save()
            if post['mentor_provided'] == 'yes':
                event.mentorevent = True
                event.save(update_fields = ['mentorevent'])
                mentor_event = Mentor_Event(event = event, deadline_mentor = post['deadline_mentor'], mentor_year_cutoff = post['mentor_year_cutoff'])
                mentor_event.save()
            return redirect('success')
        elif q == 'club' and post['password'] == '!#%$DGHSfjyt78uGU&%':
            form = Club_Form(post)
            if form.is_valid():
                form.save()
                return redirect('success')
            else:
                return redirect('error', 13)
        else:
            return redirect('error', 13)
    else:
        if 'logged_in' in request.session:
            if q == 'event':
                clubs = Club.objects.all()
                return render(request, 'add_event.html', {'clubs': clubs, 'id_token': request.session['id_token'], 'student_id': request.session['email']})
            elif q == 'club':
                form = Club_Form()
                return render(request, 'add_club.html', {'form': form, 'id_token': request.session['id_token'], 'student_id': request.session['email']})
            else:
                return redirect('error', 14)
        else:
            return redirect('index')
Ejemplo n.º 2
0
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')