Beispiel #1
0
def get_pastevent(request, userid):
    print("DateTime jaaaaaaaaa ")
    if request.method == 'GET':
        try:
            # date_now = datetime(2020,10,26,0,0,0)
            date_now = datetime.now()
            date_modified = datetime.now()
            print(date_modified)
            print("DateTime jaaaaaaaaa ")
            print(date_modified)
            print("DateTime jaaaaaaaaa ")
            print(datetime(2000,1,1,0,0,0))
            print("DateTime jaaaaaaaaa ")
        
            event = Event.objects.all().filter(eventenddate__lt=date_now, join__in=[userid],approve="2").distinct()

            print(event)

  
            serializer = EventSerializer(event, many=True)

        
            print(serializer.data)
        
            for et in serializer.data :
                et['total'] = 0
                                
                datetable = datetime(*time.strptime(et['eventenddate'][:19], "%Y-%m-%dT%H:%M:%S")[:6])
                diff = datetable - date_now
                # # b = ((diff.total_seconds() /60) / 60)/24
                print(diff)
                # a = diff.days * (-5)
                et['total'] = et['total'] + (diff.days * (-5))

            print(serializer.data)
            result = sorted(serializer.data, key=lambda data : data['total'], reverse=True)
            max_size = len(result)
            print('--------------------------------------------')
            print(max_size)
        

            query_string = request.GET
                      
            if 'st' in query_string  and 'ed' in query_string:
                st = int(query_string['st'])
                ed = int(query_string['ed'])
                result = result[st : ed]
            elif 'st' in query_string:
                st = int(query_string['st'])
                result = result[st:]
            elif 'ed' in query_string:
                ed = int(query_string['ed'])                
                result = result[:ed]
            
            return JsonResponse({ "max_size": max_size, "data": result }, safe=False)

            # return JsonResponse(result , safe=False)
            
        except Event.DoesNotExist:
            return HttpResponse(status=404)
Beispiel #2
0
def get_yourevent(request, userid):
    if request.method == 'GET':
        try:
            event = Event.objects.all().filter(createby=userid, approve="2")
            serializer = EventSerializer(event, many=True)                     

            result = serializer.data    
            max_size = len(result)
            
            query_string = request.GET
            if 'st' in query_string  and 'ed' in query_string:
                st = int(query_string['st'])
                ed = int(query_string['ed'])
                result = result[st : ed]
            elif 'st' in query_string:
                st = int(query_string['st'])
                result = result[st:]
            elif 'ed' in query_string:
                ed = int(query_string['ed'])                
                result = result[:ed]
            
            return JsonResponse({ "max_size": max_size, "data": result }, safe=False)
            
        except Event.DoesNotExist:
            return HttpResponse(status=404)
Beispiel #3
0
def event_detail(request, pk):
    """
    Retrieve, update or delete a code .
    """
    try:
        event = Event.objects.get(pk=pk)
    except Event.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = EventSerializer(event)
        return JsonResponse(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)       
        print("=================")
        date_modified = datetime.now()
        print(data)
        # print(data['createby'])
        data['updatedate'] = date_modified
        print(data)

        serializer = EventSerializer(event, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data)
        print(serializer.errors)
        return JsonResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        event.delete()
        return HttpResponse(status=204)
Beispiel #4
0
def event_list(request):
    """
    List all code event, or create a new event.
    """
    if request.method == 'GET':
        event = Event.objects.all().filter(approve="2")
        serializer = EventSerializer(event, many=True)  
        return JsonResponse(serializer.data, safe=False)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        date_modified = datetime.now()
        data['createdate'] = date_modified
        data['bcapprove'] = ""
        # data['posterpic'] = "555"
        data['updatedate'] = None
        data['active'] = True
        data['approve'] = "1"
        print(data)
        serializer = EventSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            print("serializer.data : =======================")
            print(serializer.data)
            return JsonResponse(serializer.data, status=201)
        print(serializer.errors)
        return JsonResponse(serializer.errors, status=400)
Beispiel #5
0
def get_join(request, eventid):
    if request.method == 'GET':
        try:
            event = Event.objects.get(id=eventid)
            serializer = EventSerializer(event)
            print(serializer.data['join'])
            
            user = User.objects.all().filter(userid__in=list(serializer.data['join']))

            print(user)

            user_serializer = UserSerializer(user, many=True)

            return JsonResponse(user_serializer.data, safe=False)            
                     
        except Event.DoesNotExist:
            return HttpResponse(status=404)
Beispiel #6
0
def get_autoCompleteWords(request,word ,categoryid):
    print("DateTime jaaaaaaaaa ")
    if request.method == 'GET':
        try:
            # query_string = request.GET  
            # datetime.now()        
            # date_now = datetime(2010,1,26,0,0,0)
            date_now = datetime.now()
            
            date_modified = datetime.now()
            print(date_modified)
            print("DateTime jaaaaaaaaa ")
            print(date_modified)
            print("DateTime jaaaaaaaaa ")
            print(datetime(2000,1,1,0,0,0))
            print("DateTime jaaaaaaaaa ")
            print("DateTime jaaaaaaaaa ")
            print("DateTime jaaaaaaaaa ")
            
            # if 'searchword' in query_string :
                # searchword = query_string['searchword']
            category = Category.objects.all().filter(categoryname__icontains=word ).values_list('pk', flat=True)
            print(category)

            if categoryid == 0 :
                event = Event.objects.all().filter(Q(topic__icontains=word) | Q(hashtag__icontains=word) | Q(description__icontains=word) | Q(categoryid__in=list(category)) ,approve="2").distinct()
            else :   
                event = Event.objects.all().filter(Q(topic__icontains=word) | Q(hashtag__icontains=word) | Q(description__icontains=word) | Q(categoryid__in=list(category)) , categoryid = categoryid,approve="2").distinct()
        
            print(event)

            serializer = EventSerializer(event, many=True)
            category_serializer = list(category)
            print(serializer.data)
            print(category_serializer)
            # print(category)

            allwords = {}

            for et in serializer.data :
                # et['total'] = 0
                if et['topic'] is None :
                    et['topic'] = ''
                if et['description'] is None:
                    et['description'] = ''
                if et['hashtag'] is None:
                    et['hashtag'] = ''
                
                allstr = et['topic']+" "+et['description']+" "+et['hashtag']
                splitwords = allstr.split(" ")

                print("+++++++++++++++++++++++++++++++++++++++++++++")
                print(splitwords)

                for inwords in splitwords :
                    print(inwords)
                    if inwords.find(word) != -1 :
                        # print(allwords[inwords])
                        if inwords in allwords :
                            allwords[inwords] = allwords[inwords] + 1
                            print("55555555555555555555555555")
                            print(allwords[inwords])

                        else :
                            allwords[inwords] = 1 

            # print("*************************++++++++++++++++++++++++++++++++++++")
            # print(allwords)

            sorted_allwords = sorted(allwords, key=allwords.get, reverse=True)
            # sorted_allwords = [(k, allwords[k]) for k in sorted(allwords, key=allwords.values, reverse=True)]
            # dict.values(sorted)
            # print("-------------------------------------------")
            # print(sorted_allwords)
            # print("/////////////////////////////////////////////////////////////////")
            # print(sorted_allwords.keys())
            result = sorted_allwords[0 : 9]
            # print("**************************************************")
            # print(allwords.values())
            # print("----------------------------------------//////////////////////////////////")
            # print(result) 
            return JsonResponse({"data": result }, safe=False)
        except Event.DoesNotExist: 
            return HttpResponse(status=404)
Beispiel #7
0
def get_searchevent(request, categoryid):
    print("DateTime jaaaaaaaaa ")
    if request.method == 'GET':
        try:
            query_string = request.GET
            print("Input")
            print(query_string)
            # date_now = datetime(2010,1,26,0,0,0)
            date_now = datetime.now()
            date_modified = datetime.now()
            print(date_modified)
            print("DateTime jaaaaaaaaa ")
            print(date_modified)
            print("DateTime jaaaaaaaaa ")
            print(datetime(2000,1,1,0,0,0))
            print("DateTime jaaaaaaaaa ")

            # print()
            
            if 'searchword' in query_string :
                searchword = query_string['searchword']
                category = Category.objects.all().values_list('pk', flat=True)
                print(category)

                if categoryid == 0 :
                    print('cate =============.====================================')
                    event = Event.objects.all().filter(Q(topic__icontains=searchword) | Q(hashtag__icontains=searchword), approve="2").distinct()
                else :   
                    event = Event.objects.all().filter(Q(topic__icontains=searchword) | Q(hashtag__icontains=searchword), categoryid = categoryid, approve="2").distinct()
            
                print(event)

                serializer = EventSerializer(event, many=True)
                category_serializer = list(category)
                print('result ============================================')
                print(serializer.data)
                print(category_serializer)
                # print(category)
                for et in serializer.data :
                    et['total'] = 0
                    if et['topic'] is None :
                        et['topic'] = ''
                    if et['description'] is None:
                        et['description'] = ''
                    if et['hashtag'] is None:
                        et['hashtag'] = ''

                    if et['topic'].find(searchword) != -1 :
                        et['total'] = et['total'] + 100
                    
                    etsplit = et['hashtag'].split('#')
                    for  sp in etsplit :
                        if sp.find(searchword) != -1 :
                            et['total'] = et['total'] + 30

                    if et['description'].find(searchword) != -1 :
                        et['total'] = et['total'] + 40
                                    
                    datetable = datetime(*time.strptime(et['eventenddate'][:19], "%Y-%m-%dT%H:%M:%S")[:6])
                    diff = datetable - date_now
                    print(diff)
                    et['total'] = et['total'] + (diff.days * (-5))

                    for ct in category_serializer :
                        print(et['categoryid'])
                        for ec in et['categoryid'] :
                            if ct == ec :
                                et['total'] = et['total'] + 25    
                                
                result = sorted(serializer.data, key=lambda data : data['total'], reverse=True)     
                max_size = len(result)
                print('--------------------------------------------')
                print(max_size)
            
            else :
                if categoryid == 0 :
                    event = Event.objects.all().filter(eventenddate__gt=date_now,approve="2").distinct()
                else :   
                    event = Event.objects.all().filter(eventenddate__gt=date_now, categoryid = categoryid, approve="2").distinct()

                serializer = EventSerializer(event, many=True)
                
                print(serializer.data)
                
                for et in serializer.data :
                    et['total'] = 0
                                    
                    datetable = datetime(*time.strptime(et['eventenddate'][:19], "%Y-%m-%dT%H:%M:%S")[:6])
                    diff = datetable - date_now
                    print(diff)
                    et['total'] = et['total'] + (diff.days * (-5))  
                                
                result = sorted(serializer.data, key=lambda data : data['total'], reverse=True)     
                max_size = len(result)
                print('--------------------------------------------')
                print(max_size)
                       

            if 'st' in query_string  and 'ed' in query_string:
                st = int(query_string['st'])
                ed = int(query_string['ed'])
                result = result[st : ed]
            elif 'st' in query_string:
                st = int(query_string['st'])
                result = result[st:]
            elif 'ed' in query_string:
                ed = int(query_string['ed'])                
                result = result[:ed]

            print("Output")
            print(result)
            
            return JsonResponse({ "max_size": max_size, "data": result }, safe=False)
        except Event.DoesNotExist:
            return HttpResponse(status=404)