def edit_story(request, id): story = get_object_or_404(Story, id=id) if request.user == story.user or request.organization.admingroup in request.user.groups.all(): if request.method == 'POST': form = StoryForm(data=request.POST, instance=story) if form.is_valid(): story.save() return HttpResponseRedirect('/') else: form = StoryForm(instance=story) return render_to_response('forum/new_debate.html', {'form': form, 'object': story}, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/')
def edit_story(request, id): story = get_object_or_404(Story, id=id) if request.user == story.user or request.organization.admingroup in request.user.groups.all( ): if request.method == 'POST': form = StoryForm(data=request.POST, instance=story) if form.is_valid(): story.save() return HttpResponseRedirect('/') else: form = StoryForm(instance=story) return render_to_response('forum/new_debate.html', { 'form': form, 'object': story }, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/')
def new_story(request, id=None): """slug is the slug of the parent, may be null""" if request.method == 'POST': form = StoryForm(request.POST) if form.is_valid(): story = form.save(commit=False) story.user = request.user story.save() return HttpResponseRedirect('/') else: story = Story() initial = {} if id: parent = get_object_or_404(Story, id=id) story.parent = parent initial['title'] = "Re: " + parent.title initial['group'] = parent.group form = StoryForm(instance=story, initial=initial) return render_to_response('forum/new_debate.html', {'form': form}, context_instance=RequestContext(request))
def index(request): if request.method == "POST": print("Got form submission") form = StoryForm(request.POST) if form.is_valid: new_story = form.save() return redirect(index) else: print("Form has errors") response = 'Errors:' print("Else loop is called") form = StoryForm(request.POST) for key in form.errors.keys(): value = form.errors[key] errors = '' for error in value: errors = errors + error + ' ' response = response + ' ' + key + ': ' + errors return HttpResponse('<li class="error">' + response + '</li>') storyList = Story.objects.all().order_by('-date_posted') tourdateList = Tourdate.objects.all().order_by('-date') if storyList: print("storyList was generated by news.views") form = StoryForm() form2 = TourdateForm() context = { 'story': storyList, 'form': form, 'form2': form2, 'tourdate': tourdateList, } return render(request, 'news.html', context)
def addtourdate(request): if request.method == "POST": form = TourdateForm(request.POST) if form.is_valid: new_date = form.save() return redirect(index) else: print("Form has errors") response = 'Errors:' print("Else loop is called") form = StoryForm(request.POST) for key in form.errors.keys(): value = form.errors[key] errors = '' for error in value: errors = errors + error + ' ' response = response + ' ' + key + ': ' + errors return HttpResponse('<li class="error">' + response + '</li>') return redirect(index)