def edit(request, wizard): account = get_object_or_404(Account, user=request.user) if request.method == "POST": form = forms.Edit(request.POST, account=account) if form.is_valid(): control.edit(account, form.cleaned_data["username"].strip(), form.cleaned_data["first_name"].strip(), form.cleaned_data["last_name"].strip(), form.cleaned_data["mobile"].strip(), form.cleaned_data["source"], form.cleaned_data["description"].strip()) if wizard: return HttpResponseRedirect("/account/wiz/passport") else: return HttpResponseRedirect("/account/profile") else: form = forms.Edit(account=account) args = { "form_title": account, "form": form, "cancel_url": "/account/profile", "form_subtitle": _("ADD_REQUIRED_PROFILE_INFO"), "form_info": _("USER_PRIVECY_INFORMATION"), } return render_response(request, "site/form.html", args)
def setprimary(request, **kwargs): team_link = kwargs.get("team_link") picture_id = kwargs["picture_id"] account = get_object_or_404(Account, user=request.user) team = team_link and team_control.get_or_404(team_link) or None picture = get_object_or_404(Picture, id=picture_id) prefix = team_link and "/%s" % team_link or "" url = "%s/gallery/list/%s" % (prefix, picture.gallery.id) if team: assert_member(account, team) if request.method == "POST": form = Form(request.POST) if form.is_valid(): control.setprimary(account, picture) return HttpResponseRedirect(url) else: form = Form() # TODO make template that shows the image being set! args = { "form" : form, "form_title" : _("SET_AS_PRIMARY_PICTURE"), "cancel_url" : url } if team: return rtr(team, None, request, "site/form.html", args) else: return render_response(request, "site/form.html", args)
def edit(request, wizard): account = get_object_or_404(Account, user=request.user) if request.method == "POST": form = forms.Edit(request.POST, account=account) if form.is_valid(): control.edit( account, form.cleaned_data["username"].strip(), form.cleaned_data["first_name"].strip(), form.cleaned_data["last_name"].strip(), form.cleaned_data["mobile"].strip(), form.cleaned_data["source"], form.cleaned_data["description"].strip() ) if wizard: return HttpResponseRedirect("/account/wiz/passport") else: return HttpResponseRedirect("/account/profile") else: form = forms.Edit(account=account) args = { "form_title" : account, "form" : form, "cancel_url" : "/account/profile", "form_subtitle" : _("ADD_REQUIRED_PROFILE_INFO"), "form_info" : _("USER_PRIVECY_INFORMATION"), } return render_response(request, "site/form.html", args)
def add(request, **kwargs): team_link = kwargs.get("team_link") gallery_id = kwargs["gallery_id"] account = get_object_or_404(Account, user=request.user) gallery = get_object_or_404(Gallery, id=gallery_id) team = team_link and team_control.get_or_404(team_link) or None url_prefix = team_link and "/%s" % team_link or "" if team: assert_member(account, team) if request.method == "POST": form = forms.Add(request.POST, request.FILES) if form.is_valid(): picture = control.add(account, form.cleaned_data["image"], gallery) url = "%s/gallery/view/%s" % (url_prefix, picture.id) return HttpResponseRedirect(url) else: form = forms.Add() args = { "form" : form, "form_title" : _("ADD_PICTURE_TO_GALLERY"), "cancel_url" : "%s/gallery/list/%s" % (url_prefix, gallery_id), "multipart_form" : True } if team: return rtr(team, None, request, "site/form.html", args) else: return render_response(request, "site/form.html", args)
def borrower_list(request): account = get_object_or_404(Account, user=request.user) borrows = Borrow.objects.filter(borrower=account) args = { "page_title" : _("YOUR_BORROWS"), "list_data" : control.to_list_data(borrows) } return render_response(request, "site/list.html", args)
def render_team_response(team, current, request, template, args): args.update({ "team_menu_public" : _get_team_menue_public(team, current), "team_menu_intern" : _get_team_menue_intern(team, current), "current_team" : team, "current_team_links" : team.links.all(), }) return render_response(request, template, args)
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)
def borrower_list(request): account = get_object_or_404(Account, user=request.user) borrows = Borrow.objects.filter(borrower=account) args = { "page_title": _("YOUR_BORROWS"), "list_data": control.to_list_data(borrows) } return render_response(request, "site/list.html", args)
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)
def borrower_view(request, borrow_id): account = get_object_or_404(Account, user=request.user) borrow = get_object_or_404(Borrow, id=borrow_id) if account != borrow.borrower: if team_control.is_member(account, borrow.team): # is_lender url = "/%s/borrow/view/%s" % (borrow.team.link, borrow.id) return HttpResponseRedirect(url) # redirect lender to right url raise PermissionDenied args = {"borrow": borrow, "logs": borrow.logs.all()} return render_response(request, "borrow/view.html", args)
def borrower_view(request, borrow_id): account = get_object_or_404(Account, user=request.user) borrow = get_object_or_404(Borrow, id=borrow_id) if account != borrow.borrower: if team_control.is_member(account, borrow.team): # is_lender url = "/%s/borrow/view/%s" % (borrow.team.link, borrow.id) return HttpResponseRedirect(url) # redirect lender to right url raise PermissionDenied args = { "borrow" : borrow, "logs" : borrow.logs.all() } return render_response(request, "borrow/view.html", args)
def view(request, **kwargs): team_link = kwargs.get("team_link") picture_id = kwargs["picture_id"] team = team_link and team_control.get_or_404(team_link) or None picture = get_object_or_404(Picture, id=picture_id) args = { "picture" : picture } if team: return rtr(team, None, request, "gallery/view.html", args) else: return render_response(request, "gallery/view.html", args)
def view(request, username): current_account = get_object_or_404(Account, user=request.user) view_account = get_object_or_404(Account, user__username=username) if not control.can_view_account(current_account, view_account): raise PermissionDenied email = control.get_email_or_404(view_account) args = { "view_account" : view_account, "links" : view_account.links.all(), "email" : email } return render_response(request, "account/view.html", args)
def listing(request, **kwargs): team_link = kwargs.get("team_link") gallery_id = kwargs["gallery_id"] team = team_link and team_control.get_or_404(team_link) or None gallery = get_object_or_404(Gallery, id=gallery_id) pictures = gallery.pictures.all() args = { "gallery" : gallery, "pictures" : pictures } if team: return rtr(team, None, request, "gallery/list.html", args) else: return render_response(request, "gallery/list.html", args)
def departures(request): today = datetime.datetime.now().date() account = get_object_or_404(Account, user=request.user) borrows = control.departures(account) args = { "page_title": _("DEPARTURES"), "list_data": control.to_list_data(borrows, team_link=True, columns="DEPARTURES") } return render_response(request, "site/list.html", args)
def departures(request): today = datetime.datetime.now().date() account = get_object_or_404(Account, user=request.user) borrows = control.departures(account) args = { "page_title" : _("DEPARTURES"), "list_data" : control.to_list_data( borrows, team_link=True, columns="DEPARTURES" ) } return render_response(request, "site/list.html", args)
def view(request, username): current_account = get_object_or_404(Account, user=request.user) view_account = get_object_or_404(Account, user__username=username) if not control.can_view_account(current_account, view_account): raise PermissionDenied email = control.get_email_or_404(view_account) args = { "view_account": view_account, "links": view_account.links.all(), "email": email } return render_response(request, "account/view.html", args)
def index(request): if request.method == 'POST': form = TeamSelectForm(request.POST) if form.is_valid(): team_link = form.cleaned_data['team'].link return HttpResponseRedirect("/%s" % team_link) else: form = TeamSelectForm() imgdir = os.path.join("apps", "site", "static", "site", "splash") img = random.choice(os.listdir(os.path.join(PROJECT_DIR, imgdir))) splash_bg = os.path.join("/static", "site", "splash", img) args = { 'form' : form, "splash_bg" : splash_bg } return render_response(request, 'site/index.html', args)
def index(request): if request.method == 'POST': form = TeamSelectForm(request.POST) if form.is_valid(): team_link = form.cleaned_data['team'].link return HttpResponseRedirect("/%s" % team_link) else: form = TeamSelectForm() imgdir = os.path.join("apps", "site", "static", "site", "splash") img = random.choice(os.listdir(os.path.join(PROJECT_DIR, imgdir))) splash_bg = os.path.join("/static", "site", "splash", img) args = {'form': form, "splash_bg": splash_bg} return render_response(request, 'site/index.html', args)
def link_delete(request, link_id): account = get_object_or_404(Account, user=request.user) link = get_object_or_404(Link, id=link_id) if request.method == "POST": form = forms.LinkDelete(request.POST, link=link, account=account) if form.is_valid(): control.link_delete(account, link) return HttpResponseRedirect("/account/profile") else: form = forms.LinkDelete(link=link, account=account) args = { "form" : form, "form_title" : _("LINK_DELETE?"), "form_subtitle" : link.get_label(), "cancel_url" : "/account/profile" } return render_response(request, "site/form.html", args)
def borrower_cancel(request, borrow_id): account = get_object_or_404(Account, user=request.user) borrow = get_object_or_404(Borrow, id=borrow_id) if account != borrow.borrower: raise PermissionDenied if request.method == "POST": form = forms.Cancel(request.POST) if form.is_valid(): control.cancel(account, borrow, form.cleaned_data["note"].strip()) return HttpResponseRedirect("/borrow/view/%s" % borrow.id) else: form = forms.Cancel() args = { "form" : form, "form_title" : _("BORROW_CANCEL"), "cancel_url" : "/borrow/view/%s" % borrow_id } return render_response(request, "site/form.html", args)
def replace_logo(request, team_link): account = get_object_or_404(Account, user=request.user) team = control.get_or_404(team_link) assert_member(account, team) if request.method == "POST": form = forms.ReplaceLogo(request.POST, request.FILES) if form.is_valid(): logo = form.cleaned_data["logo"] control.replace_logo(account, team, logo) return HttpResponseRedirect("/%s" % team.link) else: form = forms.ReplaceLogo() args = { "form" : form, "form_title" : _("REPLACE_LOGO"), "multipart_form" : True, "cancel_url" : "/%s" % team.link } return render_response(request, "site/form.html", args)
def link_delete(request, link_id): account = get_object_or_404(Account, user=request.user) link = get_object_or_404(Link, id=link_id) if request.method == "POST": form = forms.LinkDelete(request.POST, link=link, account=account) if form.is_valid(): control.link_delete(account, link) return HttpResponseRedirect("/account/profile") else: form = forms.LinkDelete(link=link, account=account) args = { "form": form, "form_title": _("LINK_DELETE?"), "form_subtitle": link.get_label(), "cancel_url": "/account/profile" } return render_response(request, "site/form.html", args)
def borrower_cancel(request, borrow_id): account = get_object_or_404(Account, user=request.user) borrow = get_object_or_404(Borrow, id=borrow_id) if account != borrow.borrower: raise PermissionDenied if request.method == "POST": form = forms.Cancel(request.POST) if form.is_valid(): control.cancel(account, borrow, form.cleaned_data["note"].strip()) return HttpResponseRedirect("/borrow/view/%s" % borrow.id) else: form = forms.Cancel() args = { "form": form, "form_title": _("BORROW_CANCEL"), "cancel_url": "/borrow/view/%s" % borrow_id } return render_response(request, "site/form.html", args)
def create(request): account = get_object_or_404(Account, user=request.user) if request.method == "POST": form = forms.CreateTeam(request.POST, request.FILES) if form.is_valid(): name = form.cleaned_data["name"].strip() country = form.cleaned_data["country"] logo = form.cleaned_data["logo"] application = form.cleaned_data["application"] team = control.create(account, name, country, logo, application) return HttpResponseRedirect("/%s/created" % team.link) else: form = forms.CreateTeam() args = { "form" : form, "form_title" : _("CREATE_TEAM"), "multipart_form" : True, "cancel_url" : "/" } return render_response(request, "site/form.html", args)
def set_passport(request, wizard): account = get_object_or_404(Account, user=request.user) if request.method == "POST": form = forms.SetPassport(request.POST, request.FILES) if form.is_valid(): passport = form.cleaned_data["passport"] control.set_passport(account, passport) return HttpResponseRedirect("/account/profile") # TODO go to initial borrow request user came from else: form = forms.SetPassport() args = { "form" : form, "form_title" : _("SET_PASSPORT"), "cancel_url" : "/account/profile", "multipart_form" : True, "form_subtitle" : _("ADD_REQUIRED_PASSPORT_IMAGE"), "form_info" : _("USER_PRIVECY_INFORMATION"), } return render_response(request, "site/form.html", args)
def replace_logo(request, team_link): account = get_object_or_404(Account, user=request.user) team = control.get_or_404(team_link) assert_member(account, team) if request.method == "POST": form = forms.ReplaceLogo(request.POST, request.FILES) if form.is_valid(): logo = form.cleaned_data["logo"] control.replace_logo(account, team, logo) return HttpResponseRedirect("/%s" % team.link) else: form = forms.ReplaceLogo() args = { "form": form, "form_title": _("REPLACE_LOGO"), "multipart_form": True, "cancel_url": "/%s" % team.link } return render_response(request, "site/form.html", args)
def set_passport(request, wizard): account = get_object_or_404(Account, user=request.user) if request.method == "POST": form = forms.SetPassport(request.POST, request.FILES) if form.is_valid(): passport = form.cleaned_data["passport"] control.set_passport(account, passport) return HttpResponseRedirect("/account/profile") # TODO go to initial borrow request user came from else: form = forms.SetPassport() args = { "form": form, "form_title": _("SET_PASSPORT"), "cancel_url": "/account/profile", "multipart_form": True, "form_subtitle": _("ADD_REQUIRED_PASSPORT_IMAGE"), "form_info": _("USER_PRIVECY_INFORMATION"), } return render_response(request, "site/form.html", args)
def create(request): account = get_object_or_404(Account, user=request.user) if request.method == "POST": form = forms.CreateTeam(request.POST, request.FILES) if form.is_valid(): name = form.cleaned_data["name"].strip() country = form.cleaned_data["country"] logo = form.cleaned_data["logo"] application = form.cleaned_data["application"] team = control.create(account, name, country, logo, application) return HttpResponseRedirect("/%s/created" % team.link) else: form = forms.CreateTeam() args = { "form": form, "form_title": _("CREATE_TEAM"), "multipart_form": True, "cancel_url": "/" } return render_response(request, "site/form.html", args)
def link_create(request): account = get_object_or_404(Account, user=request.user) if request.method == "POST": form = forms.LinkCreate(request.POST, account=account) if form.is_valid(): control.link_create( account, form.cleaned_data["site"], form.cleaned_data["profile"].strip(), ) return HttpResponseRedirect("/account/profile") else: form = forms.LinkCreate(account=account) args = { "form_title" : account, "form" : form, "cancel_url" : "/account/profile", "form_subtitle" : _("ADD_REQUIRED_SOCIAL_LINK"), "form_info" : _("USER_PRIVECY_INFORMATION"), } return render_response(request, "site/form.html", args)
def comment(request, **kwargs): borrow_id = kwargs["borrow_id"] team_link = kwargs.get("team_link") account = get_object_or_404(Account, user=request.user) team = team_link and team_control.get_or_404(team_link) or None borrow = get_object_or_404(Borrow, id=borrow_id) url_prefix = team and "/%s" % team.link or "" url = "%s/borrow/view/%s" % (url_prefix, borrow_id) if request.method == "POST": form = forms.Comment(request.POST) if form.is_valid(): control.comment(account, borrow, form.cleaned_data["note"].strip()) return HttpResponseRedirect(url) else: form = forms.Comment() args = {"form": form, "form_title": _("BORROW_COMMENT"), "cancel_url": url} if team: return rtr(team, "borrows", request, "site/form.html", args) return render_response(request, "site/form.html", args)
def borrower_rate(request, borrow_id): account = get_object_or_404(Account, user=request.user) borrow = get_object_or_404(Borrow, id=borrow_id) if account != borrow.borrower: raise PermissionDenied if request.method == "POST": form = forms.Rate(request.POST) if form.is_valid(): rating = form.cleaned_data["rating"] note = form.cleaned_data["note"].strip() control.borrower_rate(account, borrow, rating, note) return HttpResponseRedirect("/borrow/view/%s" % borrow.id) else: form = forms.Rate() form_title = u"%s %s" % (_("RATE"), borrow) args = { "form" : form, "form_title" : form_title, "cancel_url" : "/borrow/view/%s" % borrow_id } return render_response(request, "site/form.html", args)
def link_create(request): account = get_object_or_404(Account, user=request.user) if request.method == "POST": form = forms.LinkCreate(request.POST, account=account) if form.is_valid(): control.link_create( account, form.cleaned_data["site"], form.cleaned_data["profile"].strip(), ) return HttpResponseRedirect("/account/profile") else: form = forms.LinkCreate(account=account) args = { "form_title": account, "form": form, "cancel_url": "/account/profile", "form_subtitle": _("ADD_REQUIRED_SOCIAL_LINK"), "form_info": _("USER_PRIVECY_INFORMATION"), } return render_response(request, "site/form.html", args)
def borrower_rate(request, borrow_id): account = get_object_or_404(Account, user=request.user) borrow = get_object_or_404(Borrow, id=borrow_id) if account != borrow.borrower: raise PermissionDenied if request.method == "POST": form = forms.Rate(request.POST) if form.is_valid(): rating = form.cleaned_data["rating"] note = form.cleaned_data["note"].strip() control.borrower_rate(account, borrow, rating, note) return HttpResponseRedirect("/borrow/view/%s" % borrow.id) else: form = forms.Rate() form_title = u"%s %s" % (_("RATE"), borrow) args = { "form": form, "form_title": form_title, "cancel_url": "/borrow/view/%s" % borrow_id } return render_response(request, "site/form.html", args)
def listing(request, **kwargs): team_link = kwargs.get("team_link") account = get_object_or_404(Account, user=request.user) columns = [ _("RESPONSIBLE"), _("POSTALCODE"), _("CITY"), _("STREET"), _("ACTIVE"), ] if team_link: team = team_control.get_or_404(team_link) assert_member(account, team) def station2entrie(s): return { "labels" : [ s.responsible, s.postalcode, s.city, s.street, s.active ], "url" : "/%s/station/view/%s" % (team.link, s.id) } stations = Station.objects.filter(team=team) entries = map(station2entrie, stations) args = { "page_title" : _("STATIONS"), "list_data" : { "columns" : columns, "entries" : entries } } return rtr(team, "stations", request, "site/list.html", args) else: def station2entrie(s): return { "labels" : [ s.responsible, s.postalcode, s.city, s.street, s.active ], "url" : "/station/view/%s" % s.id } stations = Station.objects.filter(responsible=account) entries = map(station2entrie, stations) args = { "page_title" : _("STATIONS"), "list_data" : { "columns" : columns, "entries" : entries } } return render_response(request, "site/list.html", args)
def comment(request, **kwargs): borrow_id = kwargs["borrow_id"] team_link = kwargs.get("team_link") account = get_object_or_404(Account, user=request.user) team = team_link and team_control.get_or_404(team_link) or None borrow = get_object_or_404(Borrow, id=borrow_id) url_prefix = team and "/%s" % team.link or "" url = "%s/borrow/view/%s" % (url_prefix, borrow_id) if request.method == "POST": form = forms.Comment(request.POST) if form.is_valid(): control.comment(account, borrow, form.cleaned_data["note"].strip() ) return HttpResponseRedirect(url) else: form = forms.Comment() args = { "form" : form, "form_title" : _("BORROW_COMMENT"), "cancel_url" : url } if team: return rtr(team, "borrows", request, "site/form.html", args) return render_response(request, "site/form.html", args)
def view(request, **kwargs): tab = kwargs["tab"] station_id = kwargs["station_id"] team_link = kwargs.get("team_link") account = get_object_or_404(Account, user=request.user) team = team_link and team_control.get_or_404(team_link) or None if team: assert_member(account, team) station = get_object_or_404(Station, id=station_id, team=team) else: station = get_object_or_404(Station, id=station_id, responsible=account) bikes, borrows = _load_view_data(station, tab) data = borrow_control.to_list_data(borrows, team_link=True, columns=tab) template_args = { "bike_rows" : list(chunks(bikes, 2)), "station" : station, "list_data" : data, "page_title" : _VIEW[tab]["page_title"], "tabs" : _tabs(station, team, tab), } template = _VIEW[tab]["template"] if team: return rtr(team, "stations", request, template, template_args) return render_response(request, template, template_args)
def remove(request, **kwargs): team_link = kwargs.get("team_link") picture_id = kwargs["picture_id"] team = team_link and team_control.get_or_404(team_link) or None picture = get_object_or_404(Picture, id=picture_id) gallery = picture.gallery account = get_object_or_404(Account, user=request.user) prefix = team_link and "/%s" % team_link or "" url = "%s/gallery/list/%s" % (prefix, gallery.id) if request.method == "POST": form = Form(request.POST) if form.is_valid(): control.remove(account, picture) return HttpResponseRedirect(url) else: form = Form() args = { "form" : form, "form_title" : _("REMOVE_GALLERY_PICTURE"), "cancel_url" : url } if team: return rtr(team, None, request, "site/form.html", args) else: return render_response(request, "site/form.html", args)
def terms(request): return render_response(request, 'site/terms.html', {})
def donate(request): return render_response(request, 'site/donate.html', {})
def created(request, team_link): account = get_object_or_404(Account, user=request.user) team = get_object_or_404(Team, link=team_link) return render_response(request, "team/created.html", { "team" : team })
def google_site_verification(request): return render_response(request, 'google437fc9f7c48a6697.html', {})
def created(request, team_link): account = get_object_or_404(Account, user=request.user) team = get_object_or_404(Team, link=team_link) return render_response(request, "team/created.html", {"team": team})