def post(self,request): if request.user.is_authenticated(): data = qdict_to_dict(request.DATA) data['writing_user']=request.user.id art = ArticleSerializer(data=data, partial=True) if not art.is_valid(): print art.errors return HttpResponseRedirect('/') art.save() else: data = qdict_to_dict(request.DATA) data['is_anony']=True art = AnonyArticleSerializer(data=data, partial=True) if not art.is_valid(): print art.errors return HttpResponseRedirect('/') art.save() try: for img in request.FILES.getlist('content_image'): print img image_name = image_uploader(img,'article') image = ArticleImage(image_name = image_name , article = art.object) image.save() except: art.object.delete() return HttpResponseRedirect('/') return HttpResponseRedirect('/article/?id=%s'%(art.data['id']))
def post(self,request,user_id): """ Profile Image Change """ if not request.user.is_authenticated(): return HttpResponseRedirect('/login/') if not 'profile_image' in request.FILES: return HttpResponseRedirect('/') else: image = image_uploader(request.FILES['profile_image'],'profile') if image is not None: request.user.profile_image = image request.user.save() return HttpResponseRedirect('/profile/%s/'%(user_id)) return HttpResponseRedirect('/profile/%s/'%(user_id))