def create(self, request): # get information upload_description = request.POST.get('description') board_id = int(request.POST.get('board_id')) theBoard = Board.objects.get(pk=board_id) print theBoard latitude = float(request.POST.get('latitude', -1)) longitude = float(request.POST.get('longitude', -1)) if theBoard.owner.id == request.user.id: # have permission to upload if request.FILES.get('pic') == None: # here is a bug in piston that the form validation can't validate # file type, such as FileField and ImageField. # I have to do this all by myself. return errorResponse(1, 0, '请求错误', rc.BAD_REQUEST) filename = UploadImage.handle_upload_image( request.FILES['pic'], UploadImage.ImgType.PICTURE) imageUrl = '/media/pictures/' + filename thePicture = Picture.objects.create( image=imageUrl, timestamp=datetime.datetime.now()) print thePicture pictureStatus = PictureStatus.objects.create( picture=thePicture, description=upload_description, board=theBoard) print pictureStatus return getPictureStatusDict(request, pictureStatus) else: return errorResponse(0, 2, '您不拥有该相册!', rc.FORBIDDEN)
def create(self,request): # get information upload_description = request.POST.get('description') board_id = int(request.POST.get('board_id')) theBoard = Board.objects.get(pk = board_id) print theBoard latitude = float(request.POST.get('latitude',-1)) longitude = float(request.POST.get('longitude',-1)) if theBoard.owner.id == request.user.id: # have permission to upload if request.FILES.get('pic') == None: # here is a bug in piston that the form validation can't validate # file type, such as FileField and ImageField. # I have to do this all by myself. return errorResponse(1,0,'请求错误',rc.BAD_REQUEST) filename = UploadImage.handle_upload_image(request.FILES['pic'],UploadImage.ImgType.PICTURE) imageUrl = '/media/pictures/'+filename thePicture = Picture.objects.create(image=imageUrl,timestamp = datetime.datetime.now()) print thePicture pictureStatus = PictureStatus.objects.create(picture=thePicture,description = upload_description,board = theBoard) print pictureStatus return getPictureStatusDict(request,pictureStatus) else : return errorResponse(0,2,'您不拥有该相册!',rc.FORBIDDEN)
def create(self,request): the_introduction = request.form.cleaned_data['introduction'] the_location = request.form.cleaned_data['location'] the_nick = request.form.cleaned_data['nick'] print 'the nick:'+the_nick avatarUrl = None if request.FILES.get('avatar') != None: filename = UploadImage.handle_upload_image(request.FILES['avatar'],UploadImage.ImgType.AVATAR) host = request.get_host() avatarUrl = 'http://'+host+'/media/avatar/'+filename user = request.user if the_introduction != None and the_introduction != '': user.addition.introduction = the_introduction if the_location != None and the_location != '': user.addition.location = the_location if the_nick != None and the_nick != '': user.addition.nick = the_nick if avatarUrl != None and avatarUrl != '': user.addition.avatar = avatarUrl user.save() user.addition.save() return getUserDict(request,user)
def create(self, request): the_introduction = request.form.cleaned_data['introduction'] the_location = request.form.cleaned_data['location'] the_nick = request.form.cleaned_data['nick'] print 'the nick:' + the_nick avatarUrl = None if request.FILES.get('avatar') != None: filename = UploadImage.handle_upload_image( request.FILES['avatar'], UploadImage.ImgType.AVATAR) host = request.get_host() avatarUrl = 'http://' + host + '/media/avatar/' + filename user = request.user if the_introduction != None and the_introduction != '': user.addition.introduction = the_introduction if the_location != None and the_location != '': user.addition.location = the_location if the_nick != None and the_nick != '': user.addition.nick = the_nick if avatarUrl != None and avatarUrl != '': user.addition.avatar = avatarUrl user.save() user.addition.save() return getUserDict(request, user)