})
53 50
 
54 51
 
52
+@logit
55 53
 def message_type_list_api(request, msg_type):
56 54
     """
57 55
     分类消息列表
@@ -82,16 +80,13 @@ def message_type_list_api(request, msg_type):
82 80
     type_messages, left = pagination(type_messages, page, num)
83 81
     type_messages = [msg.msg_info(user_id) for msg in type_messages]
84 82
 
85
-    return JsonResponse({
86
-        'status': 200,
87
-        'message': u'获取消息列表成功',
88
-        'data': {
89
-            'messages': type_messages,
90
-            'left': left,
91
-        },
83
+    return response(200, 'Get Message List Success', u'获取消息列表成功', {
84
+        'messages': type_messages,
85
+        'left': left,
92 86
     })
93 87
 
94 88
 
89
+@logit
95 90
 def message_type_read_api(request, msg_type=None):
96 91
     """
97 92
     消息读取
@@ -124,12 +119,10 @@ def message_type_read_api(request, msg_type=None):
124 119
         if _all == 'true':  # 用户消息(点赞/评论)全部读取
125 120
             UserMessageInfo.objects.filter(to_uid=user_id, msg_type=msg_type).update(read=True)
126 121
 
127
-    return JsonResponse({
128
-        'status': 200,
129
-        'message': u'已读消息成功',
130
-    })
122
+    return response(200, 'Read Message Success', u'已读消息成功')
131 123
 
132 124
 
125
+@logit
133 126
 def message_type_delete_api(request, msg_type=None):
134 127
     """
135 128
     消息删除
@@ -163,7 +156,4 @@ def message_type_delete_api(request, msg_type=None):
163 156
         if _all == 'true':  # 用户消息(点赞/评论)全部删除
164 157
             UserMessageInfo.objects.filter(to_uid=user_id, msg_type=msg_type).update(status=False)
165 158
 
166
-    return JsonResponse({
167
-        'status': 200,
168
-        'message': u'消息删除成功',
169
-    })
159
+    return response(200, 'Delete Message Success', u'消息删除成功')

+ 9 - 19
operation/views.py

@@ -1,8 +1,8 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3 3
 from django.conf import settings
4
-from django.http import JsonResponse
5 4
 from django.shortcuts import redirect
5
+from logit import logit
6 6
 
7 7
 from account.models import UserInfo
8 8
 from operation.models import FeedbackInfo, SplashInfo
@@ -11,6 +11,7 @@ from utils.error.response_utils import response
11 11
 from utils.redis.rapp import get_latest_app
12 12
 
13 13
 
14
+@logit
14 15
 def upgrade_api(request):
15 16
     """
16 17
     APP 升级
@@ -32,15 +33,12 @@ def upgrade_api(request):
32 33
             'latest_url': latest_app.get('latest_adr_url', ''),
33 34
         }
34 35
 
35
-    return JsonResponse({
36
-        'status': 200,
37
-        'message': u'获取最新版信息成功',
38
-        'data': {
39
-            'appinfo': appinfo,
40
-        },
36
+    return response(200, 'Get Latest App Success', u'获取最新版信息成功', {
37
+        'appinfo': appinfo,
41 38
     })
42 39
 
43 40
 
41
+@logit
44 42
 def splash_api(request):
45 43
     """
46 44
     启动页面
@@ -50,15 +48,12 @@ def splash_api(request):
50 48
     splashes = SplashInfo.objects.all()
51 49
     splashes = [splash.data for splash in splashes]
52 50
 
53
-    return JsonResponse({
54
-        'status': 200,
55
-        'message': u'获取最新版信息成功',
56
-        'data': {
57
-            'splashes': splashes,
58
-        },
51
+    return response(200, 'Get Splash Success', u'获取最新版信息成功', {
52
+        'splashes': splashes,
59 53
     })
60 54
 
61 55
 
56
+@logit
62 57
 def feedback_api(request):
63 58
     """
64 59
     用户反馈
@@ -76,12 +71,7 @@ def feedback_api(request):
76 71
         feedback=feedback
77 72
     )
78 73
 
79
-    return JsonResponse({
80
-        'status': 200,
81
-        'message': u'反馈成功',
82
-        'data': {
83
-        },
84
-    })
74
+    return response(200, 'Feedback Success', u'反馈成功')
85 75
 
86 76
 
87 77
 def download_api(request):

+ 10 - 40
pay/views.py

@@ -3,7 +3,6 @@
3 3
 import xmltodict
4 4
 from django.conf import settings
5 5
 from django.db import transaction
6
-from django.http import JsonResponse
7 6
 from django.shortcuts import HttpResponse
8 7
 from logit import logit
9 8
 from TimeConvert import TimeConvert as tc
@@ -94,15 +93,10 @@ def wx_order_create_api(request):
94 93
     elif trade_type == 'APP':
95 94
         wxpay_params = wxpay.order.get_appapi_params(prepay_id)
96 95
 
97
-    return JsonResponse({
98
-        'status': 200,
99
-        'message': 'Order Create Success',
100
-        'description': u'订单创建成功',
101
-        'data': {
102
-            'order_id': order.order_id,
103
-            'prepay_id': prepay_id,
104
-            'wxpay_params': wxpay_params,
105
-        }
96
+    return response(200, 'Order Create Success', u'订单创建成功', {
97
+        'order_id': order.order_id,
98
+        'prepay_id': prepay_id,
99
+        'wxpay_params': wxpay_params,
106 100
     })
107 101
 
108 102
 
@@ -191,14 +185,7 @@ def wx_order_query_api(request):
191 185
         return response(OrderStatusCode.WX_ORDER_NOT_FOUND)
192 186
 
193 187
     if order.pay_status == OrderInfo.PAID:
194
-        return JsonResponse({
195
-            'status': 200,
196
-            'message': 'Order Pay Success',
197
-            'description': u'订单支付成功',
198
-            'data': {
199
-
200
-            }
201
-        })
188
+        return response(200, 'Order Pay Success', u'订单支付成功')
202 189
     elif order.pay_status == OrderInfo.FAIL:
203 190
         return response(OrderStatusCode.WX_ORDER_PAY_FAIL)
204 191
 
@@ -218,14 +205,7 @@ def wx_order_query_api(request):
218 205
     # 订单状态判断更新
219 206
     if trade_state == 'SUCCESS':  # 订单支付成功
220 207
         order_paid_success(order)
221
-        return JsonResponse({
222
-            'status': 200,
223
-            'message': 'Order Pay Success',
224
-            'description': u'订单支付成功',
225
-            'data': {
226
-
227
-            }
228
-        })
208
+        return response(200, 'Order Pay Success', u'订单支付成功')
229 209
     elif trade_state == 'NOTPAY':  # 订单未支付
230 210
         return response(OrderStatusCode.WX_ORDER_NOT_PAY)
231 211
     elif trade_state == 'USERPAYING':  # 订单支付中
@@ -251,13 +231,9 @@ def wx_order_list_api(request):
251 231
     orders, left = pagination(orders, page, num)
252 232
     orders = [order.data(user_id) for order in orders]
253 233
 
254
-    return JsonResponse({
255
-        'status': 200,
256
-        'message': u'获取订单列表成功',
257
-        'data': {
258
-            'orders': orders,
259
-            'left': left,
260
-        },
234
+    return response(200, 'Get Order List Success', u'获取订单列表成功', {
235
+        'orders': orders,
236
+        'left': left,
261 237
     })
262 238
 
263 239
 
@@ -280,13 +256,7 @@ def wx_order_detail_api(request):
280 256
     if user_id not in [order.from_uid, order.to_lid, order.to_uid]:
281 257
         return response(OrderStatusCode.NO_DETAIL_PERMISSION)
282 258
 
283
-    return JsonResponse({
284
-        'status': 200,
285
-        'message': u'获取订单详情成功',
286
-        'data': {
287
-            'order': order.data(user_id),
288
-        },
289
-    })
259
+    return response(200, 'Get Order Detail Success', u'获取订单详情成功')
290 260
 
291 261
 
292 262
 @logit

+ 25 - 38
photo/views.py

@@ -7,8 +7,8 @@ from curtail_uuid import CurtailUUID
7 7
 from django.conf import settings
8 8
 from django.core.files.storage import default_storage
9 9
 from django.db import transaction
10
-from django.http import JsonResponse
11 10
 from django.shortcuts import render
11
+from logit import logit
12 12
 from rest_framework import viewsets
13 13
 from TimeConvert import TimeConvert as tc
14 14
 
@@ -16,7 +16,7 @@ from account.models import LensmanInfo, UserInfo
16 16
 from group.models import GroupInfo, GroupPhotoInfo, GroupUserInfo
17 17
 from photo.models import PhotosInfo, UUIDInfo
18 18
 from photo.serializers import PhotosInfoSerializer
19
-from utils.error.errno_utils import PhotoStatusCode
19
+from utils.error.errno_utils import LensmanStatusCode, PhotoStatusCode
20 20
 from utils.error.response_utils import response
21 21
 from utils.ip_utils import ip_addr
22 22
 from utils.redis.rgroup import get_group_info, get_group_users_info, set_group_info, set_group_users_info
@@ -28,6 +28,7 @@ from utils.watermark_utils import watermark_wrap
28 28
 r = settings.REDIS_CACHE
29 29
 
30 30
 
31
+@logit
31 32
 def uuid_init(request):
32 33
     """
33 34
     生成唯一标识
@@ -39,14 +40,11 @@ def uuid_init(request):
39 40
     for i in xrange(num):
40 41
         UUIDInfo.objects.create(uuid=CurtailUUID.uuid(UUIDInfo))
41 42
 
42
-    return JsonResponse({
43
-        'status': 200,
44
-        'message': u'UUID 更新成功',
45
-        'data': '',
46
-    })
43
+    return response(200, 'UUID Refresh Success', u'UUID 更新成功')
47 44
 
48 45
 
49 46
 # curl -X POST -F user_id=xxxxxxx -F num=100 http://api.pai.ai/uuid
47
+@logit
50 48
 @transaction.atomic
51 49
 def uuid(request):
52 50
     """
@@ -63,11 +61,7 @@ def uuid(request):
63 61
         uuid.status = False
64 62
         uuid.save()
65 63
 
66
-    return JsonResponse({
67
-        'status': 200,
68
-        'message': u'获取唯一标识成功',
69
-        'data': [uuid.uuid for uuid in uuids],
70
-    })
64
+    return response(200, 'Get UUID Success', u'获取唯一标识成功', [uuid.uuid for uuid in uuids])
71 65
 
72 66
 
73 67
 # [How to do a PUT request with curl?](http://stackoverflow.com/questions/13782198/how-to-do-a-put-request-with-curl)
@@ -82,6 +76,7 @@ def uuid(request):
82 76
 #               while the < makes a text field and just get the contents for that text field from a file.
83 77
 #
84 78
 # curl -X POST -F user_id=xxxxxxx -F session_id=xxxxxxx -F photo_id=xxxxxxx -F photo=@xxxxxxx.jpg http://api.pai.ai/photos/upload
79
+@logit
85 80
 def upload_photo(request):
86 81
     """
87 82
     上传图片
@@ -100,10 +95,7 @@ def upload_photo(request):
100 95
     try:
101 96
         LensmanInfo.objects.get(lensman_id=lensman_id)
102 97
     except LensmanInfo.DoesNotExist:
103
-        return JsonResponse({
104
-            'status': 4000,
105
-            'message': u'摄影师不存在',
106
-        })
98
+        return response(LensmanStatusCode.LENSMAN_NOT_FOUND)
107 99
 
108 100
     # photo_id = curtailUUID(PhotosInfo, 'photo_id')
109 101
 
@@ -131,13 +123,10 @@ def upload_photo(request):
131 123
         m_photo_path=m_photo_path,
132 124
     )
133 125
 
134
-    return JsonResponse({
135
-        'status': 200,
136
-        'message': u'照片上传成功',
137
-        'data': photo.data,
138
-    })
126
+    return response(200, 'Photo Upload Success', u'照片上传成功', photo.data)
139 127
 
140 128
 
129
+@logit
141 130
 def session_join_api(request):
142 131
     """
143 132
     Session 详情
@@ -247,51 +236,49 @@ def session_join_api(request):
247 236
     )
248 237
     latest_photo = group_photos.first()
249 238
 
250
-    return JsonResponse({
251
-        'status': 200,
252
-        'message': u'申请成功',
253
-        'data': {
254
-            'current_id': latest_photo and latest_photo.pk or current_id,
255
-            'photos': [photo.photo_info(user_id) for photo in group_photos],
256
-            'group_id': group_id,
257
-            'group': group_info,
258
-            'user_id': user_id,
259
-            'users': group_users,
260
-        }
239
+    return response(200, 'Apply Success', u'申请成功', {
240
+        'current_id': latest_photo and latest_photo.pk or current_id,
241
+        'photos': [photo.photo_info(user_id) for photo in group_photos],
242
+        'group_id': group_id,
243
+        'group': group_info,
244
+        'user_id': user_id,
245
+        'users': group_users,
261 246
     })
262 247
 
263 248
 
249
+@logit
264 250
 def session_detail(request, session_id):
265 251
     photos = PhotosInfo.objects.filter(session_id=session_id)
266 252
     return render(request, 'photo/session_detail.html', {'photos': photos})
267 253
 
268 254
 
255
+@logit
269 256
 def photo_standard(request, photo_id):
270 257
     photo = PhotosInfo.objects.get(photo_id=photo_id)
271 258
     return render(request, 'photo/photo_detail.html', {'photo_url': photo.p_photo_url})
272 259
 
273 260
 
261
+@logit
274 262
 def photo_standard_api(request, photo_id):
275 263
     photo = PhotosInfo.objects.get(photo_id=photo_id)
276
-    return JsonResponse({
277
-        'status': 200,
278
-        'message': u'获取照片详情成功',
279
-        'data': {
280
-            'photo': photo.detail,
281
-        }
264
+    return response(200, 'Get Photo Detail Success', u'获取照片详情成功', {
265
+        'photo': photo.detail,
282 266
     })
283 267
 
284 268
 
269
+@logit
285 270
 def photo_medium(request, photo_id):
286 271
     photo = PhotosInfo.objects.get(photo_id=photo_id)
287 272
     return render(request, 'photo/photo_detail.html', {'photo_url': photo.m_photo_url})
288 273
 
289 274
 
275
+@logit
290 276
 def photo_large(request, photo_id):
291 277
     photo = PhotosInfo.objects.get(photo_id=photo_id)
292 278
     return render(request, 'photo/photo_detail.html', {'photo_url': photo.l_photo_url})
293 279
 
294 280
 
281
+@logit
295 282
 def photo_raw(request, photo_id):
296 283
     photo = PhotosInfo.objects.get(photo_id=photo_id)
297 284
     return render(request, 'photo/photo_detail.html', {'photo_url': photo.r_photo_url})

pai2 - Gogs: Go Git Service

拍爱

rapp.py 613B

    # -*- coding: utf-8 -*- import json from django.conf import settings from operation.models import LatestAppInfo from utils.redis.rkeys import LATEST_APP_INFO r = settings.REDIS_CACHE # 最新 APP 相关 def set_latest_app(src=0): """ 设置最新 APP 信息 """ try: appinfo = LatestAppInfo.objects.filter(src=src)[0].data except IndexError: appinfo = {} r.set(LATEST_APP_INFO % src, json.dumps(appinfo)) return appinfo def get_latest_app(src=0): """ 获取最新 APP 信息 """ return json.loads(r.get(LATEST_APP_INFO % src) or '{}') or set_latest_app(src)