iff-607b36ab2b0beb837a51cc7f0156d074e6ac5d2cL46">46
'photo',
)
+INSTALLED_APPS += ('multidomain', )
+
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
@@ -57,6 +59,13 @@ MIDDLEWARE_CLASSES = (
'django.middleware.security.SecurityMiddleware',
)
+MIDDLEWARE_CLASSES += ('multidomain.middleware.DomainMiddleware', )
+
+URL_CONFIG = (
+ # (r'^(.+\.)?xfoto\.com\.cn', 'pai2.urls_www'),
+ (r'^(.+\.)?api\.xfoto\.com\.cn', 'pai2.urls_api'),
+)
+
ROOT_URLCONF = 'pai2.urls'
TEMPLATES = [
@@ -138,6 +147,9 @@ REST_FRAMEWORK = {
'PAGE_SIZE': 1
}
+# 唯一标识设置
+CURTAIL_UUID_LENGTH = 7
+
# 域名设置
DOMAIN = 'http://xfoto.com.cn'
@@ -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 |
|
@@ -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 |
+] |
@@ -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; |
@@ -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) |
@@ -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> |
@@ -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> |
@@ -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 |
@@ -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 |