Exemple #1
0
def edit(request, id):
    tags = ''
    if id:
        twitternew = get_object_or_404(Twitternew, pk=id)
        for tag in twitternew.get_tags():
            tags = u'{0} {1}'.format(tags, tag.tag)
        tags = tags.strip()
    else:
        twitternew = Twitternew(create_user=request.user)

    if request.POST:
        form = TwitternewForm(request.POST, instance=twitternew)
        if form.is_valid():
            form.save()
            return redirect('/twitternews/')
    else:
        form = TwitternewForm(instance=twitternew, initial={'tags': tags})
    return render(request, 'twitternews/edit.html', {'form': form})
Exemple #2
0
def write(request):
    if request.method == 'POST':
        form = TwitternewForm(request.POST)
        if form.is_valid():
            twitternew = Twitternew()
            twitternew.create_user = request.user
            twitternew.title = form.cleaned_data.get('title')
            twitternew.content = form.cleaned_data.get('content')
            status = form.cleaned_data.get('status')
            if status in [Twitternew.PUBLISHED, Twitternew.DRAFT]:
                twitternew.status = form.cleaned_data.get('status')
            twitternew.save()
            tags = form.cleaned_data.get('tags')
            twitternew.create_tags(tags)
            return redirect('/twitternews/')
    else:
        form = TwitternewForm()
    return render(request, 'twitternews/write.html', {'form': form})