本文整理汇总了Python中frog.common.Result.append方法的典型用法代码示例。如果您正苦于以下问题:Python Result.append方法的具体用法?Python Result.append怎么用?Python Result.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frog.common.Result
的用法示例。
在下文中一共展示了Result.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [as 别名]
def post(request):
""" Create a Gallery """
defaultname = 'New Gallery %i' % Gallery.objects.all().count()
title = request.POST.get('title', defaultname)
description = request.POST.get('description', '')
security = int(request.POST.get('security', Gallery.PUBLIC))
parentid = request.POST.get('parent')
if parentid:
parent = Gallery.objects.get(pk=int(parentid))
g, created = parent.gallery_set.get_or_create(title=title)
g.security = parent.security
else:
g, created = Gallery.objects.get_or_create(title=title)
g.security = security
g.description = description
g.owner = request.user
g.save()
res = Result()
res.isSuccess = True
res.append(g.json())
res.message = 'Gallery created' if created else ''
return JsonResponse(res)
示例2: post
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [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())
示例3: put
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [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())
示例4: put
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [as 别名]
def put(request, obj_id=None):
""" Adds Image and Video objects to Gallery based on GUIDs """
guids = filter(None, request.PUT.get('guids', '').split(','))
security = request.PUT.get('security')
object_ = 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)
object_.images.add(*images)
object_.videos.add(*videos)
if security is not None:
object_.security = json.loads(security)
object_.save()
for child in object_.gallery_set.all():
child.security = object_.security
child.save()
res = Result()
res.append(object_.json())
res.isSuccess = True
return JsonResponse(res)
示例5: csrf
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [as 别名]
def csrf(request):
res = Result()
try:
res.append(request.COOKIES['csrftoken'])
except KeyError:
pass
return JsonResponse(res.asDict())
示例6: getUser
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [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())
示例7: userList
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [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())
示例8: post
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [as 别名]
def post(request):
"""Returns a serialized object
:param obj_id: ID of comment object
:type obj_id: int
:returns: json
"""
guid = request.POST.get('guid', None)
res = Result()
if guid:
obj = getObjectsFromGuids([guid,])[0]
c = Comment()
c.comment = request.POST.get('comment', 'No comment')
c.user = request.user
c.user_name = request.user.get_full_name()
c.user_email = request.user.email
c.content_object = obj
c.site_id = 1
c.save()
obj.comment_count = obj.comment_count + 1
obj.save()
__email(c, obj)
res.append({'id': c.id, 'comment': c.comment})
res.isSuccess = True
else:
res.isError = True
res.message = "No guid provided"
return JsonResponse(res)
示例9: switchArtist
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [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())
示例10: post
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [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
"""
key = request.POST.get('key', None)
val = request.POST.get('val', None)
res = Result()
if key and val:
obj, created = UserPref.objects.get_or_create(user=request.user)
if created:
obj.data = json.dumps(DefaultPrefs.copy())
obj.save()
val = json.loads(val)
obj.setKey(key, val)
obj.save()
res.append(obj.json())
res.isSuccess = True
else:
res.isError = True
res.message = 'No key and value provided'
return JsonResponse(res)
示例11: post
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [as 别名]
def post(request):
"""Creates a tag object
:param name: Name for tag
:type name: str
:returns: json
"""
res = Result()
name = request.POST.get("name", None)
if not name:
res.isError = True
res.message = "No name given"
return JsonResponse(res)
tag, created = Tag.objects.get_or_create(name=name)
res.isSuccess = True
if created:
res.message = "Created"
res.append(tag.json())
return JsonResponse(res)
示例12: releaseNotes
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [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())
示例13: artistLookup
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [as 别名]
def artistLookup(request):
res = Result()
query = request.GET.get('query', False)
if query:
users = User.objects.filter(first_name__icontains=query.lower())
else:
users = User.objects.all()
for user in users:
res.append(userToJson(user))
return JsonResponse(res.values)
示例14: get
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [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())
示例15: get
# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import append [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)
if created:
obj.data = json.dumps(DefaultPrefs.copy())
obj.save()
res.append(obj.json())
res.isSuccess = True
return JsonResponse(res)