本文整理汇总了Python中frog.common.Result.asDict方法的典型用法代码示例。如果您正苦于以下问题:Python Result.asDict方法的具体用法?Python Result.asDict怎么用?Python Result.asDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frog.common.Result
的用法示例。
在下文中一共展示了Result.asDict方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getUser
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def getUser(request):
res = Result()
data = {}
if request.user.is_anonymous():
res.isError = True
data['prefs'] = DefaultPrefs
elif request.GET.get('q'):
return JsonResponse(res.asDict())
else:
data['user'] = userToJson(request.user)
data['user']['isManager'] = any(request.user.groups.filter(name='manager')) or request.user.is_staff
data['gallery'] = None
personal = Gallery.objects.filter(owner=request.user, security=Gallery.PERSONAL)
if personal:
data['personal_gallery'] = personal[0].json()
data['prefs'] = request.user.frog_prefs.get_or_create(user=request.user)[0].json()
galleryid = request.GET.get('gallery')
if galleryid is not None:
gallery = Gallery.objects.filter(pk=galleryid, owner=request.user)
if gallery:
data['gallery'] = gallery[0].json()
res.append(data)
return JsonResponse(res.asDict())
示例2: get
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def get(request, obj_id=None):
"""Lists all tags
:returns: json
"""
res = Result()
if obj_id:
if obj_id == '0':
obj = {
'id': 0,
'name': 'TAGLESS',
'artist': False,
}
else:
obj = get_object_or_404(Tag, pk=obj_id).json()
res.append(obj)
return JsonResponse(res.asDict())
else:
if request.GET.get('count'):
itags = Tag.objects.all().annotate(icount=Count('image'))
vtags = Tag.objects.all().annotate(vcount=Count('video'))
for i, tag in enumerate(itags):
tag.count = itags[i].icount + vtags[i].vcount
res.append(tag.json())
else:
for tag in Tag.objects.all():
res.append(tag.json())
return JsonResponse(res.asDict())
示例3: userList
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def userList(request):
res = Result()
for user in User.objects.filter(is_active=True).order_by('first_name'):
res.append(userToJson(user))
return JsonResponse(res.asDict())
示例4: isUnique
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def isUnique(request):
data = request.POST or json.loads(request.body)['body']
paths = data.get('paths', [])
res = Result()
if data.get('user'):
user = User.objects.get(username=data['user'])
elif request.user.is_anonymous():
raise HttpResponseForbidden
else:
user = request.user
for path in paths:
uniqueid = Piece.getUniqueID(path, user)
img = Image.objects.filter(unique_id=uniqueid)
vid = Video.objects.filter(unique_id=uniqueid)
if img:
res.append(img[0].json())
elif vid:
res.append(vid[0].json())
else:
res.append(True)
return JsonResponse(res.asDict())
示例5: switchArtist
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def switchArtist(request):
data = request.POST or json.loads(request.body)['body']
artist = data.get('artist', None)
guids = data.get('guids', '').split(',')
res = Result()
if artist:
if isinstance(artist, int):
author = User.objects.get(pk=artist)
tag = Tag.objects.get_or_create(name=author.get_full_name().lower(), defaults={'artist': True})[0]
else:
first, last = artist.lower().split(' ')
author = User.objects.get_or_create(first_name=first, last_name=last, defaults={
'username': '%s%s' % (first[0], last),
})[0]
tag = Tag.objects.get_or_create(name=artist.lower(), defaults={'artist': True})[0]
objects = getObjectsFromGuids(guids)
for n in objects:
n.author = author
n.tagArtist(tag)
res.append(userToJson(author))
res.value['tag'] = tag.id
return JsonResponse(res.asDict())
示例6: delete
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def delete(request, obj_id=None):
"""Removes tags from objects resolved from guids
:param tags: Tags to remove
:type tags: list
:param guids: Guids to remove tags from
:type guids: list
:returns: json
"""
res = Result()
if obj_id:
# -- Delete the tag itself
tag = Tag.objects.get(pk=obj_id)
guids = []
images = Image.objects.filter(tags__id=obj_id)
guids += [_.guid for _ in images]
videos = Video.objects.filter(tags__id=obj_id)
guids += [_.guid for _ in videos]
# -- Remove all tags from objects
_manageTags([tag.id], guids, add=False)
# -- Delete old tags
tag.delete()
else:
tags = [_ for _ in request.DELETE.get('tags', '').split(',') if _]
guids = [_ for _ in request.DELETE.get('guids', '').split(',') if _]
_manageTags(tags, guids, add=False)
return JsonResponse(res.asDict())
示例7: csrf
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def csrf(request):
res = Result()
try:
res.append(request.COOKIES['csrftoken'])
except KeyError:
pass
return JsonResponse(res.asDict())
示例8: post
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def post(request):
"""Sets a key to a value on the currently logged in users preferences
:param key: Key to set
:type key: str
:param val: Value to set
:type val: primitive
:returns: json
"""
data = request.POST or json.loads(request.body)['body']
key = data.get('key', None)
val = data.get('val', None)
res = Result()
if key is not None and val is not None:
obj, created = UserPref.objects.get_or_create(user=request.user)
if created:
obj.data = json.dumps(DefaultPrefs.copy())
obj.save()
try:
val = json.loads(val)
except (TypeError, ValueError):
pass
obj.setKey(key, val)
obj.save()
res.append(obj.json())
return JsonResponse(res.asDict())
示例9: get
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def get(request, obj_id=None):
if obj_id:
obj = Gallery.objects.get(pk=obj_id)
if obj.security != Gallery.PUBLIC and request.user.is_anonymous():
raise PermissionDenied
else:
res = Result()
flat = bool(request.GET.get('flat'))
if request.user.is_authenticated():
objects = Gallery.objects.filter(Q(security__lte=Gallery.PRIVATE) | Q(owner=request.user))
else:
objects = Gallery.objects.filter(security=Gallery.PUBLIC)
objects = objects.filter(parent__isnull=True)
for obj in objects:
if flat:
res.append({'title': obj.title, 'id': obj.id});
for child in obj.gallery_set.all().order_by('title'):
res.append({'title': '-- %s' % child.title, 'id': child.id});
else:
res.append(obj.json())
return JsonResponse(res.asDict())
示例10: put
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def put(request, obj_id=None):
""" Adds Image and Video objects to Gallery based on GUIDs """
data = request.PUT or json.loads(request.body)['body']
guids = data.get('guids', '').split(',')
move = data.get('from')
security = request.PUT.get('security')
gallery = Gallery.objects.get(pk=obj_id)
if guids:
objects = getObjectsFromGuids(guids)
images = filter(lambda x: isinstance(x, Image), objects)
videos = filter(lambda x: isinstance(x, Video), objects)
gallery.images.add(*images)
gallery.videos.add(*videos)
if move:
fromgallery = Gallery.objects.get(pk=move)
fromgallery.images.remove(*images)
fromgallery.videos.remove(*videos)
if security is not None:
gallery.security = json.loads(security)
gallery.save()
for child in gallery.gallery_set.all():
child.security = gallery.security
child.save()
res = Result()
res.append(gallery.json())
return JsonResponse(res.asDict())
示例11: releaseNotes
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def releaseNotes(request):
res = Result()
lastid = request.GET.get('lastid', 0)
today = datetime.datetime.today()
relevent = today - datetime.timedelta(days=30)
notes = ReleaseNotes.objects.filter(date__gte=relevent, pk__gt=lastid).order_by('-id')
for note in notes:
res.append(note.json())
return JsonResponse(res.asDict())
示例12: login_
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def login_(request):
data = request.POST or json.loads(request.body)['body']
email = data['email'].lower()
password = data.get('password')
result = Result()
user = None
if email:
user = authenticate(username=email, password=password)
else:
result.message = 'Please enter an email address'
result.isError = True
if user:
first_name = request.POST.get('first_name')
last_name = request.POST.get('last_name')
if first_name:
user.first_name = first_name
if last_name:
user.last_name = last_name
if not user.is_active:
result.message = 'User account not active'
result.isError = True
else:
result.message = 'Invalid Credentials'
result.isError = True
if result.isError:
return JsonResponse(result.asDict())
login(request, user)
# -- Create an artist tag for them
Tag.objects.get_or_create(
name=user.get_full_name(),
defaults={'artist': True}
)
return JsonResponse(result.asDict())
示例13: get
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import asDict [as 别名]
def get(request):
"""Gets the currently logged in users preferences
:returns: json
"""
res = Result()
obj, created = UserPref.objects.get_or_create(user=request.user, defaults={'data': json.dumps(DefaultPrefs.copy())})
data = obj.json()
data['subscriptions'] = [_.json() for _ in GallerySubscription.objects.filter(user=request.user)]
res.append(data)
return JsonResponse(res.asDict())