def edit_page(request, id): langs = [] for lang in settings.LANGUAGES: langs.append({ 'code': lang[0], 'title': _(lang[1]) }) page = get_object_or_404(Page, id=id) PageForm = get_page_form(page.parent_id) if request.method == 'POST': page_form = PageForm(request.POST, prefix='page_form', instance=page) if page_form.is_valid(): page = page_form.save(commit=False) if not request.user.has_perm('professionals_pages.public_page'): page.public = False page.save() return redirect('professionals_pages:administration:pages_list') else: page_form = PageForm(prefix='page_form', instance=page) return render(request, 'professionals_pages/administration/edit_page.html', { 'page': page, 'langs': langs, 'page_form': page_form, })
def create_page(request, parent=None): if parent: parent = get_object_or_404(Page, id=parent) PageForm = get_page_form(parent) if request.method == 'POST': page_form = PageForm(request.POST, prefix='page_form') if page_form.is_valid(): page = page_form.save(commit=False) if parent: page.parent = parent if not request.user.has_perm('professionals_pages.public_page'): page.public = False page.save() if parent: # наследование прав от родителя copy_perms_for_groups(parent, page) return redirect('professionals_pages:administration:create_page_content', page_id=page.id) else: page_form = PageForm(prefix='page_form') return render(request, 'professionals_pages/administration/create_page.html', { 'parent': parent, 'page_form': page_form, })
def create_page(request, code, parent=None): library = get_object_or_404(Library, code=code) cbs = get_cbs(library) if not check_owning(request.user, cbs): return HttpResponse(u"У Вас нет прав на создание страниц в этой ЦБС") if parent: parent = get_object_or_404(Page, id=parent) PageForm = get_page_form(library, parent) if request.method == "POST": page_form = PageForm(request.POST, prefix="page_form") if page_form.is_valid(): page = page_form.save(commit=False) if parent: page.parent = parent if not request.user.has_perm("participants_pages.public_page"): page.public = False page.library = library page.save() return redirect("participants_pages:administration:create_page_content", page_id=page.id, code=code) else: page_form = PageForm(prefix="page_form") return render( request, "participants_pages/administration/create_page.html", {"parent": parent, "page_form": page_form, "library": library}, )
def edit_page(request, code, id): library = get_object_or_404(Library, code=code) cbs = get_cbs(library) if not check_owning(request.user, cbs): return HttpResponse(u"У Вас нет прав на редактирование страницы в этой ЦБС") langs = [] for lang in settings.LANGUAGES: langs.append({"code": lang[0], "title": _(lang[1])}) page = get_object_or_404(Page, id=id) PageForm = get_page_form(library, page.parent_id) if request.method == "POST": page_form = PageForm(request.POST, prefix="page_form", instance=page) page_form.is_valid() if page_form.is_valid(): page = page_form.save(commit=False) if not request.user.has_perm("participants_pages.public_page"): page.public = False page.save() return redirect("participants_pages:administration:pages_list", code=code) else: page_form = PageForm(prefix="page_form", instance=page) return render( request, "participants_pages/administration/edit_page.html", {"page": page, "langs": langs, "page_form": page_form, "library": library}, )
def create_page(request, library_code, parent=None, managed_libraries=[]): library = org_utils.get_library(library_code, managed_libraries) if not library: return HttpResponseForbidden( u'Вы должны быть сотрудником этой организации') if parent: parent = get_object_or_404(Page, id=parent, library=library) PageForm = get_page_form(library, parent) if request.method == 'POST': page_form = PageForm(request.POST, prefix='page_form') if page_form.is_valid(): page = page_form.save(commit=False) if parent: page.parent = parent if not request.user.has_perm('participant_pages.public_page'): page.public = False page.library = library page.save() if parent: # наследование прав от родителя copy_perms_for_groups(parent, page) else: try: users_group = Group.objects.get(name='users') assign_permission([users_group], [page], VIEW_PAGE_PERMISSION) except Group.DoesNotExist: pass return redirect( 'participant_pages:administration:create_page_content', library_code=library_code, page_id=page.id) else: page_form = PageForm(prefix='page_form') return render(request, 'participant_pages/administration/create_page.html', { 'library': library, 'parent': parent, 'page_form': page_form, })
def create_page(request, library_code, parent=None, managed_libraries=[]): library = org_utils.get_library(library_code, managed_libraries) if not library: return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации') if parent: parent = get_object_or_404(Page, id=parent, library=library) PageForm = get_page_form(library, parent) if request.method == 'POST': page_form = PageForm(request.POST, prefix='page_form') if page_form.is_valid(): page = page_form.save(commit=False) if parent: page.parent = parent if not request.user.has_perm('participant_pages.public_page'): page.public = False page.library = library page.save() if parent: # наследование прав от родителя copy_perms_for_groups(parent, page) else: try: users_group = Group.objects.get(name='users') assign_permission([users_group], [page], VIEW_PAGE_PERMISSION) except Group.DoesNotExist: pass return redirect('participant_pages:administration:create_page_content', library_code=library_code, page_id=page.id) else: page_form = PageForm(prefix='page_form') return render(request, 'participant_pages/administration/create_page.html', { 'library': library, 'parent': parent, 'page_form': page_form, })
def edit_page(request, library_code, id, managed_libraries=[]): library = org_utils.get_library(library_code, managed_libraries) if not library: return HttpResponseForbidden(u'Вы должны быть сотрудником этой организации') langs = [] for lang in settings.LANGUAGES: langs.append({ 'code': lang[0], 'title': _(lang[1]) }) page = get_object_or_404(Page, id=id) PageForm = get_page_form(page.parent_id) if request.method == 'POST': page_form = PageForm(request.POST, prefix='page_form', instance=page) if page_form.is_valid(): page = page_form.save(commit=False) if not request.user.has_perm('participant_pages.public_page'): page.public = False page.save() if page.parent_id: return redirect('participant_pages:administration:pages_list', library_code=library_code, parent=page.parent_id) return redirect('participant_pages:administration:pages_list', library_code=library_code) else: page_form = PageForm(prefix='page_form', instance=page) return render(request, 'participant_pages/administration/edit_page.html', { 'library': library, 'page': page, 'langs': langs, 'page_form': page_form })
def edit_page(request, library_code, id, managed_libraries=[]): library = org_utils.get_library(library_code, managed_libraries) if not library: return HttpResponseForbidden( u'Вы должны быть сотрудником этой организации') langs = [] for lang in settings.LANGUAGES: langs.append({'code': lang[0], 'title': _(lang[1])}) page = get_object_or_404(Page, id=id) PageForm = get_page_form(page.parent_id) if request.method == 'POST': page_form = PageForm(request.POST, prefix='page_form', instance=page) if page_form.is_valid(): page = page_form.save(commit=False) if not request.user.has_perm('participant_pages.public_page'): page.public = False page.save() if page.parent_id: return redirect('participant_pages:administration:pages_list', library_code=library_code, parent=page.parent_id) return redirect('participant_pages:administration:pages_list', library_code=library_code) else: page_form = PageForm(prefix='page_form', instance=page) return render(request, 'participant_pages/administration/edit_page.html', { 'library': library, 'page': page, 'langs': langs, 'page_form': page_form })