Пример #1
0
def create_story(request, base62_id):
    mid = base62.to_decimal(base62_id)
    meta = get_object_or_404(QuestionMeta, id=mid)
    if request.POST:
        story_form = StoryForm(request.POST, owner=request.user, meta=meta)
        if story_form.is_valid():
            story = story_form.save(publish="publish" in request.POST)
            return HttpResponseRedirect(story.get_absolute_url())
    else:
        story_form = StoryForm(owner=request.user, meta=meta, initial={"question": request.GET.get("qid")})
    return render(request, "story/create_story.html", {"story_form": story_form})
Пример #2
0
def update_story(request, base62_id):
    story = get_object_or_404(Story, id=base62.to_decimal(base62_id), owner=request.user)
    if request.method == "POST":
        story_form = StoryForm(request.POST, instance=story, owner=request.user, meta=story.question_meta)
        if story_form.is_valid():
            story_form.save()
            messages.success(request, _("Your story updated"))
            return HttpResponseRedirect(story.get_absolute_url())
        else:
            return render(request, "story/create_story.html", {"story_form": story_form})
    story_form = StoryForm(instance=story, owner=request.user, meta=story.question_meta)
    return render(request, "story/create_story.html", {"story_form": story_form})
Пример #3
0
def create_story(request, base62_id):
    mid = base62.to_decimal(base62_id)
    meta = get_object_or_404(QuestionMeta, id=mid)
    if request.POST:
        story_form = StoryForm(request.POST, owner=request.user, meta=meta)
        if story_form.is_valid():
            story = story_form.save()
            return HttpResponseRedirect(story.get_absolute_url())
    else:
        story_form = StoryForm(owner=request.user, meta=meta, initial={
            'question': request.GET.get('qid')})
    return render(request, 'story/create_story.html',
                  {'story_form': story_form})
Пример #4
0
def create_story(request, base62_id):
    mid = base62.to_decimal(base62_id)
    meta = get_object_or_404(QuestionMeta, id=mid)
    if request.POST:
        story_form = StoryForm(request.POST, owner=request.user, meta=meta)
        if story_form.is_valid():
            story = story_form.save()
            return HttpResponseRedirect(story.get_absolute_url())
    else:
        story_form = StoryForm(owner=request.user,
                               meta=meta,
                               initial={'question': request.GET.get('qid')})
    return render(request, 'story/create_story.html',
                  {'story_form': story_form})
Пример #5
0
def update_story(request, base62_id):
    story = get_object_or_404(Story,
                              id=base62.to_decimal(base62_id),
                              owner=request.user)
    if request.method == "POST":
        story_form = StoryForm(request.POST,
                               instance=story,
                               owner=request.user)
        if story_form.is_valid():
            story_form.save()
            messages.success(request, _('Your story updated'))
            return HttpResponseRedirect(story.get_absolute_url())
        else:
            return render(request, 'story/create_story.html',
                          {'story_form': story_form})
    story_form = StoryForm(instance=story, owner=request.user)
    return render(request, 'story/create_story.html',
                  {'story_form': story_form})