本文整理汇总了Python中subscription.models.Subscription.getByIp方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.getByIp方法的具体用法?Python Subscription.getByIp怎么用?Python Subscription.getByIp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subscription.models.Subscription
的用法示例。
在下文中一共展示了Subscription.getByIp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import getByIp [as 别名]
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)