Ejemplo n.º 1
0
def upload(request):
    if request.method == "POST":
        upload = UploadForm(request.POST, request.FILES)
        filename = upload.save(request)
        if filename:
            return HttpResponseRedirect("/i/%s" % filename)
        else:
            user = None
            if 'user_id' in request.session:
                user_service = UserService()
                user = user_service.get(request.session['user_id'])
            return render(request,
                          'home.html', {
                              "user": user,
                              "upload_form": upload
                          },
                          context_instance=RequestContext(request))
    elif "url" in request.GET:
        image_service = ImageService()
        try:
            key = image_service.store_from_url(request.GET["url"],
                                               request.session["user_id"])
            return HttpResponseRedirect("/i/%s" % key)
        except ImageError as e:
            return HttpResponse(e.msg, status=400)
    else:
        return HttpResponseRedirect("/")
Ejemplo n.º 2
0
 def clean(self):
     user_service = UserService()
     user = user_service.login(self.cleaned_data['username'],
                               self.cleaned_data['password'])
     if user:
         self.cleaned_data['user_id'] = user.get_key()
         return self.cleaned_data
     else:
         raise forms.ValidationError(u'Invalid username or password')
Ejemplo n.º 3
0
def home(request):
    user = None
    if 'user_id' in request.session:
        user_service = UserService()
        user = user_service.get(request.session['user_id'])

    upload_form = UploadForm(label_suffix="<br/>")

    return render(request, 'home.html',
                  {"user": user, "upload_form": upload_form},
                  context_instance=RequestContext(request))
Ejemplo n.º 4
0
def home(request):
    user = None
    if 'user_id' in request.session:
        user_service = UserService()
        user = user_service.get(request.session['user_id'])

    upload_form = UploadForm(label_suffix="<br/>")

    return render(request,
                  'home.html', {
                      "user": user,
                      "upload_form": upload_form
                  },
                  context_instance=RequestContext(request))
Ejemplo n.º 5
0
def upload(request):
    if request.method == "POST":
        upload = UploadForm(request.POST, request.FILES)
        filename = upload.save(request)
        if filename:
            return HttpResponseRedirect("/i/%s" % filename)
        else:
            user = None
            if 'user_id' in request.session:
                user_service = UserService()
                user = user_service.get(request.session['user_id'])
            return render(request, 'home.html',
                          {"user": user, "upload_form": upload},
                          context_instance=RequestContext(request))
    elif "url" in request.GET:
        image_service = ImageService()
        try:
            key = image_service.store_from_url(request.GET["url"],
                                               request.session["user_id"])
            return HttpResponseRedirect("/i/%s" % key)
        except ImageError as e:
            return HttpResponse(e.msg, status=400)
    else:
        return HttpResponseRedirect("/")
Ejemplo n.º 6
0
 def save(self):
     user_data = self.cleaned_data
     user_service = UserService()
     return user_service.save(user_data)