def change_view(self, request, object_id, extra_context=None): extra_context = extra_context or {} page = get_object_or_404(Page, id=object_id) parent = page.get_parent() parent = parent.id if parent else '' if request.POST: template = request.POST.get('template', page.template) content_form = stoat_forms.get_content_form(template, request.POST) else: initial = {} for pc in page.pagecontent_set.all(): # Ugly hack to store booleans as text. if pc.typ == 'bool': try: val = True if int(pc.content) else False except ValueError: val = True else: val = pc.get_content() initial['content_' + clean_field_title(pc.title)] = val content_form = stoat_forms.get_content_form(page.template, initial=initial) extra_context.update({ 'content_form': content_form, 'media': content_form.media + self.media, 'parent': parent, }) return self._django_change_view(request, object_id, extra_context=extra_context)
def change_view(self, request, object_id, extra_context=None): extra_context = extra_context or {} page = get_object_or_404(Page, id=object_id) parent = page.get_parent() parent = parent.id if parent else '' if request.POST: template = request.POST.get('template', page.template) content_form = stoat_forms.get_content_form(template, request.POST) else: initial = {} for pc in page.pagecontent_set.all(): # Ugly hack to store booleans as text. if pc.typ == 'bool': val = True if int(pc.content) else False else: val = pc.content initial['content_' + clean_field_title(pc.title)] = val content_form = stoat_forms.get_content_form(page.template, initial=initial) extra_context.update({ 'content_form': content_form, 'media': content_form.media + self.media, 'parent': parent, }) return self._django_change_view(request, object_id, extra_context=extra_context)
def edit_page_content(request, page_id, lang): lang_form = LanguageForm({'lang': lang}) if not lang_form.is_valid(): return HttpResponse(_(u'Language is not registered in system.') + _(u" Language code: ") + lang) page = get_object_or_404(Page, id=page_id) try: content = Content.objects.get(page=page_id, lang=lang) except Content.DoesNotExist: content = Content(page=page, lang=lang) ContentForm = get_content_form(('page', 'lang')) if request.method == 'POST': content_form = ContentForm(request.POST, prefix='content_form', instance=content) if content_form.is_valid(): content = content_form.save(commit=False) content.page = page content.save() save = request.POST.get('save', u'save_edit') if save == u'save': return redirect('professionals_pages:administration:edit_page', id=page_id) else: content_form = ContentForm(prefix='content_form', instance=content) return render(request, 'professionals_pages/administration/edit_page_content.html', { 'page': page, 'content': content, 'content_form': content_form, })
def create_page_content(request, code, page_id): library = get_object_or_404(Library, code=code) cbs = get_cbs(library) if not check_owning(request.user, cbs): return HttpResponse(u"У Вас нет прав на создание страницы в этой ЦБС") page = get_object_or_404(Page, id=page_id) ContentForm = get_content_form(("page",)) if request.method == "POST": content_form = ContentForm(request.POST, prefix="content_form") if content_form.is_valid(): content = content_form.save(commit=False) content.page = page content.save() save = request.POST.get("save", u"save_edit") if save == u"save": return redirect("participants_pages:administration:edit_page", id=page_id, code=code) else: return redirect( "participants_pages:administration:edit_page_content", page_id=page_id, lang=content.lang ) else: content_form = ContentForm(prefix="content_form") return render( request, "participants_pages/administration/create_page_content.html", {"page": page, "content_form": content_form, "library": library}, )
def edit_page_content(request, library_code, page_id, lang, managed_libraries=[]): library = org_utils.get_library(library_code, managed_libraries) if not library: return HttpResponseForbidden( u'Вы должны быть сотрудником этой организации') lang_form = LanguageForm({'lang': lang}) if not lang_form.is_valid(): return HttpResponse( _(u'Language is not registered in system.') + _(u" Language code: ") + lang) page = get_object_or_404(Page, id=page_id) try: content = Content.objects.get(page=page_id, lang=lang) except Content.DoesNotExist: content = Content(page=page, lang=lang) ContentForm = get_content_form(('page', 'lang')) if request.method == 'POST': content_form = ContentForm(request.POST, prefix='content_form', instance=content) if content_form.is_valid(): content = content_form.save(commit=False) content.page = page content.save() save = request.POST.get('save', u'save_edit') if save == u'save': return redirect('participant_pages:administration:edit_page', library_code=library_code, id=page_id) else: content_form = ContentForm(prefix='content_form', instance=content) return render( request, 'participant_pages/administration/edit_page_content.html', { 'library': library, 'page': page, 'content': content, 'content_form': content_form, 'content_type': 'participant_pages', 'content_id': str(library.id) + '_' + page.url_path.replace('/', '_') })
def edit_page_content(request, library_code, page_id, lang, managed_libraries=[]): library = org_utils.get_library(library_code, managed_libraries) if not library: return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации') lang_form = LanguageForm({'lang': lang}) if not lang_form.is_valid(): return HttpResponse(_(u'Language is not registered in system.') + _(u" Language code: ") + lang) page = get_object_or_404(Page, id=page_id) try: content = Content.objects.get(page=page_id, lang=lang) except Content.DoesNotExist: content = Content(page=page, lang=lang) ContentForm = get_content_form(('page', 'lang')) if request.method == 'POST': content_form = ContentForm(request.POST, prefix='content_form', instance=content) if content_form.is_valid(): content = content_form.save(commit=False) content.page = page content.save() save = request.POST.get('save', u'save_edit') if save == u'save': return redirect('participant_pages:administration:edit_page', library_code=library_code, id=page_id) else: content_form = ContentForm(prefix='content_form', instance=content) return render(request, 'participant_pages/administration/edit_page_content.html', { 'library': library, 'page': page, 'content': content, 'content_form': content_form, 'content_type': 'participant_pages', 'content_id': str(library.id) + '_' + page.url_path.replace('/', '_') })
def edit_page_content(request, code, page_id, lang): library = get_object_or_404(Library, code=code) cbs = get_cbs(library) if not check_owning(request.user, cbs): return HttpResponse(u"У Вас нет прав на редактирование страницы в этой ЦБС") lang_form = LanguageForm({"lang": lang}) if not lang_form.is_valid(): return HttpResponse(_(u"Language is not registered in system.") + _(u" Language code: ") + lang) page = get_object_or_404(Page, id=page_id) try: content = Content.objects.get(page=page_id, lang=lang) except Content.DoesNotExist: content = Content(page=page, lang=lang) ContentForm = get_content_form(("page", "lang")) if request.method == "POST": content_form = ContentForm(request.POST, prefix="content_form", instance=content) if content_form.is_valid(): content = content_form.save(commit=False) content.page = page content.save() save = request.POST.get("save", u"save_edit") if save == u"save": return redirect("participants_pages:administration:edit_page", id=page_id, code=code) else: content_form = ContentForm(prefix="content_form", instance=content) return render( request, "participants_pages/administration/edit_page_content.html", {"page": page, "content": content, "content_form": content_form, "library": library}, )