Beispiel #1
0
def edit(request, project_id):
    user = users.get_current_user()
    if user is None:
        return HttpResponseRedirect(users.create_login_url("/"))
    try:
        key = db.Key(encoded=project_id)
        project = db.Query(Project).filter("owner", request.user).filter("__key__", key).get()
    except:
        raise Http404
    else:
        if project is None:
            raise Http404

    form = ProjectForm(data=request.POST or None, instance=project)
    if request.method == "POST":
        if form.is_valid():
            try:
                project = form.save(commit=False)
            except ValueError, err:
                pass

            if request.FILES:
                uploaded_icon = request.FILES["icon"]
                # TODO: Check for exceptions here...
                icon = images.resize(uploaded_icon["content"], 72, 72)
                project.icon = db.Blob(icon)

            project.put()
Beispiel #2
0
def create(request):
    # TODO: create a decorator: @requires_login(users.create_login_url...)
    user = users.get_current_user()
    if user is None:
        return HttpResponseRedirect(users.create_login_url(reverse("droidsconnect.project.views.create")))

    if request.method == "POST":
        # form = ProjectForm(request.POST)
        form = ProjectForm(data=request.POST)
        if form.is_valid():
            try:
                project = form.save(commit=False)
                project.owner = request.user
            except ValueError, err:
                # TODO: Handle errors...
                pass
            else:
                project.put()

            if request.FILES:
                uploaded_icon = request.FILES["icon"]
                # TODO: Check for exceptions here...
                icon = images.resize(uploaded_icon["content"], 72, 72)
                project.icon = db.Blob(icon)

            project.put()

            key = project.key()
            id = str(key)

            return HttpResponseRedirect(reverse("droidsconnect.project.views.detail", args=[id]))
        else:
            logging.info("not valid...")