Beispiel #1
0
def update_page(bookId, pageId):
    errors = ["An error occurred while updating your page."]
    the_page = Page.query.get(pageId)
    form = PageForm()
    form['csrf_token'].data = request.cookies['csrf_token']

    if form.validate_on_submit():
        the_page.update_page_data(form.data['title'], form.data["text"])
        db.session.add(the_page)
        db.session.commit()
        return {the_page.get_id(): the_page.to_dict()}

    return {"errors": errors}
Beispiel #2
0
def create_page(bookId):
    errors = ["An error occurred while creating a new page."]
    form = PageForm()
    form['csrf_token'].data = request.cookies['csrf_token']

    if form.validate_on_submit():
        new_page = Page(title=form.data['title'],
                        text=form.data["text"],
                        book_id=bookId)
        db.session.add(new_page)
        db.session.commit()
        return {new_page.get_id(): new_page.to_dict()}

    return {"errors": errors}
Beispiel #3
0
def admin_page_modify(request, page_id):
    page = Page.objects.get(id=page_id)
    page_snap_form = PageSnapForm()
    if request.method == 'POST':
        page_form = PageForm(request.POST, request.FILES, instance=page)
        if page_form.is_valid():
            update_page = page_form.save()
            return HttpResponseRedirect('/custom123user/admin/pageview/')
    else:
        page_form = PageForm(instance=page)
    return render(request, 'admin_page_modify.html', {
        'page': page,
        'page_form': page_form,
        'page_snap_form': page_snap_form
    })
Beispiel #4
0
def add_page(request):
	# A HTTP POST?
	if request.method == 'POST':
		form = PageForm(request.POST)

		if form.is_valid():
			# Save the new event to the database.
			form.save(commit=True)
			# Now call the index() view.
			# The user will be shown the homepage.
			return index(request)
		else:
			# The supplied form contained errors - just print them to the terminal.
			print form.errors
	else:
		# If the request was not a POST, display the form to enter details.
		form = PageForm()
	# Bad form (or form details), no form supplied...
	# Render the form with error messages (if any).
	return render(request, 'app/add_page.html', {'form': form})
Beispiel #5
0
def submit_page(path):
    path = decode_path(path)
    form = PageForm()
    if form.validate_on_submit():
        photo = form.img.data
        filename = photos.save(photo) if photo else DEFAULT_IMAGE
        page = Page(path=path,
                    title=form.title.data,
                    text=form.text.data,
                    img=filename,
                    author=current_user)
        db.session.add(page)
        db.session.commit()
        return redirect(url_for('submit'))
    info = {
        'title': 'SUBMIT: PAGE',
        'homepage': False,
        'banner_img': DEFAULT_IMAGE,
        'form': form,
        'path': path
    }
    return render_template('submit/page.html', info=info)
Beispiel #6
0
def edit_page(path=''):
    if not ModuleAPI.can_write('page'):
        return abort(403)

    page = Page.get_by_path(path)
    form = request.form

    if page:
        revision = page.get_latest_revision()

        # Add the `needs_paid` option to the revision, so it will be inside
        # the form.
        revision.needs_paid = revision.page.needs_paid

        form = PageForm(form, revision)
    else:
        form = PageForm()

    groups = Group.query.all()

    # on page submit (edit or create)
    if form.validate_on_submit():
        # if there was no page we want to create an entire new page (and not
        # just a revision)
        if not page:
            page = Page(path)

        page.needs_paid = form['needs_paid'].data

        db.session.add(page)
        db.session.commit()

        custom_form_id = int(form.custom_form_id.data)
        if custom_form_id == 0:
            custom_form_id = None

        new_revision = PageRevision(page,
                                    form.nl_title.data.strip(),
                                    form.en_title.data.strip(),
                                    form.comment.data.strip(),
                                    current_user,
                                    form.nl_content.data.strip(),
                                    form.en_content.data.strip(),
                                    'filter_html' in form,
                                    custom_form_id)

        db.session.add(new_revision)
        db.session.commit()

        # Enter permission in db
        for form_entry, group in zip(form.permissions, groups):
            permission_entry = PagePermission.query\
                .filter(PagePermission.group_id == group.id,
                        PagePermission.page_id == page.id).first()

            permission_level = form_entry.select.data

            if permission_entry:
                permission_entry.permission = permission_level
            else:
                permission_entry = PagePermission(group.id, page.id,
                                                  permission_level)

            db.session.add(permission_entry)
            db.session.commit()

        flash(_('The page has been saved'), 'success')

        # redirect newly created page
        return redirect(url_for('page.get_page', path=path))
    else:
        flash_form_errors(form)
        for group in groups:
            permission = None
            if page:
                permission = PagePermission.query\
                    .filter(PagePermission.group_id == group.id,
                            PagePermission.page_id == page.id)\
                    .first()

            if permission:
                form.permissions\
                    .append_entry({'select': permission.permission})
            else:
                form.permissions.append_entry({})

    return render_template('page/edit_page.htm', page=page, form=form,
                           path=path, groups=zip(groups, form.permissions))