def get_requests_type(request): event_services.check_events_happened() requests = Request.objects.filter(Q(user__pk__gt=request.data['user']) | Q(user__pk__lt=request.data['user']), status=request.data['type']) serializer = RequestSerializer(requests, many=True) return Response(serializer.data)
def get_requests(request): event_services.check_events_happened() requests = Request.objects.filter( Q(user__pk__gt=request.data['user']) | Q(user__pk__lt=request.data['user'])).order_by('-id') serializer = RequestSerializer(requests, many=True) return Response(serializer.data)
def disapprove_organizer_request(id): event_services.check_events_happened() req = OrganizerRequest.objects.get(id=id) req.status = "DISAPPROVED" req.save() services.set_notification2( "SORRY YOUR REQUEST TO BECOME AN ORGANIZER HAS BEEN DISAPPROVED BY THE ADMIN\n", req.id, 'PROFILE') return get_organizer_requests()
def get_user(request): event_services.check_events_happened() user = User.objects.get(pk=request.data['user']) if user.is_organizer: organizer = user.organizer else: organizer = None serializer = UsersSerializer(user, many=False) serializer2 = OrganizerSerializer(organizer, many=False) return Response({'user': serializer.data, 'organizer': serializer2.data})
def get_organizer(request): event_services.check_events_happened() organizer = Organizer.objects.all() user = User.objects.get(pk=request.data['user']) o1 = {} for o in organizer: if o.user == user: o1 = o serializer = OrganizerSerializer(o1, many=False) context = serializer.data return Response(context)
def disapprove_request(request): event_services.check_events_happened() event_services.check_events_happened() req = Request.objects.get(id=request.data['id']) req.status = "DISAPPROVED" req.save() event = req.event event.status = "DISAPPROVED" event.save() services.set_notification( "SORRY YOUR REQUEST HAS BEEN DISAPPROVED BY THE ADMIN OF THIS SITE!\n" "BETTER LUCK NEXT TIME", req.id) return get_requests(request)
def approve_organizer_request(id): event_services.check_events_happened() req = OrganizerRequest.objects.get(id=id) req.status = "APPROVED" req.save() organizer = req.organizer organizer.user = req.user organizer.save() user = req.user user.is_organizer = True user.save() services.set_notification2( "CONGRATULATIONS YOUR REQUEST TO BECOME AN ORGANIZER HAS BEEN APPROVED BY THE ADMIN\n", req.id, 'PROFILE') return get_organizer_requests()
def add_organizer(request): event_services.check_events_happened() user = User.objects.get(id=request.data['user']) o = Organizer() o.address = request.data['address'] o.cnic = request.data['cnic'] o.phone_number = request.data['phone_number'] o.save() req = OrganizerRequest() req.status = 'PENDING' req.user = user req.user_name = user.username req.organizer = o req.save() return Response({'status': 'OK'})
def get_user_events_category(request): event_services.check_events_happened() user = User.objects.get(id=request.data['user']) l = [] events = user.event_set.filter( Q(status="HAPPENING TODAY") | Q(status="HAPPENED") | Q(status="APPROVED"), category=request.data['category']).order_by('-id') for i in events: try: l.append(i.imagetable_set.all()[0]) except IndexError: l.append(ImageTable.objects.get(pk=4)) serializer = EventsSerializer(events, many=True) serializer2 = ImageTableSerializer(l, many=True) return Response({'events': serializer.data, 'images': serializer2.data})
def get_user_event(request): event_services.check_events_happened() user = User.objects.get(id=request.data['user']) event = user.event_set.get(pk=request.data['event']) event = event_services.get_last_event(event) images = event.imagetable_set.all() """ images = None try: print(images) except AttributeError: images = [] images.append(ImageTable.objects.get(pk=4)) print(images) """ serializer = EventsSerializer(event, many=False) serializer2 = ImageTableSerializer(images, many=True) return Response({'event': serializer.data, 'images': serializer2.data})
def get_user_events(request): event_services.check_events_happened() user = User.objects.get(id=request.data['user']) events = user.event_set.filter(Q(status="HAPPENING TODAY") | Q(status="HAPPENED") | Q(status="APPROVED"))\ .order_by('-id') l2 = [] """ for e in user.event_set.all().exclude(status="UPDATED").exclude(status="DELETED").exclude(status="CANCELED")\ .exclude(status="REQUESTED").exclude(status="DISAPPROVED").order_by('-id'): # user.event_set.all(): if e.status == "APPROVED" or e.status == "HAPPENING TODAY" or e.status == "HAPPENED": l.append(event_services.get_last_event(e)) l.sort(key=lambda x: x.id, reverse=True) print(l) """ for i in events: try: l2.append(i.imagetable_set.all()[0]) except IndexError: l2.append(ImageTable.objects.get(pk=4)) serializer = EventsSerializer(events, many=True) serializer2 = ImageTableSerializer(l2, many=True) return Response({'events': serializer.data, 'images': serializer2.data})
def approve_request(id): event_services.check_events_happened() req = Request.objects.get(id=id) if req.type == "UPDATE": add_registrations_to_event(req.event) change_status2(req.event, "APPROVED") services.set_notification( "CONGRATULATIONS YOUR REQUEST FOR UPDATE HAS BEEN APPROVED BY THE ADMIN OF " "THIS SITE!", req.id, "ORGANIZER") services.notify_all_updated( "The Event " + req.event_title + " has been updated by the organizer " "of the event", req.event, "USER") elif req.type == "DELETE": add_registrations_to_event(req.event) change_status2(req.event, "DELETED") services.set_notification( "CONGRATULATIONS YOUR REQUEST FOR DELETE HAS BEEN APPROVED BY THE ADMIN OF " "THIS SITE!", req.id, "ORGANIZER") services.notify_all_updated( "Sorry To Inform you the event " + req.event_title + " has been deleted by the organizer. Your Payment will be refunded " "by the organizer as soon as Possible", req.event, "USER") elif req.type == "NEW": event = req.event event.status = "APPROVED" event.save() services.set_notification( "CONGRATULATIONS YOUR REQUEST HAS BEEN APPROVED BY THE ADMIN OF THIS SITE!", req.id, "ORGANIZER") services.notify_all( "A new Event Has Been Added That Might Be Of Your Interest! \nClick To Regist" "er As Soon As Possible!", req.event, "USER") req.status = "APPROVED" req.save() return get_requests()
def get_organizer_requests(): event_services.check_events_happened() requests = OrganizerRequest.objects.all().order_by('-id') serializer = OrganizerRequestSerializer(requests, many=True) return Response(serializer.data)
def get_user_requests_type(request): event_services.check_events_happened() user = User.objects.get(pk=request.data['user']) requests = user.request_set.filter(status=request.data['type']) serializer = RequestSerializer(requests, many=True) return Response(serializer.data)
def get_user_requests(request): event_services.check_events_happened() user = User.objects.get(pk=request.data['user']) req = user.request_set.all().order_by('-id') serializer = RequestSerializer(req, many=True) return Response(serializer.data)