コード例 #1
0
ファイル: views.py プロジェクト: F483/bikesurf.org
def create(request, team_link, bike_id):

    # get parameters
    start = request.GET.get('start', None)
    finish = request.GET.get('finish', None)
    try:
        start = start and parse(start).date() or None
        finish = finish and parse(finish).date() or None
    except ValueError:
        start = None
        finish = None

    team = team_control.get_or_404(team_link)
    account = get_object_or_404(Account, user=request.user)
    is_lender = team_control.is_member(account, team)
    bike = get_object_or_404(Bike, id=bike_id)
    if request.method == "POST":
        form = forms.Create(request.POST, bike=bike, account=account, 
                            start=start, finish=finish, is_lender=is_lender)
        if form.is_valid():
            borrow = control.create(account, bike,
                                    form.cleaned_data["start"],
                                    form.cleaned_data["finish"],
                                    form.cleaned_data["note"].strip())
            return HttpResponseRedirect("/borrow/view/%s" % borrow.id)
    else:
        form = forms.Create(bike=bike, account=account, 
                            start=start, finish=finish, is_lender=is_lender)
    args = { 
        "form" : form, "form_title" : _("BORROW_CREATE"),
        "cancel_url" : "/%s/bike/view/%s" % (team_link, bike_id),
        "has_required_info" : account_control.has_required_info(account)
    }
    return rtr(team, "borrows", request, "borrow/create.html", args)
コード例 #2
0
ファイル: views.py プロジェクト: F483/bikesurf.org
def profile(request):
    account = get_object_or_404(Account, user=request.user)
    email = control.get_email_or_404(account)
    args = { 
        "links" : account.links.all(), "email" : email,
        "has_required_info" : control.has_required_info(account)
    }
    return render_response(request, "account/profile.html", args)
コード例 #3
0
def profile(request):
    account = get_object_or_404(Account, user=request.user)
    email = control.get_email_or_404(account)
    args = {
        "links": account.links.all(),
        "email": email,
        "has_required_info": control.has_required_info(account)
    }
    return render_response(request, "account/profile.html", args)
コード例 #4
0
def create(account, bike, start, finish, note):
    if not account_control.has_required_info(account):
        raise PermissionDenied
    if not creation_is_allowed(account, bike, start, finish):
        raise PermissionDenied
    borrow = Borrow()
    borrow.bike = bike
    borrow.team = bike.team
    borrow.borrower = account
    borrow.start = start
    borrow.finish = finish
    borrow.active = False
    borrow.state = "REQUEST"
    borrow.save()
    log(account, borrow, note, "CREATE")
    return borrow
コード例 #5
0
def create(request, team_link, bike_id):

    # get parameters
    start = request.GET.get('start', None)
    finish = request.GET.get('finish', None)
    try:
        start = start and parse(start).date() or None
        finish = finish and parse(finish).date() or None
    except ValueError:
        start = None
        finish = None

    team = team_control.get_or_404(team_link)
    account = get_object_or_404(Account, user=request.user)
    is_lender = team_control.is_member(account, team)
    bike = get_object_or_404(Bike, id=bike_id)
    if request.method == "POST":
        form = forms.Create(request.POST,
                            bike=bike,
                            account=account,
                            start=start,
                            finish=finish,
                            is_lender=is_lender)
        if form.is_valid():
            borrow = control.create(account, bike, form.cleaned_data["start"],
                                    form.cleaned_data["finish"],
                                    form.cleaned_data["note"].strip())
            return HttpResponseRedirect("/borrow/view/%s" % borrow.id)
    else:
        form = forms.Create(bike=bike,
                            account=account,
                            start=start,
                            finish=finish,
                            is_lender=is_lender)
    args = {
        "form": form,
        "form_title": _("BORROW_CREATE"),
        "cancel_url": "/%s/bike/view/%s" % (team_link, bike_id),
        "has_required_info": account_control.has_required_info(account)
    }
    return rtr(team, "borrows", request, "borrow/create.html", args)