Пример #1
0
 def put(self, request, pk):
     subscription = Subscription.objects.get(subscriptionId=pk)
     serializer = SubscriptionSerializer(subscription, data=request.data)
     if serializer.is_valid():
         subscription = serializer.save()
         transaction = SubscriptionTransaction.createFromSubscription(subscription, 'renew')
         returnData = serializer.data
         returnData['subscriptionTransactionId']=transaction.subscriptionTransactionId
         return Response(returnData)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
 def put(self, request, pk):
     subscription = Subscription.objects.get(subscriptionId=pk)
     serializer = SubscriptionSerializer(subscription, data=request.data)
     if serializer.is_valid():
         subscription = serializer.save()
         transaction = SubscriptionTransaction.createFromSubscription(subscription, 'renew')
         returnData = serializer.data
         returnData['subscriptionTransactionId']=transaction.subscriptionTransactionId
         return Response(returnData)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
 def create(self, validated_data):
     user = User.objects.create_user(validated_data['username'],
                                     validated_data['email'],
                                     validated_data['password'])
     # Assign a new user default top 5 coins
     default_coins = Coin.objects.order_by('rank')[:5]
     for coin in default_coins:
         # Subscription serializer field for user model is a readonly field so we need to pass that data in save
         default_subscription_serializer = SubscriptionSerializer(
             data={'coin': coin.slug})
         # validation
         if default_subscription_serializer.is_valid():
             default_subscription_serializer.save(owner=user)
     return user
Пример #4
0
 def get(self, request):
     if not 'partnerId' in request.GET:
         return Response({'error':'partnerId is required'}, status=status.HTTP_400_BAD_REQUEST)
     partnerId=request.GET.get("partnerId")
     if 'ipAddress' in request.GET:
         ipAddress=request.GET.get("ipAddress")
     else:
         ipAddress=getRemoteIpAddress(request)
     isMember = False
     expDate = ""
     name = ""
     imageUrl = ""
     ipSub = Subscription.getActiveByIp(ipAddress, partnerId)
     subList = SubscriptionSerializer(ipSub, many=True).data
     if subList != []:
         isMember = True
         for sub in subList:
             if expDate == "":
                 expDate = sub['endDate']
             else:
                 expDate = max(expDate, sub['endDate'])
             items = ImageInfo.objects.all().filter(partyId=sub['partyId'])
             if (items.exists()):
                 memberInfo = items[0]
                 name = memberInfo.name
                 imageUrl = memberInfo.imageUrl
     return HttpResponse(json.dumps({'isMember':isMember, 'expDate':expDate, "name":name, "imageUrl":imageUrl }), content_type="application/json")
Пример #5
0
    def get(self, request, *args, **kwargs):
        # Checking if user is authenticated
        if request.user.is_authenticated():
            # Getting the new subscription count
            observers = []

            for item in SubscriptionController.GetObservers(request.user):
                if item.timestamp > request.user.last_login:
                    observers.append(SubscriptionSerializer(item).data)
            # Getting the new review count
            reviews = []

            for item in ReviewController.ReviewsForUser(request.user):
                if item.created > request.user.last_login and item.added_by != request.user:
                    reviews.append({
                        'review':
                        ReviewSerializer(item).data,
                        'topic_list':
                        ReviewTopicController.GetTopics(item)
                    })

            # Returning the response with reviews and subscription list
            return JsonResponse({
                'Reviews': reviews,
                'Observers': observers,
                'UserAuthenticated': True
            })
        else:
            # User is not authenticated
            return JsonResponse({'UserAuthenticated': False})
Пример #6
0
 def put(self, request):
     if not isPhoenix(request):
        return HttpResponse(status=400)
     # partnerId = request.GET.get('partnerId')
     # subscription = Subscription.objects.all().filter(partnerId=partnerId)[0]
     if 'subscriptionId' in request.GET:
         subscriptionId = request.GET.get('subscriptionId')
         subscription = Subscription.objects.all().get(subscriptionId=subscriptionId)
     else:
         return Response({'error':'subscriptionId required'})
     serializer = SubscriptionSerializer(subscription, data=request.data)
     if serializer.is_valid():
         subscription = serializer.save()
         returnData = serializer.data
         return Response(returnData)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #7
0
 def get(self, request, partyId):
     allSubscriptions = Subscription.objects.all().filter(partyId=partyId)
     serializer = SubscriptionSerializer(allSubscriptions, many=True)
     #return HttpResponse(json.dumps(dict(serializer.data)))
     ret = {}
     for s in serializer.data:
         ret[s['partnerId']] = dict(s)
     return HttpResponse(json.dumps(ret), status=200)
Пример #8
0
 def get(self, request, partyId):
     now = datetime.datetime.now()
     activeSubscriptions = Subscription.objects.all().filter(partyId=partyId).filter(endDate__gt=now).filter(startDate__lt=now)
     serializer = SubscriptionSerializer(activeSubscriptions, many=True)
 #return HttpResponse(json.dumps(dict(serializer.data)))
     ret = {}
     for s in serializer.data:
         ret[s['partnerId']] = dict(s)
     return HttpResponse(json.dumps(ret), status=200)
Пример #9
0
 def get(self,request):
     params = request.GET
     partnerId = params['partnerId']
     ipAddress = params['ipAddress']
     userIdentifier = params['userIdentifier']
     idSub = None #Pw-418
     subList = [] #Pw-418
     ipSub = Subscription.getActiveByIp(ipAddress, partnerId)
     if Credential.objects.filter(userIdentifier=userIdentifier).filter(partnerId=partnerId).exists():
         partyId = Credential.objects.filter(partnerId=partnerId).filter(userIdentifier=userIdentifier)[0].partyId.partyId
         idSub = Subscription.getActiveById(partyId, partnerId)
     if (idSub):
         subList = SubscriptionSerializer(ipSub, many=True).data+SubscriptionSerializer(idSub, many=True).data
     else:
         subList = SubscriptionSerializer(ipSub, many=True).data
     for sub in subList:
         if Party.objects.filter(partyId = sub['partyId']).exists():
             party = PartySerializer(Party.objects.get(partyId = sub['partyId'])).data
             sub['partyType'] = party['partyType']
             sub['name'] = party['name']
     return HttpResponse(json.dumps(subList), content_type="application/json")
Пример #10
0
 def get(self, request):
     partnerId=request.GET.get("partnerId")
     if 'ipAddress' in request.GET:
         ipAddress=request.GET.get("ipAddress")
     else:
         ipAddress=getRemoteIpAddress(request)
     partyId = None
     if 'partyId' in request.GET:
         partyId = request.GET.get('partyId')
     elif 'userIdentifier' in request.GET:
         userIdentifier=request.GET.get("userIdentifier")
     else:
         return Response({'error':'partyId or userIdentifier is required'}, status=status.HTTP_400_BAD_REQUEST)
     expDate = ""
     subscribed = False
     ipSub = Subscription.getActiveByIp(ipAddress, partnerId)
     idSub = None #Pw-418
     subList = [] #Pw-418
     subscriptionType = None
     if not partyId:
         if Credential.objects.filter(userIdentifier=userIdentifier).filter(partnerId=partnerId).exists():
             partyId = Credential.objects.filter(partnerId=partnerId).filter(userIdentifier=userIdentifier)[0].partyId.partyId
             idSub = Subscription.getActiveById(partyId, partnerId)
     else:
         try:
             idSub = Subscription.getActiveById(partyId, partnerId)
         except:
             return Response({'error':'getting active susbcription by id failed'}, status=status.HTTP_400_BAD_REQUEST)
     if (idSub):
         subList = SubscriptionSerializer(ipSub, many=True).data+SubscriptionSerializer(idSub, many=True).data
     else:
         subList = SubscriptionSerializer(ipSub, many=True).data
     if subList != []:
         subscribed = True
         expDate = max(sub['endDate'] for sub in subList)
         if ipSub:
             subscriptionType = 'institutional'
         elif idSub:
             subscriptionType = 'individual'
     return HttpResponse(json.dumps({'expDate':expDate, 'subscribed':subscribed, 'subscriptionType':subscriptionType}), content_type="application/json")
Пример #11
0
 def get(self, request, partyId):
     ret = {}
     now = datetime.datetime.now()
     if Party.objects.all().get(partyId=partyId):
         consortiums = Party.objects.all().get(partyId=partyId).consortiums.all()
         for consortium in consortiums:
             consortiumActiveSubscriptions = Subscription.objects.all().filter(partyId=consortium.partyId).filter(endDate__gt=now).filter(startDate__lt=now)
             serializer = SubscriptionSerializer(consortiumActiveSubscriptions, many=True)
             partySerializer = PartySerializer(consortium)
             for s in serializer.data:
                 if s['partnerId'] in ret:
                     ret[s['partnerId']].append(partySerializer.data)
                 else:
                     ret[s['partnerId']] = []
                     ret[s['partnerId']].append(partySerializer.data)
     return HttpResponse(json.dumps(ret), status=200)
Пример #12
0
class UserProfileSerializer(serializers.Serializer):
    total_money = serializers.SerializerMethodField()
    start_money = serializers.SerializerMethodField()
    free_money = serializers.SerializerMethodField()
    subscription = SubscriptionSerializer(many=True)

    def get_total_money(self, obj):
        return obj.get_total_money()

    def get_start_money(self, obj):
        return obj.initial_money

    def get_free_money(self, obj):
        return obj.free_money

    class Meta:
        fields = ('total_money', 'start_money', 'subscription', 'free_money')
Пример #13
0
 def get(self, request):
     params = request.GET
     if 'subscriptionId' in request.GET:
         subscriptionId = request.GET.get('subscriptionId')
         subscription = Subscription.objects.all().get(subscriptionId=subscriptionId)
         serializer = SubscriptionSerializer(subscription)
         return Response(serializer.data)
     elif 'partyId' in params:
         partyId = params['partyId']
         now = datetime.datetime.now()
         if 'checkConsortium' in params and params['checkConsortium'] == 'true':
             partnerIdList = Partner.objects.all().values_list('partnerId', flat=True)
             idSub = []
             allSub = Subscription.getById(partyId)
             for partnerId in partnerIdList:
                 if allSub.filter(partnerId=partnerId).filter(endDate__gt=now).filter(startDate__lt=now).exists():
                     idSub.append(allSub.filter(partnerId=partnerId).filter(endDate__gt=now).filter(startDate__lt=now).latest('endDate'))
             serializer = SubscriptionSerializer(idSub, many=True)
         elif 'active' in params and params['active'] == 'true':
             activeSubscriptions = Subscription.objects.all().filter(partyId=partyId).filter(endDate__gt=now).filter(startDate__lt=now)
             serializer = SubscriptionSerializer(activeSubscriptions, many=True)
         else:
             allSubscriptions = Subscription.objects.all().filter(partyId=partyId)
             serializer = SubscriptionSerializer(allSubscriptions, many=True)
         return Response(serializer.data, status=200)
     elif all(param in params for param in ['partnerId', 'ipAddress', 'userIdentifier']):
         partnerId = params['partnerId']
         ipAddress = params['ipAddress']
         userIdentifier = params['userIdentifier']
         idSub = None #Pw-418
         subList = [] #Pw-418
         ipSub = Subscription.getByIp(ipAddress).filter(partnerId=partnerId)
         if Credential.objects.filter(userIdentifier=userIdentifier).filter(partnerId=partnerId).exists():
             partyId = Credential.objects.filter(partnerId=partnerId).filter(userIdentifier=userIdentifier)[0].partyId.partyId
             idSub = Subscription.getById(partyId).filter(partnerId=partnerId)
         if (idSub):
             subList = SubscriptionSerializer(ipSub, many=True).data+SubscriptionSerializer(idSub, many=True).data
         else:
             subList = SubscriptionSerializer(ipSub, many=True).data
         for sub in subList:
             if Party.objects.filter(partyId = sub['partyId']).exists():
                 party = PartySerializer(Party.objects.get(partyId = sub['partyId'])).data
                 sub['partyType'] = party['partyType']
                 sub['name'] = party['name']
         return HttpResponse(json.dumps(subList), content_type="application/json")
     else:
         return Response({"error":"Essential parameters needed."}, status=status.HTTP_400_BAD_REQUEST)
Пример #14
0
 def get(self, request):
     params = request.GET
     if not 'partyId' in params:
         return Response({'error':'partyId is required'}, status=status.HTTP_400_BAD_REQUEST)
     ret = {}
     now = datetime.datetime.now()
     partyId = params['partyId']
     if 'active' in params and params['active'] == 'true':
         if Party.objects.all().get(partyId=partyId):
             consortiums = Party.objects.all().get(partyId=partyId).consortiums.all()
             for consortium in consortiums:
                 consortiumActiveSubscriptions = Subscription.objects.all().filter(partyId=consortium.partyId).filter(endDate__gt=now).filter(startDate__lt=now)
                 serializer = SubscriptionSerializer(consortiumActiveSubscriptions, many=True)
                 partySerializer = PartySerializer(consortium)
                 for s in serializer.data:
                     if s['partnerId'] in ret:
                         ret[s['partnerId']].append(partySerializer.data)
                     else:
                         ret[s['partnerId']] = []
                         ret[s['partnerId']].append(partySerializer.data)
     return Response(ret, status=200)
Пример #15
0
        'country': countryId,
    }

    serializer = PartySerializer(data=data)
    if serializer.is_valid():
        serializer.save()

    partyId = serializer.data['partyId']
    orgIdPartyId[organizationId] = partyId
    data = {
        'partyId': partyId,
        'partnerId': partnerId,
        'startDate': startDate,
        'endDate': endDate,
    }
    serializer = SubscriptionSerializer(data=data)
    if serializer.is_valid():
        serializer.save()
    else:
        print "CANNOT SAVE SUBSCRIPTION"
        print data

    subscriptionId = serializer.data['subscriptionId']
    data = {
        'subscriptionId': subscriptionId,
        'startDate': startDate,
        'endDate': endDate,
        'transactionDate': startDate,
        'transactionType': 'create',
    }
    serializer = SubscriptionTransactionSerializer(data=data)
    cred = Credential.objects.all().filter(userIdentifier=communityId)
    if len(cred) > 0:
        partyId = cred[0].partyId.partyId
    else:
        print "not good %s" % communityId
        continue
    
    startDate = parseTime("21-DEC-12")
    endDate = parseTime(expirationDate)
    data = {
        'partyId':partyId,
        'partnerId':partnerId,
        'startDate':startDate,
        'endDate':endDate,
    }
    serializer = SubscriptionSerializer(data=data)
    if serializer.is_valid():
        serializer.save()
    else:
        print "CANNOT SAVE SUBSCRIPTION"
        print data

    subscriptionId = serializer.data['subscriptionId']
    data = {
        'subscriptionId':subscriptionId,
        'startDate':startDate,
        'endDate':endDate,
        'transactionDate':startDate,
        'transactionType':'create',
    }
    serializer = SubscriptionTransactionSerializer(data=data)
Пример #17
0
    cred = Credential.objects.all().filter(userIdentifier=communityId)
    if len(cred) > 0:
        partyId = cred[0].partyId.partyId
    else:
        print "not good %s" % communityId
        continue

    startDate = parseTime("21-DEC-12")
    endDate = parseTime(expirationDate)
    data = {
        'partyId': partyId,
        'partnerId': partnerId,
        'startDate': startDate,
        'endDate': endDate,
    }
    serializer = SubscriptionSerializer(data=data)
    if serializer.is_valid():
        serializer.save()
    else:
        print "CANNOT SAVE SUBSCRIPTION"
        print data

    subscriptionId = serializer.data['subscriptionId']
    data = {
        'subscriptionId': subscriptionId,
        'startDate': startDate,
        'endDate': endDate,
        'transactionDate': startDate,
        'transactionType': 'create',
    }
    serializer = SubscriptionTransactionSerializer(data=data)