Exemplo n.º 1
0
def get_admin_info(request, blog_id=None):
	"""Allows the user to provide admin login information for a blog.

	This is the view that a view decorated with the admin_info_required decorator
	redirects to if no admin login information can be found for a blog in
	the decorated view.

	Once the admin information is provided and verified, the user is returned
	to the page that they were previously tring to access.
	"""

	blog = get_object_or_404(Blog, pk=blog_id)
	next_page = request.GET.get(NEXT_PAGE_PARAM) or request.POST.get(NEXT_PAGE_PARAM)

	# Update the admin info and send the user to the page they originally wanted
	# to access, provided that the info provided is correct
	if request.POST:
		admin_form = AdminLoginInfoForm(blog, request.POST)
		if admin_form.is_valid():
			admin_form.update_admin_info()
			if not next_page:
				next_page = reverse('pressgang:list-blogs')
			return HttpResponseRedirect(next_page)
	else:
		admin_form = AdminLoginInfoForm(blog)

	page = Page(request)
	page.add_render_args({
		'admin_form': admin_form,
		'blog': blog,
		'next_page': next_page,
		'next_param': NEXT_PAGE_PARAM
	})
	return page.render('pressgang/core/admin_info.html')
Exemplo n.º 2
0
def add_blogs_options(request, blog_id=None):
	"""Allows the user to specify options for adding child blogs to a blog."""

	# If the blog cannot support child blogs, raise a 404
	blog = get_object_or_404(Blog, pk=blog_id)
	if not blog.version.is_multi:
		raise Http404

	# If valid options were provided, begin adding the child blogs
	if request.POST:
		add_form = BlogAdditionForm(request.POST)
		if add_form.is_valid():
			store_action(request, AddBlogsAction(blog,
				users=add_form.cleaned_data['users'],
				blog_type=add_form.cleaned_data['blog_type']))
			return HttpResponseRedirect(reverse("pressgang:add-blogs", kwargs={'blog_id': blog.pk}))
	else:
		add_form = BlogAdditionForm()

	page = Page(request)
	page.add_render_args({
		'blog': blog,
		'add_form': add_form
	})
	return page.render('pressgang/addblogs/options.html')
Exemplo n.º 3
0
def execute_action(request, **kwargs):
    """A page that executes an action.

	For this view to be called, there must be a cached Action-descended instance
	available as a session variable available through the 'current_action' key.
	"""

    action = retrieve_action(request)
    if not action:
        raise Http404

    page = Page(request)
    page.add_render_args({"action": action, "blog": action.blog})
    return page.render(action.execute_template)
Exemplo n.º 4
0
def confirm_lockdown(request, blog_id=None, lock=None):
	"""Allows the user to confirm whether or not they wish to lock down the blog."""

	# Prevent an ambiguous or redundant lockdown
	if lock is None:
		raise Http404
	blog = get_object_or_404(Blog, pk=blog_id)
	if LockdownStatus.objects.is_blog_locked(blog) == lock:
		raise Http404

	page = Page(request)
	page.add_render_args({
		'blog': blog,
		'lock': lock
	})
	return page.render('pressgang/lockdown/confirm.html')
Exemplo n.º 5
0
def install_options(request):
	"""Allows the user to provide options for installing a new blog."""

	if request.POST:
		install_form = InstallBlogForm(request.POST)
		if install_form.is_valid():
			store_action(request, install_form.create_installer())
			return HttpResponseRedirect(reverse('pressgang:install-blog', kwargs={'slug': install_form.cleaned_data['slug']}))
	else:
		install_form = InstallBlogForm()

	page = Page(request)
	page.add_render_args({
		'install_form': install_form
	})
	return page.render('pressgang/install/options.html')
Exemplo n.º 6
0
def list_blogs(request):
    """Displays all blogs on the site to a user."""

    # Get our sync result if we have one
    try:
        synced = request.session["synced"]
    except KeyError:
        synced = False
    else:
        del request.session["synced"]

    page = Page(request)
    page.add_render_args(
        {
            "blogs": Blog.objects.list_by_date(),
            "current_version": WordPressVersion.objects.current_version(),
            "synced": synced,
        }
    )
    return page.render("pressgang/manage/list.html")
Exemplo n.º 7
0
def reversion_options(request, blog_id=None):
	"""Allows the user to select which blog version to revert to."""

	# If the blog has no version snapshots, raise a 404
	blog = get_object_or_404(Blog, pk=blog_id)
	if not blog.has_version_snapshots:
		raise Http404

	# If a valid version was selected, begin the reversion process
	if request.POST:
		revert_form = ReversionForm(blog, request.POST)
		if revert_form.is_valid():
			store_action(request, RevertAction(blog, snapshot=revert_form.cleaned_data['snapshot']))
			return HttpResponseRedirect(reverse("pressgang:revert-blog", kwargs={'blog_id': blog.pk}))
	else:
		revert_form = ReversionForm(blog)

	page = Page(request)
	page.add_render_args({
		'blog': blog,
		'revert_form': revert_form
	})
	return page.render('pressgang/revert/options.html')