def create_project1(request): graph = request.facebook.graph user = graph.get_object("me") uid = user['id'] if request.method == 'POST': # If the form has been submitted... form = SubmitForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass project = projects.objects.create( pname = form.cleaned_data['pname'], desc_short = '0', desc_long = form.cleaned_data['desc_long'], pcreator = uid, pdate = '1990-04-03', image_url = '0', help_text = '0', membership = '0', newtons = '0', ) project_max = projects.objects.order_by('-pid')[0] project_max_id = project_max.pid admin = project_admins.objects.create( uid = uid, pid = int(project_max_id) ) membership = memberships.objects.create( uid = uid, pid = int(project_max_id) ) return http.HttpResponseRedirect('create_project2') # Redirect after POST else: form = SubmitForm(request.POST) # An unbound form errors = form.errors return render_to_response('citsci/create_project1.html', { 'form': form, 'errors': errors, }) else: form = SubmitForm() # An unbound form return render_to_response('citsci/create_project1.html', { 'form': form, })
def edit(request, pid): if request.method == 'POST': # If the form has been submitted... form = SubmitForm(request.POST) # A form bound to the POST data creator = projects.objects.get(pid=pid).pcreator date = projects.objects.get(pid=pid).pdate if form.is_valid(): # All validation rules pass project = projects(pid=pid , pname = form.cleaned_data['pname'] , desc_long = form.cleaned_data['desc_long'] , pcreator = creator , pdate = date , image_url = '0' , help_text = '0' ) project.save() return http.HttpResponseRedirect('http://sm.rutgers.edu/citizenscience/edit2/' + pid) # Redirect after POST else: project = projects.objects.get(pid=pid) form = SubmitForm(initial={'pname': project.pname, 'desc_long': project.desc_long}) return render_to_response('citsci/edit.html', {'form': form, 'project': project, 'pid': pid})