def admin_entry_edit(request, entry_id=None): entry = None entry_form = bforms.EntryForm(initial={'created_by': request.user.id}) if entry_id: entry = get_object_or_404(BlogEntry, pk=entry_id) entry_form = bforms.EntryForm(instance=entry, initial={'text': entry.text.raw}) if request.POST: entry_form = bforms.EntryForm(request.POST, instance=entry) if entry_form.is_valid(): new_entry = entry_form.save(commit=False) if "publish" in request.POST: new_entry.is_published = True if "page" in request.POST: new_entry.is_page = True new_entry.save() tag_list = entry_form.cleaned_data['tags'] for tag in tag_list: tag_, created = Tag.objects.get_or_create(name=tag.strip()) tag_.save() new_entry.tags.add(tag_) if new_entry.is_published: return redirect(new_entry) return redirect( reverse('blogango_admin_entry_edit', args=[new_entry.id]) + '?done') return render('blogango/admin/edit_entry.html', request, { 'entry_form': entry_form, 'entry': entry })
def create_entry(request): if request.method == 'GET': create = bforms.EntryForm() elif request.method == 'POST': create = bforms.EntryForm(request.POST) if create.is_valid(): if request.POST.has_key('save'): publish = False elif request.POST.has_key('post'): publish = True entry = BlogEntry(created_by=request.user, text=create.cleaned_data['text'], title=create.cleaned_data['title'], slug=create.cleaned_data['slug'], is_page=create.cleaned_data['is_page'], is_published=publish, is_rte=create.cleaned_data['is_rte']) entry.save() tags = create.cleaned_data['tags'] tag_list = tags.split() for tag in tag_list: tag_, created = Tag.objects.get_or_create(tag_txt=tag.strip()) tag_.save() entry.tag_set.add(tag_) if request.POST.has_key('save'): return HttpResponseRedirect('.') elif request.POST.has_key('post'): return HttpResponseRedirect(entry.get_absolute_url()) payload = { 'create_form': create, } return render('blogango/create.html', request, payload)
def admin_entry_edit(request, entry_id=None): entry = None entry_form = bforms.EntryForm(initial={ 'created_by': request.user.id, 'publish_date': datetime.now() }) if entry_id: entry = get_object_or_404(BlogEntry, pk=entry_id) entry_form = bforms.EntryForm(instance=entry, initial={'text': entry.text.raw}) if request.POST: entry_form = bforms.EntryForm(request.POST, instance=entry) if entry_form.is_valid(): new_entry = entry_form.save(commit=False) if "publish" in request.POST: new_entry.is_published = True if "page" in request.POST: new_entry.is_page = True new_entry.save() tag_list = entry_form.cleaned_data['tags'] new_entry.tags.set(*tag_list) if new_entry.is_published: return redirect(new_entry) return redirect( reverse('blogango_admin_entry_edit', args=[new_entry.id]) + '?done') tags_json = json.dumps([each.name for each in Tag.objects.all()]) return render('blogango/admin/edit_entry.html', request, { 'entry_form': entry_form, 'entry': entry, 'tags_json': tags_json })
def edit_entry(request, entry_id): if request.method == 'GET': entry = BlogEntry.objects.filter(id=entry_id).values()[0] entry_ = BlogEntry.objects.get(id=entry_id) tags = Tag.objects.filter(tag_for=entry_) tags = [tag.tag_txt for tag in tags] tag_ = " ".join(tags) entry['tags'] = tag_ create = bforms.EntryForm(entry) elif request.method == 'POST': create = bforms.EntryForm(request.POST) if create.is_valid(): entry = BlogEntry.objects.get(id=entry_id) entry.text = create.cleaned_data['text'] entry.title = create.cleaned_data['title'] entry.slug = create.cleaned_data['slug'] entry.is_page = create.cleaned_data['is_page'] entry.comments_allowed = create.cleaned_data['comments_allowed'] if request.POST.has_key('save'): publish = False elif request.POST.has_key('post'): publish = True entry.is_published = publish entry.save() tags = Tag.objects.filter(tag_for=entry) for tag in tags: entry.tag_set.remove(tag) tags_data = create.cleaned_data['tags'] tag_list = tags_data.split(' ') for tag in tag_list: tag_, created = Tag.objects.get_or_create(tag_txt=tag.strip()) tag_.save() entry.tag_set.add(tag_) return HttpResponseRedirect(entry.get_absolute_url()) payload = { 'create_form': create, } return render('blogango/create.html', request, payload)