s-num lines-num-new"> 520
+def comment_submit_api(request):
+ group_id = request.POST.get('group_id', '')
+ user_id = request.POST.get('user_id', '')
+ photo_id = request.POST.get('photo_id', '')
+ comment = request.POST.get('comment', '')
+
+ current_id = int(request.POST.get('current_id', -1))
+
+ try:
+ group = GroupInfo.objects.get(group_id=group_id)
+ except GroupInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4020,
+ 'message': u'群组不存在',
+ })
+
+ try:
+ group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
+ except GroupUserInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4029,
+ 'message': u'该用户不在群组',
+ })
+
+ try:
+ group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
+ except GroupPhotoInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4030,
+ 'message': u'飞图不存在',
+ })
+
+ if comment:
+ PhotoCommentInfo.objects.create(
+ photo_id=photo_id,
+ user_id=user_id,
+ nickname=group_user.nickname,
+ avatar=group_user.avatar,
+ comment=comment,
+ )
+
+ photo_comments = PhotoCommentInfo.objects.filter(
+ photo_id=photo_id,
+ pk__gt=current_id
+ )
+ latest_comment = photo_comments.last()
+
+ return JsonResponse({
+ 'status': 200,
+ 'message': u'评论成功',
+ 'data': {
+ 'current_id': latest_comment and latest_comment.pk or current_id,
+ 'comments': [comment.comment_info for comment in photo_comments],
+ }
+ })
+
+
+def thumbup_submit_api(request):
+ group_id = request.POST.get('group_id', '')
+ user_id = request.POST.get('user_id', '')
+ photo_id = request.POST.get('photo_id', '')
+
+ try:
+ group = GroupInfo.objects.get(group_id=group_id)
+ except GroupInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4020,
+ 'message': u'群组不存在',
+ })
+
+ try:
+ group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
+ except GroupUserInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4029,
+ 'message': u'该用户不在群组',
+ })
+
+ try:
+ group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
+ except GroupPhotoInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4030,
+ 'message': u'飞图不存在',
+ })
+
+ photo_thumbup, created = PhotoThumbUpInfo.objects.get_or_create(
+ photo_id=photo_id,
+ user_id=user_id,
+ # defaults={
+ # 'nickname': group_user.nickname,
+ # 'avatar': group_user.avatar,
+ # }
+ )
+ photo_thumbup.nickname = group_user.nickname
+ photo_thumbup.avatar = group_user.avatar
+ photo_thumbup.thumbup = True
+ photo_thumbup.save()
+
+ photo_thumbups = PhotoThumbUpInfo.objects.filter(
+ photo_id=photo_id,
+ thumbup=True,
+ )
+
+ return JsonResponse({
+ 'status': 200,
+ 'message': u'点赞提交成功',
+ 'data': {
+ 'thumbup': True,
+ 'thumbups': [thumbup.thumbup_info for thumbup in photo_thumbups],
+ }
+ })
+
+
+def thumbup_list_api(request):
+ group_id = request.POST.get('group_id', '')
+ user_id = request.POST.get('user_id', '')
+ photo_id = request.POST.get('photo_id', '')
+
+ try:
+ group = GroupInfo.objects.get(group_id=group_id)
+ except GroupInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4020,
+ 'message': u'群组不存在',
+ })
+
+ try:
+ group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
+ except GroupUserInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4029,
+ 'message': u'该用户不在群组',
+ })
+
+ try:
+ group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
+ except GroupPhotoInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4030,
+ 'message': u'飞图不存在',
+ })
+
+ try:
+ thumbup = PhotoThumbUpInfo.objects.get(
+ photo_id=photo_id,
+ user_id=user_id,
+ ).thumbup
+ except PhotoThumbUpInfo.DoesNotExist:
+ thumbup = False
+
+ photo_thumbups = PhotoThumbUpInfo.objects.filter(
+ photo_id=photo_id,
+ thumbup=True,
+ )
+
+ return JsonResponse({
+ 'status': 200,
+ 'message': u'获取点赞列表成功',
+ 'data': {
+ 'thumbup': thumbup,
+ 'thumbups': [thumbup.thumbup_info for thumbup in photo_thumbups],
+ }
+ })
+
+
+def thumbup_cancel_api(request):
+ group_id = request.POST.get('group_id', '')
+ user_id = request.POST.get('user_id', '')
+ photo_id = request.POST.get('photo_id', '')
+
+ try:
+ group = GroupInfo.objects.get(group_id=group_id)
+ except GroupInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4020,
+ 'message': u'群组不存在',
+ })
+
+ try:
+ group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
+ except GroupUserInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4029,
+ 'message': u'该用户不在群组',
+ })
+
+ try:
+ group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
+ except GroupPhotoInfo.DoesNotExist:
+ return JsonResponse({
+ 'status': 4030,
+ 'message': u'飞图不存在',
+ })
+
+ photo_thumbup, created = PhotoThumbUpInfo.objects.get_or_create(
+ photo_id=photo_id,
+ user_id=user_id,
+ )
+ photo_thumbup.thumbup = False
+ photo_thumbup.save()
+
+ photo_thumbups = PhotoThumbUpInfo.objects.filter(
+ photo_id=photo_id,
+ thumbup=True,
+ )
+
+ return JsonResponse({
+ 'status': 200,
+ 'message': u'点赞取消成功',
+ 'data': {
+ 'thumbup': False,
+ 'thumbups': [thumbup.thumbup_info for thumbup in photo_thumbups],
+ }
+ })
+
+
class GroupInfoViewSet(viewsets.ModelViewSet):
queryset = GroupInfo.objects.all().order_by('-created_at')
serializer_class = GroupInfoSerializer
@@ -1,10 +1,6 @@ |
||
| 1 | 1 |
# -*- coding: utf-8 -*- |
| 2 | 2 |
|
| 3 |
-from django.conf import settings |
|
| 4 |
-from django.core.files.storage import default_storage |
|
| 5 |
-from django.db import transaction |
|
| 6 | 3 |
from django.http import JsonResponse |
| 7 |
-from django.shortcuts import render, redirect |
|
| 8 | 4 |
|
| 9 | 5 |
from operation.models import LatestAppInfo, SplashInfo |
| 10 | 6 |
|