f-584f03f4131c5dfe019da9d46a8e94181b3b5821R40">40
+
10 41
 class UserViewSet(viewsets.ModelViewSet):
11 42
     """
12 43
     API endpoint that allows users to be viewed or edited.

+ 5 - 0
api/urls.py

@@ -2,10 +2,15 @@
2 2
 
3 3
 from django.conf.urls import url
4 4
 
5
+from account import views as account_views
5 6
 from photo import views as photo_views
6 7
 
7 8
 
8 9
 urlpatterns = [
10
+    url(r'^login$', account_views.user_login, name='user_login'),
11
+]
12
+
13
+urlpatterns += [
9 14
     url(r'^uuid_init$', photo_views.uuid_init, name='uuid_init'),
10 15
     url(r'^uuid$', photo_views.uuid, name='uuid'),
11 16
     url(r'^photos/upload$', photo_views.upload_photo, name='upload_photo'),

+ 8 - 4
docs/errorcode

@@ -1,4 +1,8 @@
1
-1、照片上传 —— 401
2
-     4010 —— 参数错误
3
-     4011 —— 摄影师不存在
4
-     4012 —— 照片已存在
1
+1、用户信息 —— 400
2
+    4000 —— 用户不存在
3
+    4001 —— 用户密码错误
4
+
5
+2、照片上传 —— 401
6
+    4010 —— 参数错误
7
+    4011 —— 摄影师不存在
8
+    4012 —— 照片已存在

+ 12 - 0
pai2/settings.py

@@ -46,6 +46,8 @@ INSTALLED_APPS = (
46 46
     'photo',
47 47
 )
48 48
 
49
+INSTALLED_APPS += ('multidomain', )
50
+
49 51
 MIDDLEWARE_CLASSES = (
50 52
     'django.contrib.sessions.middleware.SessionMiddleware',
51 53
     'django.middleware.common.CommonMiddleware',
@@ -57,6 +59,13 @@ MIDDLEWARE_CLASSES = (
57 59
     'django.middleware.security.SecurityMiddleware',
58 60
 )
59 61
 
62
+MIDDLEWARE_CLASSES += ('multidomain.middleware.DomainMiddleware', )
63
+
64
+URL_CONFIG = (
65
+    # (r'^(.+\.)?xfoto\.com\.cn', 'pai2.urls_www'),
66
+    (r'^(.+\.)?api\.xfoto\.com\.cn', 'pai2.urls_api'),
67
+)
68
+
60 69
 ROOT_URLCONF = 'pai2.urls'
61 70
 
62 71
 TEMPLATES = [
@@ -138,6 +147,9 @@ REST_FRAMEWORK = {
138 147
     'PAGE_SIZE': 1
139 148
 }
140 149
 
150
+# 唯一标识设置
151
+CURTAIL_UUID_LENGTH = 7
152
+
141 153
 # 域名设置
142 154
 DOMAIN = 'http://xfoto.com.cn'
143 155
 

+ 7 - 3
pai2/urls.py

@@ -33,14 +33,18 @@ urlpatterns = [
33 33
 ]
34 34
 
35 35
 urlpatterns += [
36
-    url(r'^api/', include('api.urls', namespace='api')),
37
-    # url(r'^photo/', include('photo.urls', namespace='photo'))
36
+    # url(r'^api/', include('api.urls', namespace='api')),
37
+    url(r'^s/(?P<session>\w+)$', photo_views.session_detail, name='session_detail'),
38
+    url(r'^p/(?P<photo>\w+)$', photo_views.photo_standard, name='photo_standard'),  # standard thumbnail, available for free
39
+    url(r'^m/(?P<photo>\w+)$', photo_views.photo_medium, name='photo_medium'),  # medium/mobile version, without watermark, login or paid by others
40
+    url(r'^l/(?P<photo>\w+)$', photo_views.photo_large, name='photo_large'),  # large, might support server side panning later, login required
41
+    url(r'^r/(?P<photo>\w+)$', photo_views.photo_raw, name='photo_raw'),  # raw image, only for finishers
38 42
 ]
39 43
 
40 44
 # Wire up our API using automatic URL routing.
41 45
 # Additionally, we include login URLs for the browsable API.
42 46
 urlpatterns += [
43
-    url(r'^apihome/', include(router.urls)),
47
+    url(r'^api/', include(router.urls)),
44 48
     url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
45 49
 ]
46 50
 

+ 10 - 0
pai2/urls_api.py

@@ -0,0 +1,10 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+
4
+from django.conf import settings
5
+from django.conf.urls import include, url
6
+
7
+
8
+urlpatterns = [
9
+    url(r'^', include('api.urls', namespace='api')),
10
+]

+ 0 - 4
pai2/uwsgi.bak/pai2_nginx.conf

@@ -26,10 +26,6 @@ server {
26 26
         alias /home/paiai/work/pai2/collect_static; # your Django project's static files - amend as required
27 27
     }
28 28
 
29
-    location /p/  {
30
-        alias /home/paiai/work/pai2/media/photo;  # Photo
31
-    }
32
-
33 29
     # Finally, send all non-media requests to the Django server.
34 30
     location / {
35 31
         # uwsgi_pass  pai2;

+ 6 - 6
photo/models.py

@@ -47,16 +47,16 @@ class PhotosInfo(CreateUpdateMixin):
47 47
 
48 48
     @property
49 49
     def photo_url(self):
50
-        # return u'{0}/media/{1}'.format(settings.DOMAIN, self.photo_path) if self.photo_path else ''
51
-        return u'{0}/p/{1}'.format(settings.DOMAIN, self.photo_name) if self.photo_name else ''
50
+        return u'{0}/media/{1}'.format(settings.DOMAIN, self.photo_path) if self.photo_path else ''
51
+        # return u'{0}/p/{1}'.format(settings.DOMAIN, self.photo_name) if self.photo_name else ''
52 52
 
53 53
     def _data(self):
54 54
         return {
55 55
             'pk': self.pk,
56
-            'lensman_id': self.lensman_id,
57
-            'session_id': self.session_id,
58
-            'photo_id': self.photo_id,
59
-            'photo_url': self.photo_url,
56
+            'user': self.lensman_id,
57
+            'session': self.session_id,
58
+            'photo': self.photo_id,
59
+            # 'photo_url': self.photo_url,
60 60
         }
61 61
 
62 62
     data = property(_data)

+ 10 - 0
photo/templates/photo/photo_detail.html

@@ -0,0 +1,10 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head lang="en">
4
+    <meta charset="UTF-8">
5
+    <title></title>
6
+</head>
7
+<body>
8
+    <img src="{{ photo_url }}">
9
+</body>
10
+</html>

+ 12 - 0
photo/templates/photo/session_detail.html

@@ -0,0 +1,12 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head lang="en">
4
+    <meta charset="UTF-8">
5
+    <title></title>
6
+</head>
7
+<body>
8
+    {% for photo in photos %}
9
+    <div><img src="{{ photo.photo_url }}"></div>
10
+    {% endfor %}
11
+</body>
12
+</html>

+ 33 - 7
photo/views.py

@@ -3,6 +3,7 @@
3 3
 from django.core.files.storage import default_storage
4 4
 from django.db import transaction
5 5
 from django.http import JsonResponse
6
+from django.shortcuts import render, redirect
6 7
 
7 8
 from rest_framework import viewsets
8 9
 
@@ -19,7 +20,7 @@ def uuid_init(request):
19 20
     num = int(request.GET.get('num', 1000))
20 21
 
21 22
     for i in xrange(num):
22
-        UUIDInfo.objects.create(uuid=curtailUUID())
23
+        UUIDInfo.objects.create(uuid=curtailUUID(UUIDInfo))
23 24
 
24 25
     return JsonResponse({
25 26
         'status': 200,
@@ -28,10 +29,10 @@ def uuid_init(request):
28 29
     })
29 30
 
30 31
 
31
-# curl -X POST -F lensman_id=123 -F num=100 http://xfoto.com.cn/api/uuid
32
+# curl -X POST -F user=xxxxxxx -F num=100 http://api.xfoto.com.cn/uuid
32 33
 @transaction.atomic
33 34
 def uuid(request):
34
-    lensman_id = request.POST.get('lensman_id', '')
35
+    lensman_id = request.POST.get('user', '')
35 36
     num = int(request.POST.get('num', 100))
36 37
 
37 38
     uuids = UUIDInfo.objects.select_for_update().filter(status=True)[:num]
@@ -58,10 +59,10 @@ def uuid(request):
58 59
 #               name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file  upload,
59 60
 #               while the < makes a text field and just get the contents for that text field from a file.
60 61
 #
61
-# curl -X POST -F lensman_id=123 -F session_id=456 -F photo=@7056288a9ddf2db294cf50a943920989.jpg;filename=789 http://xfoto.com.cn/api/photos/upload
62
+# curl -X POST -F user=xxxxxxx -F session=xxxxxxx -F photo=@xxxxxxx.jpg http://api.xfoto.com.cn/photos/upload
62 63
 def upload_photo(request):
63
-    lensman_id = request.POST.get('lensman_id', '')
64
-    session_id = request.POST.get('session_id', '')
64
+    lensman_id = request.POST.get('user', '')
65
+    session_id = request.POST.get('session', '')
65 66
 
66 67
     photo = request.FILES.get('photo', '')
67 68
 
@@ -79,7 +80,7 @@ def upload_photo(request):
79 80
             'message': u'摄影师不存在',
80 81
         })
81 82
 
82
-    photo_id = curtailUUID()
83
+    photo_id = curtailUUID(PhotosInfo, 'photo_id')
83 84
 
84 85
     _, extension = os.path.splitext(photo.name)
85 86
     # photo_path = 'photo/{0}/{1}/{2}{3}'.format(lensman_id, session_id, photo_id, extension)
@@ -105,6 +106,31 @@ def upload_photo(request):
105 106
     })
106 107
 
107 108
 
109
+def session_detail(request, session):
110
+    photos = PhotosInfo.objects.filter(session_id=session)
111
+    return render(request, 'photo/session_detail.html', {'photos': photos})
112
+
113
+
114
+def photo_standard(request, photo):
115
+    photo = PhotosInfo.objects.get(photo_id=photo)
116
+    return render(request, 'photo/photo_detail.html', {'photo_url': photo.photo_url})
117
+
118
+
119
+def photo_medium(request, photo):
120
+    photo = PhotosInfo.objects.get(photo_id=photo)
121
+    return render(request, 'photo/photo_detail.html', {'photo_url': photo.photo_url})
122
+
123
+
124
+def photo_large(request, photo):
125
+    photo = PhotosInfo.objects.get(photo_id=photo)
126
+    return render(request, 'photo/photo_detail.html', {'photo_url': photo.photo_url})
127
+
128
+
129
+def photo_raw(request, photo):
130
+    photo = PhotosInfo.objects.get(photo_id=photo)
131
+    return render(request, 'photo/photo_detail.html', {'photo_url': photo.photo_url})
132
+
133
+
108 134
 class PhotoInfoViewSet(viewsets.ModelViewSet):
109 135
     queryset = PhotosInfo.objects.all().order_by('-created_at')
110 136
     serializer_class = PhotosInfoSerializer

+ 5 - 3
utils/uuid_utils.py

@@ -1,16 +1,18 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
+from django.conf import settings
4
+
3 5
 from photo.models import UUIDInfo
4 6
 
5 7
 import shortuuid
6 8
 
7 9
 
8
-def curtailUUID(length=10):
10
+def curtailUUID(model, field='uuid', length=settings.CURTAIL_UUID_LENGTH):
9 11
     flag = True
10 12
     while flag:
11 13
         uuid = shortuuid.uuid()[-length:]
12 14
         try:
13
-            UUIDInfo.objects.get(uuid=uuid)
14
-        except UUIDInfo.DoesNotExist:
15
+            model.objects.get(**{field: uuid})
16
+        except model.DoesNotExist:
15 17
             flag = False
16 18
     return uuid

Pai2/pai2 - Gogs: Go Git Service

382 次代码提交 (44ff9cb8652903764d86e6e9a244fb5f2ade8bcc)

作者 SHA1 备注 提交日期
  Brightcells 44ff9cb865 Add api flyimg_detail_api 9 年之前
  Brightcells e9e810dc97 Fix Bug: unionid => unionId 9 年之前
  Brightcells 7049ae7e19 mini/userinfo 9 年之前
  Brightcells b52202a821 appId/appsecret 9 年之前
  Brightcells ac895ae2cd Add new api get_userinfo_api 9 年之前
  Brightcells 2d6faa5600 Add WECHAT_OAUTH2_RETRY_REDIRECT_URI 9 年之前
  Brightcells 96f741a814 Update upload_path 9 年之前
  Brightcells 435363c27a file md5 error 9 年之前
  Brightcells 90fd7187d8 file md5 9 年之前
  Brightcells 8d20a44c71 Remove 'Only Once Function' 9 年之前
  Brightcells ae70dce3ef file md5 9 年之前
  Brightcells 6e308e93b4 file md5 9 年之前
  Brightcells 8b64974ab3 Update requirements.txt 9 年之前
  Brightcells cdc55504fa Update requirements.txt 9 年之前
  Brightcells 23072337d7 Update acquire_lock: change 'ex' to 'time' 9 年之前
  Brightcells dd0d652498 Change to use 'from paginator import pagination' 9 年之前
  Brightcells ec611ba992 Add forbidden duplicate upload photo 9 年之前
  Brightcells ac953b8a4c Update requirements.txt 9 年之前
  Brightcells 048bb01c3e Update requirements.txt 9 年之前
  Brightcells 019a4588d3 Fix Bug: lost 'from django.conf import settings' 9 年之前
  Brightcells 88014f32b7 Remove unused vars in settings.py 9 年之前
  Brightcells 42f466c0a5 Change to use django-ip to get client ip 9 年之前
  Brightcells 3d1118760c Change to 'r.REDIS_EXPIRED_xx_xx' 9 年之前
  Brightcells 246a9ff4b8 Change to 'from utils.redis.connect import r' 9 年之前
  Brightcells 0a58248c81 Realize tour guide upload photo when auth in FE 9 年之前
  Brightcells 0d046d557e Return order detail for api wx_order_detail_api 9 年之前
  Brightcells d19a7d5efb Check tour guide group whether ended 9 年之前
  Brightcells 58845b4fd7 Fix Bug: get_geo_submit_flag result error 9 年之前
  Brightcells 5d13ae0917 Fix Bug: get_geo_submit_flag result error 9 年之前
  Brightcells 634de2864a Update requirements.txt 9 年之前
  Brightcells d31ffaa118 Update TODO 9 年之前
  Brightcells 4f1aa7665d Add geo submit flag for api tgu_group_user_locations_api 9 年之前
  Brightcells a9527e0247 Remove geo submit flag for api tg_group_detail_api 9 年之前
  Brightcells cd287d6483 Add docstring for def set_geo_submit_flag 9 年之前
  Brightcells a6660a7ab6 Realize set geo submit flag for api tg_group_detail_api 9 年之前
  Brightcells 4d51c3e342 Basic realize set geo submit flag for api tg_group_detail_api 9 年之前
  Brightcells 9b8d6f0f09 Update comment 9 年之前
  Brightcells 2d33b37a4b DONE TODO: Sum(relative_persons) for api tg_group_detail_api 9 年之前
  Brightcells 19fb5e3b2d DONE TODO: Remove tourguide for api tg_group_detail_api 9 年之前
  Brightcells 8fb9461cba to 9 年之前
  Brightcells 90d377ee6e Add gather location 9 年之前
  Brightcells b62ab5aac1 Fix Bug: attentions and schedules update error 9 年之前
  Brightcells 612465eec2 Logit body and res for api tg_group_update_api 9 年之前
  Brightcells 4b68389146 Remove gather_info when gather_at expired for api pai2_tginfo_api 9 年之前
  Brightcells 87ea86d2b1 Fix Bug: return not 200 cause duplicate upload 9 年之前
  Brightcells 59def8d479 Add forbidden duplicate upload photo 9 年之前
  Brightcells 214bbec976 Update requirements.txt & Change param ex_time to time 9 年之前
  Brightcells 5d3befcd2b Update return format 9 年之前
  Brightcells 564ff620d7 Add unique_together = (('group_id', 'user_id'),) for GroupUserInfo 9 年之前
  Brightcells 95ee5c7b7a Add logit res for tgu_group_user_join_api 9 年之前