def invite_friend(request, event_id): if request.method == 'POST': event = Event.objects.get(pk=event_id) selected_friendList = request.POST.getlist('friendList') for selected_friend_id in selected_friendList: selected_friend = User.objects.get(pk=selected_friend_id) attendence = Attendence() attendence.participant = selected_friend attendence.event = event isInvited = True attendence.save() return HttpResponseRedirect(("../../{}").format(event_id)) else: friendProfileList = request.user.get_profile().friends.all() friendList = [] if friendProfileList.exists(): for friendProfile in friendProfileList: attendence = Attendence.objects \ .filter(event_id=event_id,participant=friendProfile.user)[:1] if len(attendence) == 0: friendList.append(friendProfile.user) return render(request, 'eventdapp/invite.html',{ 'friendList' : friendList, 'event_id' : event_id, })
def invite_friend(request, event_id): if request.method == 'POST': event = Event.objects.get(pk=event_id) selected_friendList = request.POST.getlist('friendList') for selected_friend_id in selected_friendList: selected_friend = User.objects.get(pk=selected_friend_id) attendence = Attendence() attendence.participant = selected_friend attendence.event = event isInvited = True attendence.save() return HttpResponseRedirect(("../../{}").format(event_id)) else: friendProfileList = request.user.get_profile().friends.all() friendList = [] if friendProfileList.exists(): for friendProfile in friendProfileList: attendence = Attendence.objects \ .filter(event_id=event_id,participant=friendProfile.user)[:1] if len(attendence) == 0: friendList.append(friendProfile.user) return render(request, 'eventdapp/invite.html', { 'friendList': friendList, 'event_id': event_id, })
def attend_event(request, event_id, is_going): event = Event.objects.get(pk=event_id) attendence = Attendence.objects.filter(event__pk = event.id, participant__pk = request.user.id) user = request.user is_going = is_going.upper() if not Attendence.is_valid_participation(is_going): raise Http404 if not attendence.exists(): new_attendence = Attendence() new_attendence.participant = user new_attendence.event = event new_attendence.participation = is_going new_attendence.save() elif attendence.exists(): att = attendence[0] att.participation = is_going att.save() return HttpResponseRedirect(("../../../{}").format(event.id))
def attend_event(request, event_id, is_going): event = Event.objects.get(pk=event_id) attendence = Attendence.objects.filter(event__pk=event.id, participant__pk=request.user.id) user = request.user is_going = is_going.upper() if not Attendence.is_valid_participation(is_going): raise Http404 if not attendence.exists(): new_attendence = Attendence() new_attendence.participant = user new_attendence.event = event new_attendence.participation = is_going new_attendence.save() elif attendence.exists(): att = attendence[0] att.participation = is_going att.save() return HttpResponseRedirect(("../../../{}").format(event.id))