4 ol-4"> 520
+def comment_submit_api(request):
521
+    group_id = request.POST.get('group_id', '')
522
+    user_id = request.POST.get('user_id', '')
523
+    photo_id = request.POST.get('photo_id', '')
524
+    comment = request.POST.get('comment', '')
525
+
526
+    current_id = int(request.POST.get('current_id', -1))
527
+
528
+    try:
529
+        group = GroupInfo.objects.get(group_id=group_id)
530
+    except GroupInfo.DoesNotExist:
531
+        return JsonResponse({
532
+            'status': 4020,
533
+            'message': u'群组不存在',
534
+        })
535
+
536
+    try:
537
+        group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
538
+    except GroupUserInfo.DoesNotExist:
539
+        return JsonResponse({
540
+            'status': 4029,
541
+            'message': u'该用户不在群组',
542
+        })
543
+
544
+    try:
545
+        group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
546
+    except GroupPhotoInfo.DoesNotExist:
547
+        return JsonResponse({
548
+            'status': 4030,
549
+            'message': u'飞图不存在',
550
+        })
551
+
552
+    if comment:
553
+        PhotoCommentInfo.objects.create(
554
+            photo_id=photo_id,
555
+            user_id=user_id,
556
+            nickname=group_user.nickname,
557
+            avatar=group_user.avatar,
558
+            comment=comment,
559
+        )
560
+
561
+    photo_comments = PhotoCommentInfo.objects.filter(
562
+        photo_id=photo_id,
563
+        pk__gt=current_id
564
+    )
565
+    latest_comment = photo_comments.last()
566
+
567
+    return JsonResponse({
568
+        'status': 200,
569
+        'message': u'评论成功',
570
+        'data': {
571
+            'current_id': latest_comment and latest_comment.pk or current_id,
572
+            'comments': [comment.comment_info for comment in photo_comments],
573
+        }
574
+    })
575
+
576
+
577
+def thumbup_submit_api(request):
578
+    group_id = request.POST.get('group_id', '')
579
+    user_id = request.POST.get('user_id', '')
580
+    photo_id = request.POST.get('photo_id', '')
581
+
582
+    try:
583
+        group = GroupInfo.objects.get(group_id=group_id)
584
+    except GroupInfo.DoesNotExist:
585
+        return JsonResponse({
586
+            'status': 4020,
587
+            'message': u'群组不存在',
588
+        })
589
+
590
+    try:
591
+        group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
592
+    except GroupUserInfo.DoesNotExist:
593
+        return JsonResponse({
594
+            'status': 4029,
595
+            'message': u'该用户不在群组',
596
+        })
597
+
598
+    try:
599
+        group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
600
+    except GroupPhotoInfo.DoesNotExist:
601
+        return JsonResponse({
602
+            'status': 4030,
603
+            'message': u'飞图不存在',
604
+        })
605
+
606
+    photo_thumbup, created = PhotoThumbUpInfo.objects.get_or_create(
607
+        photo_id=photo_id,
608
+        user_id=user_id,
609
+        # defaults={
610
+        #     'nickname': group_user.nickname,
611
+        #     'avatar': group_user.avatar,
612
+        # }
613
+    )
614
+    photo_thumbup.nickname = group_user.nickname
615
+    photo_thumbup.avatar = group_user.avatar
616
+    photo_thumbup.thumbup = True
617
+    photo_thumbup.save()
618
+
619
+    photo_thumbups = PhotoThumbUpInfo.objects.filter(
620
+        photo_id=photo_id,
621
+        thumbup=True,
622
+    )
623
+
624
+    return JsonResponse({
625
+        'status': 200,
626
+        'message': u'点赞提交成功',
627
+        'data': {
628
+            'thumbup': True,
629
+            'thumbups': [thumbup.thumbup_info for thumbup in photo_thumbups],
630
+        }
631
+    })
632
+
633
+
634
+def thumbup_list_api(request):
635
+    group_id = request.POST.get('group_id', '')
636
+    user_id = request.POST.get('user_id', '')
637
+    photo_id = request.POST.get('photo_id', '')
638
+
639
+    try:
640
+        group = GroupInfo.objects.get(group_id=group_id)
641
+    except GroupInfo.DoesNotExist:
642
+        return JsonResponse({
643
+            'status': 4020,
644
+            'message': u'群组不存在',
645
+        })
646
+
647
+    try:
648
+        group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
649
+    except GroupUserInfo.DoesNotExist:
650
+        return JsonResponse({
651
+            'status': 4029,
652
+            'message': u'该用户不在群组',
653
+        })
654
+
655
+    try:
656
+        group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
657
+    except GroupPhotoInfo.DoesNotExist:
658
+        return JsonResponse({
659
+            'status': 4030,
660
+            'message': u'飞图不存在',
661
+        })
662
+
663
+    try:
664
+        thumbup = PhotoThumbUpInfo.objects.get(
665
+            photo_id=photo_id,
666
+            user_id=user_id,
667
+        ).thumbup
668
+    except PhotoThumbUpInfo.DoesNotExist:
669
+        thumbup = False
670
+
671
+    photo_thumbups = PhotoThumbUpInfo.objects.filter(
672
+        photo_id=photo_id,
673
+        thumbup=True,
674
+    )
675
+
676
+    return JsonResponse({
677
+        'status': 200,
678
+        'message': u'获取点赞列表成功',
679
+        'data': {
680
+            'thumbup': thumbup,
681
+            'thumbups': [thumbup.thumbup_info for thumbup in photo_thumbups],
682
+        }
683
+    })
684
+
685
+
686
+def thumbup_cancel_api(request):
687
+    group_id = request.POST.get('group_id', '')
688
+    user_id = request.POST.get('user_id', '')
689
+    photo_id = request.POST.get('photo_id', '')
690
+
691
+    try:
692
+        group = GroupInfo.objects.get(group_id=group_id)
693
+    except GroupInfo.DoesNotExist:
694
+        return JsonResponse({
695
+            'status': 4020,
696
+            'message': u'群组不存在',
697
+        })
698
+
699
+    try:
700
+        group_user = GroupUserInfo.objects.get(group_id=group_id, user_id=user_id, user_status=GroupUserInfo.PASSED)
701
+    except GroupUserInfo.DoesNotExist:
702
+        return JsonResponse({
703
+            'status': 4029,
704
+            'message': u'该用户不在群组',
705
+        })
706
+
707
+    try:
708
+        group_photo = GroupPhotoInfo.objects.get(pk=photo_id)
709
+    except GroupPhotoInfo.DoesNotExist:
710
+        return JsonResponse({
711
+            'status': 4030,
712
+            'message': u'飞图不存在',
713
+        })
714
+
715
+    photo_thumbup, created = PhotoThumbUpInfo.objects.get_or_create(
716
+        photo_id=photo_id,
717
+        user_id=user_id,
718
+    )
719
+    photo_thumbup.thumbup = False
720
+    photo_thumbup.save()
721
+
722
+    photo_thumbups = PhotoThumbUpInfo.objects.filter(
723
+        photo_id=photo_id,
724
+        thumbup=True,
725
+    )
726
+
727
+    return JsonResponse({
728
+        'status': 200,
729
+        'message': u'点赞取消成功',
730
+        'data': {
731
+            'thumbup': False,
732
+            'thumbups': [thumbup.thumbup_info for thumbup in photo_thumbups],
733
+        }
734
+    })
735
+
736
+
520 737
 class GroupInfoViewSet(viewsets.ModelViewSet):
521 738
     queryset = GroupInfo.objects.all().order_by('-created_at')
522 739
     serializer_class = GroupInfoSerializer

+ 0 - 4
operation/views.py

@@ -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
 

adminSystem - Gogs: Go Git Service

Nessuna descrizione

license 1.1KB

    The MIT License (MIT) Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.