Ejemplo n.º 1
0
def new_story(request):
    if request.method == 'POST':
        storyform = StoryForm(data=request.POST)
        if storyform.is_valid():
            storyform.save(request.user)
            return redirect('author', request.user.username)
    return redirect(request.META.get('HTTP_REFERER'))
Ejemplo n.º 2
0
def new_story(request):
    if request.method == 'POST':
        storyform = StoryForm(data=request.POST)
        if storyform.is_valid():
            storyform.save(request.user)
            return redirect('author', request.user.username)
    return redirect(request.META.get('HTTP_REFERER'))
Ejemplo n.º 3
0
def mobile_post(request):
    logging.debug("Uploading Experience")
    story_form = StoryForm(request.user, request.POST, request.FILES)
    if story_form.is_valid():
        story = story_form.save(request.user)
        return render_to_response("story/story-post-reply.html", {
            "story":story,
        }, context_instance=RequestContext(request))
    else:
        return HTTPResponse(status=400, content="Error")
Ejemplo n.º 4
0
def add_story(request):
    if request.method == "POST":
        form = StoryForm(request.POST, request.FILES)

        if form.is_valid():
            story = form.save(commit=False)
            story.user = request.user
            story.save()

            if form.cleaned_data["images"]:
                for image in form.cleaned_data["images"]:
                    saved_image = StoryImage.objects.create(image=image)
                    story.images.add(saved_image)

            story.save()
            return render_to_response("success.html")
    else:
        form = StoryForm()
    return direct_to_template(request, "story/add.html", locals())
Ejemplo n.º 5
0
 def post(request, id=None):
     form = StoryForm(request.user, request.POST)
     if form.is_valid():
         if id:
             story = get_object_or_404(StoryModel, id=id)
             story.title = form.cleaned_data['title']
             story.text = form.cleaned_data['text']
             story.track = form.cleaned_data['track']
             story.event = form.cleaned_data['event']
             story.tags.set(*form.cleaned_data['tags'])
         else:
             story = form.save(commit=False)
             story.user = request.user
         story.save()
         form.save_m2m() if not id else None
         return HttpResponseRedirect(reverse('story:stories'))
     return render(request, 'story-editor.html', {'title': form['title'].value(), 'form': form})
Ejemplo n.º 6
0
 def get(request, id=None):
     story = get_object_or_404(StoryModel, id=id) if id else None
     if story and story.user != request.user and story.is_active:
         return HttpResponseForbidden()
     form = StoryForm(request.user, instance=story)
     return render(request, 'story-editor.html', {'title': story.title if story else 'New story', 'form': form})