Mercurial > public > sg101
comparison user_photos/views.py @ 1096:d9cd3180c12c
More GCalendar V3 conversion in progress.
Built a brand new post editor. It is hardcoded into GCalendar
right now. We will make it more general in the future.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 14 Jun 2016 21:16:09 -0500 |
parents | 7138883966b3 |
children | 364f8ec48612 |
comparison
equal
deleted
inserted
replaced
1095:74d7e56a9cfb | 1096:d9cd3180c12c |
---|---|
80 ret['msg'] = '\n'.join(errors) | 80 ret['msg'] = '\n'.join(errors) |
81 else: | 81 else: |
82 ret['msg'] = 'Photo uploads are temporarily disabled' | 82 ret['msg'] = 'Photo uploads are temporarily disabled' |
83 | 83 |
84 return HttpResponse(json.dumps(ret), content_type='application/json') | 84 return HttpResponse(json.dumps(ret), content_type='application/json') |
85 | |
86 | |
87 def upload_ajax_v3(request): | |
88 """This view is the V3 ajax version of the upload function, above. | |
89 | |
90 We return a JSON object response to the client with the following name | |
91 & value pairs: | |
92 'msg' : string error message if success is false | |
93 'url' : the image URL as a string if success | |
94 """ | |
95 ret = {'error_msg': '', 'url': ''} | |
96 status_code = 400 | |
97 | |
98 if not request.user.is_authenticated(): | |
99 ret['error_msg'] = 'Please login to use this service' | |
100 return JsonResponse(ret, status=403) | |
101 if not request.is_ajax() or request.method != 'POST': | |
102 ret['error_msg'] = 'This method is not allowed' | |
103 return JsonResponse(ret, status=405) | |
104 | |
105 if settings.USER_PHOTOS_ENABLED: | |
106 form = UploadForm(request.POST, request.FILES, user=request.user) | |
107 if form.is_valid(): | |
108 try: | |
109 photo = form.save() | |
110 ret['url'] = photo.url | |
111 status_code = 200 | |
112 except Exception as ex: | |
113 ret['error_msg'] = str(ex) | |
114 status_code = 500 | |
115 else: | |
116 # gather form error messages | |
117 errors = [] | |
118 non_field_errors = form.non_field_errors().as_text() | |
119 if non_field_errors: | |
120 errors.append(non_field_errors) | |
121 for field_errors in form.errors.values(): | |
122 errors.append(field_errors.as_text()) | |
123 ret['msg'] = '\n'.join(errors) | |
124 else: | |
125 ret['msg'] = 'Photo uploads are temporarily disabled' | |
126 status_code = 403 | |
127 | |
128 return JsonResponse(ret, status=status_code) | |
85 | 129 |
86 | 130 |
87 class GalleryView(ListView): | 131 class GalleryView(ListView): |
88 """A ListView for displaying a user's photos""" | 132 """A ListView for displaying a user's photos""" |
89 | 133 |