comparison user_photos/views.py @ 972:7138883966b3

Started unit tests for hotlinking images.
author Brian Neal <bgneal@gmail.com>
date Wed, 23 Sep 2015 21:26:09 -0500
parents 4f265f61874b
children d9cd3180c12c
comparison
equal deleted inserted replaced
971:4f265f61874b 972:7138883966b3
154 ret = {'error_msg': '', 'url': ''} 154 ret = {'error_msg': '', 'url': ''}
155 status_code = 400 155 status_code = 400
156 156
157 if not request.user.is_authenticated(): 157 if not request.user.is_authenticated():
158 ret['error_msg'] = 'Please login to use this service' 158 ret['error_msg'] = 'Please login to use this service'
159 return JsonResponse(ret, status=status_code) 159 return JsonResponse(ret, status=403)
160 if not request.is_ajax() or request.method != 'POST': 160 if not request.is_ajax() or request.method != 'POST':
161 ret['error_msg'] = 'This method is not allowed' 161 ret['error_msg'] = 'This method is not allowed'
162 return JsonResponse(ret, status=status_code) 162 return JsonResponse(ret, status=405)
163 163
164 if settings.USER_PHOTOS_ENABLED: 164 if settings.USER_PHOTOS_ENABLED:
165 form = HotLinkImageForm(request.POST, request.FILES, user=request.user) 165 form = HotLinkImageForm(request.POST, user=request.user)
166 if form.is_valid(): 166 if form.is_valid():
167 try: 167 try:
168 ret['url'] = form.save() 168 ret['url'] = form.save()
169 status_code = 200 169 status_code = 200
170 except Exception as ex: 170 except Exception as ex: