def profile(userid): user = db.User(id=userid) campaigns = Campaign.find_owned(owner=user.id) donations = Donation.find_owned(owner=user.id) response.meta.title = "HFunding | " + user.first_name + " " + \ user.last_name + " profile" return dict(user=user, campaigns=campaigns, donations=donations)
def new(): def set_owner(form): form.vars.owner = auth.user.id form = Campaign.form(onvalidation=set_owner) if form.accepted: redirect(url('main.profile', auth.user.id)) return locals()
def detail(cid): def validate_cost(form): form.params.campaign = campaign.id if form.params.amount > (campaign.pledged() - campaign.spended()): form.errors.amount = \ "The amount inserted is bigger than the amount pledged." campaign = Campaign.get(cid) cost_form = Cost.form(onvalidation=validate_cost) if cost_form.accepted: redirect(url('campaigns.detail', cid)) return dict(campaign=campaign, cost_form=cost_form, graph=graph_data)
def add(campaign): def set_form(form): form.params.user = auth.user.id form.params.campaign = record.id message = None record = Campaign.get(campaign) if not record: message = "Bad campaign id" form = Donation.form(onvalidation=set_form) if form.accepted: redirect(url('campaigns.detail', record.id)) return dict(msg=message, form=form, campaign=record)
def add(campaign): def validate(form): if form.params.amount > record.pledged(): form.errors.amount = "" message = None record = Campaign.get(id=campaign, user=auth.user.id) if not record: message = "Bad campaign id" form = Cost.form(onvalidation=validate) form.params.campaign = record.id if form.accepted: redirect(url('campaigns.detail', record.id)) return dict(msg=message, form=form)
def owned(): campaigns = Campaign.find_owned() return locals()
def all(): campaigns = Campaign.where(lambda c: c.start <= request.now).select( orderby=~Campaign.start, paginate=(1, 20)) return dict(campaigns=campaigns, showing='all')
def discover(): campaigns = Campaign.where(lambda c: (c.start <= request.now) & (c.closed == False)).select( orderby=~Campaign.start, paginate=(1, 20)) return dict(campaigns=campaigns, showing='discover')