Ejemplo n.º 1
0
def get_update_request_events(req):
    event2 = req.event
    event1 = get_update_event(event2)
    images = None
    try:
        images = event1.imagetable_set.all()
    except AttributeError:
        images = []
        images.append(ImageTable.objects.get(pk=4))
    serializer1 = EventsSerializer(event1, many=False)
    serializer2 = EventsSerializer(event2, many=False)
    serializer3 = ImageTableSerializer(images, many=True)
    serializer4 = RequestSerializer(req, many=False)
    return Response({'event1': serializer1.data, 'event2': serializer2.data,
                     'images': serializer3.data, 'request': serializer4.data})
Ejemplo n.º 2
0
def search(request):
    str1 = request.data['search']
    user = User.objects.get(pk=int(request.data['user']))
    users = User.objects.all()
    events = Event.objects.filter(Q(status="APPROVED") | Q(status="HAPPENING TODAY") | Q(status="HAPPENED"))
    l1 = []
    l2 = []
    for u in users:
        if u.pk != user.pk:
            l1.append({'count': searchCount(u.username.lower(), str1.lower()), 'user': u})
    for e in events:
        l2.append({'count': searchCount(e.title.lower(), str1.lower()), 'event': e})
    l1.sort(key=lambda x: x['count'], reverse=True)
    l2.sort(key=lambda x: x['count'], reverse=True)
    l3 = []
    l4 = []
    for i in l1[:10]:
        l3.append(i['user'])
    for i in l2[:10]:
        l4.append(i['event'])
    l5 = []
    for i in l4:
        try:
            l5.append(i.imagetable_set.all()[0])
        except IndexError:
            l5.append(ImageTable.objects.get(pk=4))
    serializer1 = EventsSerializer(l4, many=True)
    serializer2 = UsersSerializer(l3, many=True)
    serializer3 = ImageTableSerializer(l5, many=True)
    return Response({'users': serializer2.data, 'events': serializer1.data, 'images':serializer3.data})
Ejemplo n.º 3
0
def get_event_attendees(request):
    check_events_happened()
    event = Event.objects.get(pk=request.data['event'])
    attendees = event.attendee_set.all()
    count = 0
    sum = 0
    for a in attendees:
        if a.feedback and a.feedback > 0:
            sum = sum + a.feedback
            count = count + 1
    try:
        average = float(sum / count)
    except ZeroDivisionError:
        average = 0.0
    l = []
    for a in attendees:
        reg = a.registration
        l.append(reg.payment)
    serializer = AttendeeSerializer(attendees, many=True)
    serializer2 = PaymentSerializer(l, many=True)
    serializer3 = EventsSerializer(event, many=False)
    return Response({
        'data': serializer.data,
        'payments': serializer2.data,
        'event': serializer3.data,
        'feedback': average,
        'count': count
    })
Ejemplo n.º 4
0
def get_admin_events_happened(request):
    check_events_happened()
    events = Event.objects.filter(status='HAPPENED')
    sold = []
    sales = []
    feedback = []
    for event in events:
        if event.total_tickets == 0:
            sold.append(0.0)
            sales.append(0.0)
        else:
            sold.append(
                (float(event.sold_tickets) / float(event.total_tickets)) * 100)
            sales.append(float(event.sold_tickets) * float(event.price_ticket))
        attendees = event.attendee_set.all()
        count = 0
        sum = 0
        for a in attendees:
            if a.feedback and a.feedback > 0:
                sum = sum + a.feedback
                count = count + 1
        if count == 0:
            feedback.append(0.0)
        else:
            feedback.append((float(sum)) / float(count))
    serializer = EventsSerializer(events, many=True)
    return Response({
        'events': serializer.data,
        'sold': list(sold),
        'feedback': list(feedback),
        'sales': list(sales)
    })
Ejemplo n.º 5
0
def get_event(request):
    check_events_happened()
    event = Event.objects.get(pk=request.data['event'])
    event = get_last_event(event)
    images = None
    try:
        images = event.imagetable_set.all()
    except AttributeError:
        images = []
        images.append(ImageTable.objects.get(pk=4))
    feedback = 0.0
    if event.status == 'HAPPENED':
        attendees = event.attendee_set.all()
        count = 0
        sum = 0
        for a in attendees:
            if a.feedback and a.feedback > 0:
                sum = sum + a.feedback
                count = count + 1
        if count > 0:
            feedback = (float(sum)) / float(count)
    serializer = EventsSerializer(event, many=False)
    serializer2 = ImageTableSerializer(images, many=True)
    return Response({
        'event': serializer.data,
        'images': serializer2.data,
        'feedback': feedback
    })
Ejemplo n.º 6
0
def search(request):
    str1 = request.data['search']
    user = User.objects.get(pk=int(request.data['user']))
    users = User.objects.all()
    events = Event.objects.filter(
        Q(status="APPROVED") | Q(status="HAPPENING TODAY")
        | Q(status="HAPPENED"))
    l1 = []
    l2 = []
    for u in users:
        if u.pk != user.pk:
            l1.append({
                'count': searchCount(u.username.lower(), str1.lower()),
                'user': u
            })
    for e in events:
        l2.append({
            'count': searchCount(e.title.lower(), str1.lower()),
            'event': e
        })
    l1.sort(key=lambda x: x['count'], reverse=True)
    l2.sort(key=lambda x: x['count'], reverse=True)
    l3 = []
    l4 = []
    for i in l1:
        l3.append(i['user'])
    for i in l2:
        l4.append(i['event'])
    serializer1 = EventsSerializer(l4, many=True)
    serializer2 = UsersSerializer(l3, many=True)
    return Response({'users': serializer2.data, 'events': serializer1.data})
Ejemplo n.º 7
0
def get_complete_user_data(request):
    user = User.objects.get(pk=request.data['user'])
    serializer = UsersSerializer(user, many=False)
    try:
        ratio = float(user.attendee_set.all().__len__()) / float(
            user.registration_set.all().__len__())
    except ZeroDivisionError:
        ratio = 0.0
    try:
        user2 = User.objects.get(pk=request.data['user2'])
        flag = True
    except:
        user2 = User()
        flag = False
    if user.is_organizer:
        events = user.event_set.filter(Q(status='APPROVED') | Q(status='HAPPENED') | Q(status='HAPPENING TODAY'))\
            .order_by('-id')
        organizer = user.organizer
        l = []
        feedback = []
        for event in events:
            try:
                l.append(event.imagetable_set.all()[0])
            except IndexError:
                l.append(ImageTable.objects.get(pk=4))
            attendees = event.attendee_set.all()
            count = 0
            sum = 0
            for a in attendees:
                if a.feedback and a.feedback > 0:
                    sum = sum + a.feedback
                    count = count + 1
            if count == 0:
                feedback.append(0.0)
            else:
                feedback.append((float(sum)) / float(count))
        serializer2 = EventsSerializer(events, many=True)
        serializer3 = OrganizerSerializer(organizer, many=False)
        serializer4 = ImageTableSerializer(l, many=True)
        return Response({
            'events': serializer2.data,
            'feedback': list(feedback),
            'images': serializer4.data,
            'organizer': serializer3.data,
            'user': serializer.data,
            'ratio': ratio
        })
    elif flag and user2.is_admin and user.organizerrequest_set.filter(
            status='PENDING').__len__() > 0:
        req = user.organizerrequest_set.filter(status='PENDING')
        serializer2 = OrganizerRequestSerializer(req, many=False)
        return Response({
            'user': serializer.data,
            'ratio': ratio,
            'request': serializer2.data
        })
    return Response({'user': serializer.data, 'ratio': ratio})
Ejemplo n.º 8
0
def get_registered_events(request):
    check_events_happened()
    user = User.objects.get(pk=request.data['user'])
    reg = user.registration_set.all().order_by('-id')
    l = []
    for r in reg:
        l.append(r.event)
    serializer = EventsSerializer(l, many=True)
    return Response(serializer.data)
Ejemplo n.º 9
0
def get_admin_events(request):
    events = Event.objects.filter(Q(status="APPROVED") | Q(status="HAPPENING TODAY") | Q(status="HAPPENED")).order_by('-id')
    sold = []
    for event in events:
        if event.total_tickets == 0:
            sold.append(str(0))
        else:
            sold.append((float(event.sold_tickets) / float(event.total_tickets)) * 100)
    serializer = EventsSerializer(events, many=True)
    return Response({'events': serializer.data, 'sold': list(sold)})
Ejemplo n.º 10
0
def get_request_data(request):
    req = Request.objects.get(pk=request.data['id'])
    if req.status == 'PENDING':
        if req.type == 'UPDATE':
            return get_update_request_events(req)
        else:
            if req.type == 'NEW':
                event1 = req.event
            else:
                event1 = get_last_event(req.event)
            images = None
            try:
                images = event1.imagetable_set.all()
            except AttributeError:
                images = []
                images.append(ImageTable.objects.get(pk=4))
            serializer1 = EventsSerializer(event1, many=False)
            serializer3 = ImageTableSerializer(images, many=True)
            serializer4 = RequestSerializer(req, many=False)
            return Response({
                'event1': serializer1.data,
                'images': serializer3.data,
                'request': serializer4.data
            })
    else:
        event1 = get_last_event(req.event)
        if event1 is None:
            return Response({'status': 'No Data Found'})
        images = None
        try:
            images = event1.imagetable_set.all()
        except AttributeError:
            images = []
            images.append(ImageTable.objects.get(pk=4))
        serializer1 = EventsSerializer(event1, many=False)
        serializer3 = ImageTableSerializer(images, many=True)
        serializer4 = RequestSerializer(req, many=False)
        return Response({
            'event1': serializer1.data,
            'images': serializer3.data,
            'request': serializer4.data
        })
Ejemplo n.º 11
0
def get_events():
    check_events_happened()
    events = Event.objects.filter(Q(status="APPROVED") | Q(status="HAPPENING TODAY"), event_date__gte=date.today())\
        .order_by('-id')
    l = []
    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})
Ejemplo n.º 12
0
def get_events_2(events):
    l = []
    l2 = []
    for e in events:
        if e.status == "HAPPENING TODAY" or e.status == "APPROVED":
            l.append(e)
            try:
                l2.append(e.imagetable_set.all()[0])
            except IndexError:
                l2.append(ImageTable.objects.get(pk=4))
    serializer = EventsSerializer(l, many=True)
    serializer2 = ImageTableSerializer(l2, many=True)
    return Response({'events': serializer.data, 'images': serializer2.data})
Ejemplo n.º 13
0
def get_admin_events_approved(request):
    check_events_happened()
    events = Event.objects.filter(status='APPROVED')
    sold = []
    sales = []
    for event in events:
        if event.total_tickets == 0:
            sold.append(0.0)
            sales.append(0.0)
        else:
            sold.append((float(event.sold_tickets) / float(event.total_tickets)) * 100)
            sales.append(float(event.sold_tickets) * float(event.price_ticket))
    serializer = EventsSerializer(events, many=True)
    return Response({'events': serializer.data, 'sold': list(sold), 'sales': list(sales)})
Ejemplo n.º 14
0
def get_history(event):
    check_events_happened()
    user = event.user
    events = user.event_set.filter(event_date__lt=date.today(), status="HAPPENED")\
        .order_by('-id')
    l = []
    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})
Ejemplo n.º 15
0
def get_registration(request):
    check_events_happened()
    registration = Registration.objects.get(pk=request.data['id'])
    event = registration.event
    event = get_last_event(event)
    images = None
    try:
        images = event.imagetable_set.all()
    except AttributeError:
        images = []
        images.append(ImageTable.objects.get(pk=4))
    serializer = EventsSerializer(event, many=False)
    serializer2 = ImageTableSerializer(images, many=True)
    serializer3 = RegistrationSerializer(registration, many=False)
    return Response({'event': serializer.data, 'images': serializer2.data, 'registration': serializer3.data})
Ejemplo n.º 16
0
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})
Ejemplo n.º 17
0
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})
Ejemplo n.º 18
0
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})