def edit_page(request, vanity_url): if request.user.is_authenticated(): page = Page.objects.get(vanity_url=vanity_url) connections = page.connections if request.method == 'POST': form = PageForm(request.POST, instance=page) if form.is_valid(): page.location = form.cleaned_data['location'] page.type = form.cleaned_data['type'] page.name = form.cleaned_data['name'] page.tags = form.cleaned_data['tags'] page.description = form.cleaned_data['description'] page.homepage = form.cleaned_data['homepage'] page.date_established = form.cleaned_data['date_established'] page.save() else: form = PageForm(instance=page) # Setup for the stories story_form = StoryForm() story_types = Story.types() # Grab all of the existing stories and create a hash of 'title' => Form for editing. stories = Story.objects.filter(page=page, deleted=False) story_forms = [] for story in stories: story_forms.append(StoryForm(instance=story)) return locals()
def edit_story(request, type, id): story = Story.objects.get(id=id) form = StoryForm(request.POST, instance=story) if form.is_valid(): story = update_story(form, story) story.save() return JsonResponse({ 'message': "Story was saved successfully" }, 200) else: return JsonResponse(form.errors, status=400)
def edit_story(request, type, id): story = Story.objects.get(id=id) form = StoryForm(request.POST, instance=story) if form.is_valid(): story = update_story(form, story) story.save() return JsonResponse({'message': "Story was saved successfully"}, 200) else: return JsonResponse(form.errors, status=400)
def new_story(request, story_type, vanity_url): form = StoryForm(request.POST) story_user = request.user story_page = Page.objects.get(vanity_url=vanity_url) if form.is_valid(): story = Story.objects.create(page=story_page, user=story_user, published=True) story = update_story(form, story) story.save() story_form = StoryForm(instance=story) # Return the edit_story template back to the AJAX call # so we can insert it into the DOM return render_to_response('pages/edit_story.html', { 'story_form': story_form, 'page': story_page }, context_instance=RequestContext(request)) else: return JsonResponse(form.errors, status=400)