Ejemplo n.º 1
0
def edit(request, id, template_name="story/edit.html"):
    story = get_object_or_404(Story, pk=id)
    
    if story.creator == request.user:
        if request.POST:
            create_activity_item("edited_story", request.user, story)
            # save
            
            form = StoryEditForm(request.POST, instance=story)

            if form.is_valid():
                form.save(request.user)
                return HttpResponse(status=200, content="<div class='ajax-message'>Successfully stored Changes</div>")
            else:
                return HttpResponse(status=400, content="Error")
        else:
            return render_to_response(template_name, {
                "story": story,
                "post_form": StoryPostForm(),
                "video_form": StoryVideoForm(),
                "gpx_upload_form": GPXUploadForm(request.user),
                "story_edit_form": StoryEditForm(instance=story),
            }, context_instance=RequestContext(request))
    else:
        return render_to_response("error.html", {
            "title": _("You are not authorized"),
            "text": _("Only the creator of the Story can edit it")
        }, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def publish(request, id, template_name="story/publish.html"):
    story = get_object_or_404(Story, id=id)
    if story.creator == request.user:
        if request.method == "POST":
            form = StoryEditForm(request.POST, instance=story)
            if form.is_valid():
                story = form.save(request.user)
                story.status = story.STATUS_PUBLIC
                story.save()
            
                return render_to_response(template_name, {
                    "next": request.path,
                    "story": story,
                    "post_form": StoryPostForm(),
                    "video_form": StoryVideoForm(),
                    "gpx_upload_form": GPXUploadForm(request.user),
                    "story_edit_form": StoryEditForm(instance=story),
                }, context_instance=RequestContext(request))
        return render_to_response(template_name, {
            "next": request.path,
            "story": story,
        }, context_instance=RequestContext(request))
    else:
        return render_to_response("error.html", {
            "title": _("You are not authorized"),
            "text": _("Only the creator of the Story can edit it")
        }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def story_edit(request, id):
    """ Edit a Story """
    messages.success(request, "Your Story was edited!")

    story = get_object_or_404(Story, id=id)
    if request.method == 'POST':
        form = StoryEditForm(request.POST, instance=story)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(
                reverse('story_detail', kwargs={'id': id}))
    else:
        form = StoryEditForm()

    return render_to_response('stories/story_edit.html', {
        'form':form,
        'object':story
    }, context_instance=RequestContext(request))