def project_edit(request, uuid): project = get_object_or_404(Project, uuid=uuid) if not request.user.has_perm('core.change_project', project): return HttpResponseForbidden( custom_error_page(request, '403.html', { user: request.user, 'msg': "edit this project" })) if request.method == "POST": # If the form has been submitted... form = ProjectForm(data=request.POST, instance=project) # A form bound to the POST data if form.is_valid(): # All validation rules pass form.save() # Process the data in form.cleaned_data # ... return HttpResponseRedirect( reverse('core.views.project', args=(uuid, ))) # Redirect after POST else: form = ProjectForm(instance=project) # An unbound form return render_to_response("core/project_edit.html", { 'form': form, 'project': project }, context_instance=RequestContext(request))
def project_new(request): if request.method == "POST": # If the form has been submitted form = ProjectForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass project = form.save() project.set_owner(request.user) # Process the data in form.cleaned_data return HttpResponseRedirect( reverse('project', args=(project.uuid, ))) # Redirect after POST else: form = ProjectForm() # An unbound form return render_to_response("core/project_new.html", {'form': form}, context_instance=RequestContext(request))
def edit_project(): form = ProjectForm(request.form) if form.validate(): name = request.form["name"] id = request.form["id"] db.query(Project).filter(Project.id == id).update({"name": name}) db.commit() return redirect("admin")
def admin(): first = request.args.get("first-run") is not None newproject = NewProjectForm() projects = [ProjectForm(project=proj) for proj in Project.query.all()] unspecified = Donation.query.filter(Donation.project == None).all() donations = Donation.query.order_by( Donation.created.desc()).limit(50).all() return render_template( "admin.html", first=first, projects=projects, newproject=newproject, donations=donations, currency=currency, one_times=lambda p: sum( [d.amount for d in p.donations if d.type == DonationType.one_time]), recurring=lambda p: sum([ d.amount for d in p.donations if d.type == DonationType.monthly and d.active ]), recurring_ever=lambda p: sum([ d.amount * d.payments for d in p.donations if d.type == DonationType.monthly ]), unspecified_one_times=sum([ d.amount for d in unspecified if d.type == DonationType.one_time ]), unspecified_recurring=sum([ d.amount for d in unspecified if d.type == DonationType.monthly and d.active ]), unspecified_recurring_ever=sum([ d.amount * d.payments for d in unspecified if d.type == DonationType.monthly ]), total_one_time=sum([ d.amount for d in Donation.query.filter( Donation.type == DonationType.one_time) ]), total_recurring=sum([ d.amount for d in Donation.query.filter( Donation.type == DonationType.monthly, Donation.active == True) ]), total_recurring_ever=sum([ d.amount * d.payments for d in Donation.query.filter( Donation.type == DonationType.monthly) ]), uptodate=check_update(), )
def addProject(request): ''' The view manages Customer's project and its settings ''' if request.method == 'POST': form = ProjectForm(request.POST) if form.is_valid(): form = form.save(commit=False) form.owner = request.user form.save() return redirect("home") else: print(form.errors) print(form.non_field_errors) project_form = ProjectForm # project_form = ProjectForm(initial={'owner':request.user}) return render(request, 'project.html', {'form': project_form})