Esempio n. 1
0
def new_site():
    user = users.get_current_user()
    form = PageForm(request.form)
    if request.method == 'POST':
        if form.validate():
            site = Site(
                name=form.name.data,
                owner=user,
                users=[user],
                admins=[user],
            )
            site.put()
            page = Page.new_page(site, form.name.data, form.url.data)
            new_url = url_for('editor', page_id=page.key().id())
            if request.is_xhr:
                return jsonify(dict(type='success', redirect=new_url))
            else:
                return redirect(new_url)
        elif request.is_xhr:
            return jsonify(
                dict(type='error',
                     errors=render_template('form_errors.html', form=form)))
    if request.is_xhr:
        return render_template('site_creator.html', form=form)
    return render_template('new_site.html', form=form)
Esempio n. 2
0
def submiteditedpage(request, pageid):
    if request.user.is_authenticated() and request.method == "POST":
        page = findPage(pageid)
        if not page:
            return go404()
        if request.user.is_staff or page.author == findUser(request.user):
            if request.FILES:
                files = request.FILES
            elif page.illustration:
                files = {'illustration': page.illustration}
            else:
                files = {}
            form = PageForm(request.POST, files)
            if form.is_valid():
                page.short_desc = form.cleaned_data['short_desc']
                page.illustration = files.get('illustration')
                page.long_desc = form.cleaned_data['long_desc']
                if request.FILES.get('video'):
                    page.video = 'https://player.vimeo.com' + (Vimeo_Upload(
                        request.FILES.get('video')))
                page.save()
                return HttpResponseRedirect("/page:" + str(page.id) + "/")
            else:
                return render_to_response(
                    "editingapage.html", {
                        'form': form,
                        'page': page
                    },
                    context_instance=RequestContext(request))
    return goHome()
Esempio n. 3
0
def edit_page(nickname, pagename):

	if nickname != g.user.nickname:
		flash('Cannot edit another users content page.')
		return redirect(url_for('index'))

	user_page = g.user.user_page(pagename)

	if user_page == None:
		flash('Content page doesn''t exist')
		return redirect(url_for('index'))

	form = PageForm()

	if form.validate_on_submit():
		user_page.page_title = form.page_title.data
		user_page.page_content = form.page_content.data
		db.session.add(user_page)
		db.session.commit()
		flash('Updated content page successfully!')
		return redirect(url_for('index'))
	else:
		form.page_title.data = user_page.page_title
		form.page_content.data = user_page.page_content

	return render_template('page_form.html',
		form = form)
Esempio n. 4
0
def submitnewpage(request, parentid, book):
    if request.user.is_authenticated() and request.method == "POST":
        if (not parentid and user.is_staff()) or parentid:    
            form = PageForm(request.POST, request.FILES)
            if form.is_valid():
                page = Page()
                if int(parentid):
                    page.parent = Page.objects.all().get(id=parentid)
                else:
                    page.parent = None
                page.author = request.user
                page.short_desc = form.cleaned_data['short_desc']
                if request.FILES.get('video'): 
                    page.video = 'https://player.vimeo.com' + (
                    Vimeo_Upload(request.FILES.get('video'))
                )
                if request.FILES.get('illustration'):
                    page.illustration = request.FILES.get('illustration')
                    page.video = None
                page.long_desc = form.cleaned_data['long_desc']            
                page.book = get_object_or_404(Book,pk=int(book))
                page.save()
                return HttpResponseRedirect("/page:"+str(page.id)+"/")
            else:
                return render_to_response("writinganewpage.html", {'form': form, 'parentid': parentid, "book": book}, context_instance=RequestContext(request))
    return goHome() 
Esempio n. 5
0
def submiteditedpage(request, pageid):
    if request.user.is_authenticated() and request.method == "POST":
        page = findPage(pageid)
        if not page:
            return go404()
        if request.user.is_staff or page.author == findUser(request.user):
            if request.FILES:
                files = request.FILES
            elif page.illustration:
                files = {'illustration': page.illustration}
            else:
                files = {}
            form = PageForm(request.POST, files)
            if form.is_valid():
                page.short_desc = form.cleaned_data['short_desc']
                page.illustration = files.get('illustration')
                page.long_desc = form.cleaned_data['long_desc']
                if request.FILES.get('video'): 
                    page.video = 'https://player.vimeo.com' + (
                    Vimeo_Upload(request.FILES.get('video'))
                )
                page.save()
                return HttpResponseRedirect("/page:"+str(page.id)+"/") 
            else:
                return render_to_response("editingapage.html", {'form': form, 'page': page}, context_instance=RequestContext(request))
    return goHome()
Esempio n. 6
0
def add_page(request, category_name_url):
    context = RequestContext(request)

    category_name = decode_category_url(category_name_url)
    if request.method == 'POST':
        form = PageForm(request.POST)

        if form.is_valid():
            page = form.save(commit=False)
            try:
                cat = Category.objects.get(name=category_name)
                page.category =  cat
            except Category.DoesNotExist:
                return render_to_response('rango/add_category.html', {}, context)

            page.views = 0
            page.save()

            return category(request, category_name_url)
        else:
            print(form.errors)
    else:
        form = PageForm()

    return render_to_response('rango/add_page.html', {
       'cat_list': get_category_list(),
       'category_name_url': category_name_url,
       'category_name': category_name,
       'form': form
        },
        context)
Esempio n. 7
0
def add_page(request, category_name_url):
	print 'add_page called'
	context = RequestContext(request)

	category_name = decode_url(category_name_url)

	if request.method == 'POST':
		form = PageForm(request.POST)

		if form.is_valid():
			page = form.save(commit = False)

			cat = Category.objects.get(name = category_name)
			page.category = cat

			page.views = 0

			page.save()

			return category(request, category_name_url)

		else:
			print form.errors

	else:
		form = PageForm()

	return render_to_response('rango/add_page.html',
		{'category_name_url': category_name_url,
		'category_name': category_name, 'form':form},
		context)
Esempio n. 8
0
def edit(request, name):
    """Allows users to edit wiki pages."""
    try:
        page = Page.objects.get(name=name)
    except Page.DoesNotExist:
        page = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if not page:
                page = Page()
            page.name = form.cleaned_data['name']
            page.content = form.cleaned_data['content']

            page.save()
            return redirect(view, name=page.name)
    else:
        if page:
            form = PageForm(initial=page.__dict__)
        else:
            form = PageForm(initial={'name': name})

    context = {
        'form': form,
    }

    return render_to_response('wiki/edit.html',
        RequestContext(request, context))
Esempio n. 9
0
def edit(request, name):
    """Allows users to edit wiki pages."""
    try:
        page = Page.objects.get(name=name)
    except Page.DoesNotExist:
        page = None

    if request.method == "POST":
        form = PageForm(request.POST)
        if form.is_valid():
            if not page:
                page = Page()
            page.name = form.cleaned_data["name"]
            page.content = form.cleaned_data["content"]

            page.save()
            return HttpResponseRedirect("../../%s/" % page.name)
    else:
        if page:
            form = PageForm(initial=page.__dict__)
        else:
            form = PageForm(initial={"name": name})

    return render_to_response(
        "wiki/edit.html",
        {
            "form": form,
            "admin": is_admin(request),
            "user": get_user(request),
            "navbar": Page.objects.get(name="NavBar"),
        },
    )
Esempio n. 10
0
def submitnewpage(request, parentid, book):
    if request.user.is_authenticated() and request.method == "POST":
        if (not parentid and user.is_staff()) or parentid:
            form = PageForm(request.POST, request.FILES)
            if form.is_valid():
                page = Page()
                if int(parentid):
                    page.parent = Page.objects.all().get(id=parentid)
                else:
                    page.parent = None
                page.author = request.user
                page.short_desc = form.cleaned_data['short_desc']
                if request.FILES.get('video'):
                    page.video = 'https://player.vimeo.com' + (Vimeo_Upload(
                        request.FILES.get('video')))
                if request.FILES.get('illustration'):
                    page.illustration = request.FILES.get('illustration')
                    page.video = None
                page.long_desc = form.cleaned_data['long_desc']
                page.book = get_object_or_404(Book, pk=int(book))
                page.save()
                return HttpResponseRedirect("/page:" + str(page.id) + "/")
            else:
                return render_to_response(
                    "writinganewpage.html", {
                        'form': form,
                        'parentid': parentid,
                        "book": book
                    },
                    context_instance=RequestContext(request))
    return goHome()
Esempio n. 11
0
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)

    if request.method == 'POST':
        page_form = PageForm(request.POST, prefix='page_form', instance=page)

        if page_form.is_valid():
            page_form.save()
            return redirect('pages:administration:pages_list')

    else:
        page_form = PageForm(prefix='page_form', instance=page)

    return render(request, 'pages/administration/edit_page.html', {
        'page': page,
        'langs': langs,
        'page_form': page_form,
    })
Esempio n. 12
0
def page_edit_static(request, id):
    shop = request.shop

    page = get_object_or_404(Page, pk=id)
    page_name = page.name
    page_name_link = page.name_link
    page_title = page.title
    page_body = page.body
    page_meta_content = page.meta_content

    static_pages = Page.objects.filter(shop=shop)
    dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
    form = PageForm(shop, request.POST or None, instance=page)
    if request.method == "POST":
        if form.is_valid():
            new_page = form.save(commit=False)
            new_page.save()
            version = PageVersion(page=page)
            version.name = page_name
            version.name_link = page_name_link
            version.title = page_title
            version.body = page_body
            version.meta_content = page_meta_content
            version.save()
            request.flash['message'] = unicode(_("Page successfully edited."))
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('page_edit_static', args=[id]))

    return render_to_response(
        'store_admin/web_store/pages_edit_static_page.html', {
            'form': form,
            'page': page,
            'static_pages': static_pages,
            'dynamic_pages': dynamic_pages
        }, RequestContext(request))
Esempio n. 13
0
def add_page(request, category_name_slug):

    try:
        cat = Category.objects.get(slug=category_name_slug)
    except Category.DoesNotExist:
                cat = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if cat:
                page = form.save(commit=False)
                page.category = cat
                page.views = 0
                page.save()
                # probably better to use a redirect here.
                return category(request, category_name_slug)
        else:
            print form.errors
    else:
        form = PageForm()

    context_dict = {'form':form, 'category': cat}

    return render(request, 'rango/add_page.html', context_dict)
Esempio n. 14
0
def page_edit_static(request, id):
    shop = request.shop

    page = get_object_or_404(Page, pk=id)
    page_name = page.name
    page_name_link = page.name_link
    page_title = page.title
    page_body = page.body
    page_meta_content = page.meta_content

    static_pages = Page.objects.filter(shop=shop)
    dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
    form = PageForm(shop, request.POST or None, instance=page)
    if request.method == "POST":
        if form.is_valid():
            new_page = form.save(commit=False)
            new_page.save()
            version = PageVersion(page=page)
            version.name = page_name
            version.name_link = page_name_link
            version.title = page_title
            version.body = page_body
            version.meta_content = page_meta_content
            version.save()
            request.flash["message"] = unicode(_("Page successfully edited."))
            request.flash["severity"] = "success"
            return HttpResponseRedirect(reverse("page_edit_static", args=[id]))

    return render_to_response(
        "store_admin/web_store/pages_edit_static_page.html",
        {"form": form, "page": page, "static_pages": static_pages, "dynamic_pages": dynamic_pages},
        RequestContext(request),
    )
Esempio n. 15
0
def view(request, test_id):
    """Test view, displays a test's pages"""

    # If another test is started, go to that test
    if 'test_id' in request.session and \
       request.session['test_id'] != test_id:
        return redirect('tests:view', request.session['test_id'])

    # Attempt to load the test with test_id
    test = get_object_or_404(Test, pk=test_id)

    # If test_id is not started, start it
    if 'test_id' not in request.session:
        request.session['test_status'] = 'active'
        request.session['test_id'] = test_id
        request.session['page_number'] = 1
        request.session['page_count'] = test.pages.count()
        request.session['answers'] = {}

    page_number = request.session['page_number']
    page_count = request.session['page_count']

    # This means that a test is finished, so proceed to the results
    if request.session['test_status'] == 'finished':
        return redirect('tests:result', test_id)

    page = test.pages.all()[page_number-1]

    # If page form has been submitted
    if request.method == 'POST':
        form = PageForm(request.POST, page=page)

        if form.is_valid():
            # Save answers in session
            request.session['answers'].update(form.cleaned_data)

            # Check if there is another page from the test; if not
            # proceed to the results
            if page_number < page_count:
                request.session['page_number'] += 1
                return redirect('tests:view', test_id)
            else:
                request.session['test_status'] = 'finished'
                return redirect('tests:result', test_id)
    else:
        form = PageForm(page=page)

    # Assign context variables
    context = {
        'test': test,
        'page_number': page_number,
        'page_count': page_count,
        'form': form,
    }

    return render(request, 'tests/view.html', context)
Esempio n. 16
0
def edit(request, name):
    """Allows users to edit wiki pages."""
    try:
        page = Page.objects.get(name=name)
    except Page.DoesNotExist:
        page = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if not page:
                # it's a new page
                page = Page()

                page.name = form.cleaned_data['name']

                page.user = request.user
                page.created_on = datetime.now()
                page.save()

                page_revision = PageRevision(content = form.cleaned_data['content'], edit_reason = form.cleaned_data['edit_reason'], user = request.user, revision_for = page)
                page_revision.save()

                page.current_revision = page_revision
                page.save()

            else:
                # it's an edit on an old page

                page.name = form.cleaned_data['name']

                revision_count = PageRevision.objects.filter(revision_for = page).count()
                new_rev = revision_count + 1
                page_revision = PageRevision(content = form.cleaned_data['content'], edit_reason = form.cleaned_data['edit_reason'], user = request.user, revision_for = page, revision_num = new_rev)
                page_revision.save()

                page.current_revision = page_revision
                page.modified_on = datetime.now()
                page.user = request.user
                page.save()
            
            return HttpResponseRedirect('../../%s/' % page.name)
    else:
        if page:
            page_dict = page.__dict__
            # we have phased out page.content,
            # instead page will be a reference to current revision content.
            # but for the purposes of the form, we'll emulate it (ugly hack!)
            page_dict['content'] = page.current_revision.content
            form = PageForm(initial=page_dict)
        else:
            form = PageForm(initial={'name': name})

    context = RequestContext(request)
    return render_to_response('wiki/edit.html', {'form': form}, context)
Esempio n. 17
0
def edit(page_id):
    page = Page.objects.with_id(page_id)
    form = PageForm(request.form, page)
    if form.validate_on_submit():
        form.populate_obj(page)
        page.save()
        return redirect('/wiki/')
    return render_template('wiki_edit.html',
                           title="Wiki - edit page " + page.title,
                           page=page,
                           form=form)
Esempio n. 18
0
def create():
    page = Page()
    form = PageForm(request.form, page)
    if form.validate_on_submit():
        form.populate_obj(page)
        page.save()
        return redirect('/wiki/')
    return render_template('wiki_create.html',
                           title="Wiki - create new page",
                           page=page,
                           form=form)
Esempio n. 19
0
def pages():
	form = PageForm()

	if form.validate_on_submit():
		page = Page(page_title = form.page_title.data, page_content = form.page_content.data, user_id = g.user.id)
		db.session.add(page)
		db.session.commit()
		flash('Your page has been added!')
		return redirect(url_for('index'))

	return render_template('page_form.html',
		form = form)
Esempio n. 20
0
def page_add(request, response_format='html'):
    "Static Page add"

    if request.POST:
        form = PageForm(request.POST)
        if form.is_valid():
            page = form.save()
            return HttpResponseRedirect(reverse('core_admin_page_view', args=[page.id]))
    else:
        form = PageForm()

    return render_to_response('core/administration/page_add',
                              {'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
Esempio n. 21
0
def save_page(page_id=None):
    """Save Page to database

    If page_id is None a new Page will be inserted in the database. Otherwise
    the existing Page will be updated.
    """
    message = 'Page updated'

    page_form = PageForm(request.form)

    if not page_form.validate():
        flash('ERROR: errors detected. Page NOT saved!', category='error')
        return edit_page(page_id=page_id, page_form=page_form)

    if page_id is None:
        page = Page(request.form['title'], request.form['content'])
        page.status_id = 1
        page.user_id = session['user_id']
        page.createdate = datetime.now()
    else:
        page = get_page(page_id)

    page_form.populate_obj(page)
    page.lastmoddate = datetime.now()

    # compile input to html
    page.compile(app.config['REPL_TAGS'])

    # update pubdate if page's pubdate is None and its status is set
    # to public
    if request.form['status'] == 'public' and \
           unicode(page.status) != 'public' and \
           page.pubdate is None:
        page.pubdate = datetime.now()

    page.status = get_status(request.form['status'])

    if page.slug is None:
        page.slug = slugify(page.title)

    if page_id is None:
        db_session.add(page)
        message = 'New page was successfully added'

    db_session.commit()

    flash(message)

    return redirect(url_for('edit_page', page_id=page.id))
Esempio n. 22
0
def new_page(site_id):
    site = Site.get_admin_or_404(site_id)
    form = PageForm(request.form, site=site)
    if request.method == 'POST':
        if form.validate():
            page = Page.new_page(site, form.name.data, form.url.data)
            new_url = url_for('editor', page_id=page.key().id())
            if request.is_xhr:
                return jsonify(dict(type='success', redirect=new_url))
            return redirect(new_url)
        elif request.is_xhr:
            return jsonify(dict(type='error', errors=render_template('form_errors.html', form=form)))
    if request.is_xhr:
        return render_template('page_creator.html', form=form, site=site)
    return render_template('new_page.html', form=form, site=site)
Esempio n. 23
0
def page_edit(request, page_id, response_format='html'):
    "Static Page edit"

    page = get_object_or_404(Page, pk=page_id)
    if request.POST:
        form = PageForm(request.POST, instance=page)
        if form.is_valid():
            page = form.save()
            return HttpResponseRedirect(reverse('core_admin_page_view', args=[page.id]))
    else:
        form = PageForm(instance=page)

    return render_to_response('core/administration/page_edit',
                              {'page': page, 'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
Esempio n. 24
0
def submiteditedpage(request, pageid):
    if request.user.is_authenticated() and request.method == "POST":
        page = findPage(pageid)
        if not page:
            return go404()
        if request.user.is_staff or page.author == findUser(request.user):
            form = PageForm(request.POST, request.FILES)
            if form.is_valid():
                page.short_desc = form.cleaned_data['short_desc']
                page.illustration = request.FILES['illustration']
                page.long_desc = form.cleaned_data['long_desc']
                page.save()
                return HttpResponseRedirect("/page:"+str(page.id)+"/") 
            else:
                return render_to_response("editingapage.html", {'form': form, 'page': page}, context_instance=RequestContext(request))
    return goHome()
Esempio n. 25
0
def edit_page():
    form = PageForm(request.form)
    name = request.args['page']
    doc = db.static.find_one({'name': name})
    menu = Markup(db.static.find_one({'name': 'menu'})['content'])

    if request.method == 'POST':
        new_title = form.page_title.data
        new_content = form.page_content.data
        new_name = form.page_name.data
        db.static.update({'name': name}, {
            "$set": {
                'content': new_content,
                'title': new_title,
                'name': new_name
            }
        })
        return redirect(url_for('edit_pages'))

    file_title = Markup(doc['title'])
    file_markup = Markup(doc['content'])
    form.page_title.data = file_title
    form.page_name.data = name
    form.page_content.data = file_markup

    return render_template('edit.html', form=form, menu=menu, rss=False)
Esempio n. 26
0
def add_page(request, category_name_url):
    context = RequestContext(request)

    category_name = decode_url(category_name_url)
    if request.method == 'POST':
        form = PageForm(request.POST)

        if form.is_valid():
            # This time we cannot commit straight away.
            # Not all fields are automatically populated!
            page = form.save(commit=False)

            # Retrieve the associated Category object so we can add it.
            # Wrap the code in a try block - check if the category actually exists!
            try:
                cat = Category.objects.get(name=category_name)
                page.category = cat
            except Category.DoesNotExist:
                # If we get here, the category does not exist.
                # We render the add_page.html template without a context dictionary.
                # This will trigger the red text to appear in the template!
                return render_to_response('rango/add_page.html', {'category_name': category_name}, context)

            # Also, create a default value for the number of views.
            page.views = 0

            # With this, we can then save our new model instance.
            page.save()
            action.send(request.user, verb='added page', action_object=page, target=cat)
            # Now that the page is saved, display the category instead.
            return category(request, category_name_url)
        else:
            print form.errors
    else:
        try:
            cat = Category.objects.get(name=category_name)
        except Category.DoesNotExist:
            # If we get here, the category does not exist.
            # We render the add_page.html template without a context dictionary.
            # This will trigger the red text to appear in the template!
            return render_to_response('rango/add_page.html', {'category_name': category_name}, context)
        form = PageForm()

    return render_to_response('rango/add_page.html',
                              {'category_name_url': category_name_url,
                               'category_name': category_name, 'form': form},
                              context)
Esempio n. 27
0
def new_page(site_id):
    site = Site.get_admin_or_404(site_id)
    form = PageForm(request.form, site=site)
    if request.method == 'POST':
        if form.validate():
            page = Page.new_page(site, form.name.data, form.url.data)
            new_url = url_for('editor', page_id=page.key().id())
            if request.is_xhr:
                return jsonify(dict(type='success', redirect=new_url))
            return redirect(new_url)
        elif request.is_xhr:
            return jsonify(
                dict(type='error',
                     errors=render_template('form_errors.html', form=form)))
    if request.is_xhr:
        return render_template('page_creator.html', form=form, site=site)
    return render_template('new_page.html', form=form, site=site)
Esempio n. 28
0
 def get(self, page_id=None, **kwargs):
     """Return a page to edit or an empty form to create"""
     template = 'admin/page/new.html'
     context = {
         'form': self.form,
     }
     # render edit
     if page_id is not None:
         page = Page.get_by_id(page_id)
         if page:
             self.form = PageForm(obj=page)
             context.update({'form': self.form})
             template = 'admin/page/edit.html'
         else:
             return redirect('admin/page/')
     # render new
     return self.render_response(template, **context)
Esempio n. 29
0
def index():
    user = users.get_current_user()
    if user:
        if not UserSettings.has_seen_example() and GqlQuery(
                'SELECT __key__ FROM Site WHERE owner=:1 AND example=true',
                user).count(1) == 0:
            _create_example_site(user)
            UserSettings.mark_example_as_seen()
        sites = Site.gql('WHERE users=:1 ORDER BY name', user)
        site_form = PageForm()
        page_form = PageForm()
        return render_template('index.html',
                               sites=sites,
                               new_site_form=site_form,
                               page_form=page_form)
    else:
        return home()
Esempio n. 30
0
def create_page():
    form = PageForm(request.form)
    menu = Markup(db.static.find_one({'name': 'menu'})['content'])

    if request.method == 'POST' and form.validate():
        title = form.page_title.data
        content = form.page_content.data
        name = form.page_name.data
        db.static.insert({
            'name': name,
            'content': content,
            'title': title,
            'type': 'page'
        })
        return redirect(url_for('edit_pages'))

    return render_template('edit.html', form=form, menu=menu)
Esempio n. 31
0
def edit(request, name):
    """Allows users to edit wiki pages."""
    try:
        page = Page.objects.get(name=name)
    except Page.DoesNotExist:
        try:
            page = Page.objects.get(name=name.title())
        except Page.DoesNotExist:
            page = Page(name=name)

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            page.name = form.cleaned_data['name']
            page.content = form.cleaned_data['content']
            if not page.order:
                page.order = Page.objects.latest('order').order + 1
            page.save()
            return redirect(view, name=page.name)
    else:
        if page:
            form = PageForm(initial=page.__dict__)
        else:
            form = PageForm(initial={'name': name})

    context = {'form': form, 'page': page, 'pages': Page.objects.all()}

    return render_to_response('wiki/edit.html',
                              RequestContext(request, context))
Esempio n. 32
0
def edit(request, name):
    """Allows users to edit wiki pages."""
    try:
        page = Page.objects.get(name=name)
    except Page.DoesNotExist:
        page = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if not page:
                page = Page()
            page.name = form.cleaned_data['name']
            page.content = form.cleaned_data['content']

            page.save()
            return HttpResponseRedirect('../../%s/' % page.name)
    else:
        if page:
            form = PageForm(initial=page.__dict__)
        else:
            form = PageForm(initial={'name': name})

    return render_to_response('wiki/edit.html', {
        'form': form, 
        'admin': is_admin(request),
        'user': get_user(request),
        'navbar':Page.objects.get(name='NavBar'),
    })
Esempio n. 33
0
def edit(request, name):
    """Allows users to edit wiki pages."""
    try:
        page = Page.objects.get(name=name)
    except Page.DoesNotExist:
        page = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if not page:
                page = Page()
            page.name = form.cleaned_data['name']
            page.save()

            revision = Revision()
            revision.page = page
            revision.content = form.cleaned_data['content']
            if request.user.is_authenticated():
                revision.editor = request.user
            revision.save()
            return HttpResponseRedirect(page.get_absolute_url())
    else:
        if page:
            revision = page.get_latest_revision()
            form = PageForm(initial={'name': page.name, 'content': revision.content})
        else:
            form = PageForm(initial={'name': name})

    ctx = { 'form': form }
    return render_to_response('wiki/edit.html', ctx, context_instance=RequestContext(request))
Esempio n. 34
0
def page_create(request):
    shop = request.shop
    static_pages = Page.objects.filter(shop=shop)
    dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
    form = PageForm(shop, request.POST or None)
    if form.is_valid():
        page = form.save(commit=False)
        page.shop = shop
        page.save()
        request.flash["message"] = unicode(_("Page successfully saved."))
        request.flash["severity"] = "success"
        return HttpResponseRedirect(reverse("web_store_pages"))

    return render_to_response(
        "store_admin/web_store/pages_page_create.html",
        {"form": form, "static_pages": static_pages, "dynamic_pages": dynamic_pages},
        RequestContext(request),
    )
Esempio n. 35
0
def edit_page(page_id):
    page = Page.get_admin_or_404(page_id)
    form = PageForm(request.form, page)
    if request.method == 'POST':
        if form.validate():
            if form.data['url'] != page.url:
                page.queue_preview()
            page.name = form.name.data
            page.url = form.url.data
            page.preview_urls = [Link(url.data) for url in form.preview_urls]
            page.put()
            if request.is_xhr:
                return 'OK'
        elif request.is_xhr:
            return render_template('form_errors.html', form=form)
    if request.is_xhr:
        return render_template('page_editor.html', form=form, page=page)
    return render_template('edit_page.html', form=form, site=page.site, page=page)
Esempio n. 36
0
def add_page(request, category_name_url):
    context = RequestContext(request)
    cat_list = get_category_list()
    context_dict = {}
    context_dict['cat_list'] = cat_list

    category_name = decode_url(category_name_url)
    if request.method == 'POST':
        form = PageForm(request.POST)

        if form.is_valid():
            # This time we cannot commit straight away.
            # Not all fields are automatically populated!
            page = form.save(commit=False)

            # Retrieve the associated Category object so we can add it.
            try:
                cat = Category.objects.get(name=category_name)
                page.category = cat
            except Category.DoesNotExist:
                return render_to_response('rango/add_page.html',
                                          context_dict,
                                          context)

            # Also, create a default value for the number of views.
            page.views = 0

            # With this, we can then save our new model instance.
            page.save()

            # Now that the page is saved, display the category instead.
            return category(request, category_name_url)
        else:
            print form.errors
    else:
        form = PageForm()

    context_dict['category_name_url'] = category_name_url
    context_dict['category_name'] = category_name
    context_dict['form'] = form

    return render_to_response('rango/add_page.html',
                              context_dict,
                              context)
Esempio n. 37
0
def page_create(request):
    shop = request.shop
    static_pages = Page.objects.filter(shop=shop)
    dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
    form = PageForm(shop, request.POST or None)
    if form.is_valid():
        page = form.save(commit=False)
        page.shop = shop
        page.save()
        request.flash['message'] = unicode(_("Page successfully saved."))
        request.flash['severity'] = "success"
        return HttpResponseRedirect(reverse('web_store_pages'))

    return render_to_response(
        'store_admin/web_store/pages_page_create.html', {
            'form': form,
            'static_pages': static_pages,
            'dynamic_pages': dynamic_pages,
        }, RequestContext(request))
Esempio n. 38
0
def submitnewpage(request, parentid):
    if request.user.is_authenticated() and request.method == "POST":
        if (not parentid and user.is_staff()) or parentid:    
            form = PageForm(request.POST, request.FILES)
            if form.is_valid():
                page = Page()
                if int(parentid):
                    page.parent = Page.objects.all().get(id=parentid)
                else:
                    page.parent = None
                page.author = request.user
                page.short_desc = form.cleaned_data['short_desc']
                page.illustration = request.FILES['illustration']
                page.long_desc = form.cleaned_data['long_desc']            
                page.save()
                return HttpResponseRedirect("/page:"+str(page.id)+"/")
            else:
                return render_to_response("writinganewpage.html", {'form': form, 'parentid': parentid}, context_instance=RequestContext(request))
    return goHome() 
Esempio n. 39
0
def create(request):
    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            page = form.save()
            #page = get_object_or_404(Page, id=form.pk)

            view_page_groups_ids = form.cleaned_data['view_page_groups']

            assign_perm_for_groups_id('pages.view_page', page, view_page_groups_ids)

            return HttpResponseRedirect(reverse('administration_pages_index'))
    else:
        form = PageForm()

    return direct_to_template(request, 'pages/administration/pages_create.html',
                              {'form': form,
                               'groups'
                               'active_module': 'pages', })
Esempio n. 40
0
def page_create(request):
    shop = request.shop
    static_pages = Page.objects.filter(shop=shop)
    dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
    form = PageForm(shop, request.POST or None)
    if form.is_valid():
        page = form.save(commit = False)
        page.shop = shop
        page.save()
        request.flash['message'] = unicode(_("Page successfully saved."))
        request.flash['severity'] = "success"
        return HttpResponseRedirect(reverse('web_store_pages'))
    
    return render_to_response('store_admin/web_store/pages_page_create.html',
                              {
                               'form': form,
                               'static_pages': static_pages,
                               'dynamic_pages': dynamic_pages,
                               },
                              RequestContext(request))    
Esempio n. 41
0
def add_page(request, category_slug):
    context_dict = {}
    cat = Category.objects.get(slug=category_slug)
    context_dict["category"] = cat
    if request.method == "POST":
        form = PageForm(request.POST)
        if form.is_valid():
            if cat:
                page = form.save(commit=False)
                page.category = cat
                page.views = 0
                page.save()
                return category(request, category_slug)
        else:
            print form.errors
    else:
        form = PageForm()
        context_dict["form"] = form

    return render(request, "rango/add_page.html", context_dict)
Esempio n. 42
0
def create_page(request, parent=None):
    if parent:
        parent = get_object_or_404(Page, id=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
            page.save()
            return redirect('pages:administration:create_page_content', page_id=page.id)
    else:
        page_form = PageForm(prefix='page_form')

    return render(request, 'pages/administration/create_page.html', {
        'parent': parent,
        'page_form': page_form,
     })
def page_edit_static(request, id):
    shop = request.shop
    page = get_object_or_404(Page, pk=id)
    static_pages = Page.objects.filter(shop=shop)
    dynamic_pages = DynamicPageContent.objects.filter(shop=shop)
    form = PageForm(shop, request.POST or None, instance=page)
    if request.method == "POST":
        if form.is_valid():
            form.save()
            request.flash['message'] = unicode(_("Page successfully edited."))
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('page_edit_static', args=[id]))
        
    return render_to_response('store_admin/web_store/pages_edit_static_page.html', {
                                       'form': form,
                                       'page': page,
                                       'static_pages': static_pages, 
                                       'dynamic_pages': dynamic_pages
                                       },
                                      RequestContext(request))
Esempio n. 44
0
def add_page(request, category_name_url):
    """
    Add page to category if it doesn't exist,
    :param request
    :param category_name_url
    """
    category_name = Category._encode_url_name(category_name_url, Category._url_decode_rules_dict)
    # category_name = "ooops"
    cat = None
    if request.method == "POST":
        form = PageForm(request.POST)

        if form.is_valid():
            # Cannot commit straight away, not all fields automatically populated
            page = form.save(commit=False)

            # Retrieve the associated Category object so we can add it
            # Handle exception for Model.DoesNotExist, Go back and render the add category form
            try:
                cat = Category.objects.get(url=category_name_url)
                page.category = cat
            except Category.DoesNotExist:
                # Category does not exist, Go back and the render the add_category form
                return _process_request(request, {}, "rango/add_category.html")
            # set default value for number of views, and save new model instance
            page.views = 0
            page.save()

            # Now that the page is saved, display the category instead.
            return category(request, category_name_url)
        else:
            print form.errors
    else:
        form = PageForm()

    context_dict = {
        "category_name_url": category_name_url,
        "category_name": category_name,
        "form": form,
    }
    return _process_request(request, context_dict, "rango/add_page.html")
Esempio n. 45
0
def submiteditedpage(request, pageid):
    if request.user.is_authenticated() and request.method == "POST":
        page = findPage(pageid)
        if not page:
            return go404()
        if request.user.is_staff or page.author == findUser(request.user):
            form = PageForm(request.POST, request.FILES)
            if form.is_valid():
                page.short_desc = form.cleaned_data['short_desc']
                page.illustration = request.FILES['illustration']
                page.long_desc = form.cleaned_data['long_desc']
                page.save()
                return HttpResponseRedirect("/page:" + str(page.id) + "/")
            else:
                return render_to_response(
                    "editingapage.html", {
                        'form': form,
                        'page': page
                    },
                    context_instance=RequestContext(request))
    return goHome()
Esempio n. 46
0
def edit_page(page_id):
    page = Page.get_admin_or_404(page_id)
    form = PageForm(request.form, page)
    if request.method == 'POST':
        if form.validate():
            if form.data['url'] != page.url:
                page.queue_preview()
            page.name = form.name.data
            page.url = form.url.data
            page.preview_urls = [Link(url.data) for url in form.preview_urls]
            page.put()
            if request.is_xhr:
                return 'OK'
        elif request.is_xhr:
            return render_template('form_errors.html', form=form)
    if request.is_xhr:
        return render_template('page_editor.html', form=form, page=page)
    return render_template('edit_page.html',
                           form=form,
                           site=page.site,
                           page=page)
Esempio n. 47
0
def add_page(request, category_name_slug):
	try:
		cat =  Category.objects.get(slug=category_name_slug)
	except Category.DoesNotExist:
		cat = None 

	if request.method == 'POST':
		form =  PageForm(request.POST)

		if form.is_valid():
			if cat:
				page = form.save(commit=False)
				page.category = cat
				page.views = 0 
				page.save()
				return category(request, category_name_slug)
			else:
				print form.errors
		else:
			print form.errors
	else:
		form = PageForm()

	context_dict = {'form':form, 'category':cat, 'slug':category_name_slug }
	return render(request, 'add_page.html', context_dict)
Esempio n. 48
0
def add_page(request, category_name_slug):
    try:
        cat = Category.objects.get(slug=category_name_slug)
    except Category.DoesNotExist:
        cat = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if cat:
                page = form.save(commit=False)
                page.category = cat
                page.views = 0
                page.save()
                # probably better to use a redirect here
                return HttpResponseRedirect('/rango/')
                # return category(request, category_name_slug)
        else:
            print form.errors
    else:
        form = PageForm()

    context_dict = {'form': form, 'category': cat, 'category_name_slug': category_name_slug}

    return render(request, 'rango/add_page.html', context_dict)
def add_page(request, category_name_url):
    context = RequestContext(request)
    context_dict = {}

    category_name = decode_url(category_name_url)
    if request.method == 'POST':
        form = PageForm(data=request.POST)

        if form.is_valid():
            page = form.save(commit=False)
            try:
                cat = Category.objects.get(name=category_name)
                page.category = cat
            except Category.DoesNotExist:
                return render_to_response('rango/add_page.html', context_dict,
                                          context)
            page.views = 0
            page.save()

            return category(request, category_name_url)
        else:
            print form.errors
    else:
        form = PageForm()

    context_dict['category_name_url'] = category_name_url
    context_dict['category_name'] = category_name
    context_dict['form'] = form

    return render_to_response('rango/add_page.html', context_dict, context)
Esempio n. 50
0
def add_page(request, category_name_slug):
    """
    view for adding news pages
    -it displays the form
    - validates the form
    - updates the database
    -return to success or failure page
    """
    try:
        category = Category.objects.get(slug= category_name_slug)
    except Category.DoesNotExist:
        category = None

    form = PageForm()
    if request.method=="POST":
        form = PageForm(request.POST)
        #check if form is valid
        if form.is_valid():
            if category:
                #create a page object by saving the form           
                page = form.save(commit=False) #don't save the page object yet into the database
                page.category = category
                page.views = 0
                #no save the page object into the database
                page.save()
                #return to the succes page, in this case the index page which also shows the top 5 pages
                return show_category(request, category_name_slug)
        else:
            #form contain invalid date, so print errors
            print form.errors
    context_dict = {'category':category, 'form':form}
    #render the form with error messages if any
    return render(request, 'news/add_page.html', context_dict)
Esempio n. 51
0
def page_edit(id=None):
    """edit or create a page"""

    page = g.db.pages.find_one({'_id': id})

    if id:
        if page is None:
            abort(404)
    else:
        # create a NEW page here
        page = {'owner': g.username}

    if page.get('owner') != g.username and not (g.is_admin):
        flash("You are not the page owner", category="danger")
        return redirect(url_for('site', path=page['slug']))

    if page.get('is_markup'):
        page_template = 'generic_form.html'
        form = PageForm()
    else:
        page_template = 'generic_form_ckedit.html'
        form = HTMLPageForm()

    if form.validate_on_submit():
        page = form2object(form, page)
        if form.slug.data == '':
            page['slug'] = slugify(page['title'])
        if id:
            g.db.pages.update_one({'_id': id}, page)
        else:
            g.db.pages.insert_one(page)

        flash('Page saved.', category="info")
        return redirect(url_for('site', path=page.get('slug')))

    if request.method == 'GET':
        # get the data from the page-object into the form
        form = object2form(page, form)

    return render_template(page_template, form=form, id=id, title="Edit page")
Esempio n. 52
0
class PageHandler(BaseHandler):
    """Manage individual pages"""
    @admin_required
    def get(self, page_id=None, **kwargs):
        """Return a page to edit or an empty form to create"""
        template = 'admin/page/new.html'
        context = {
            'form': self.form,
        }
        # render edit
        if page_id is not None:
            page = Page.get_by_id(page_id)
            if page:
                self.form = PageForm(obj=page)
                context.update({'form': self.form})
                template = 'admin/page/edit.html'
            else:
                return redirect('admin/page/')
        # render new
        return self.render_response(template, **context)

    @admin_required
    def post(self, page_id=None, **kwargs):
        """Handle submitted form data"""
        # validate form
        if self.form.validate():
            title = self.form.title.data
            content = self.form.content.data
            live = self.form.live.data
            language = self.form.language.data
            # saving edited
            if page_id:
                page = Page.get_by_id(page_id)
                page.title = title
                page.content = content
                page.live = live
                page.language = language
            # creating new
            else:
                page = Page(title=title,
                            content=content,
                            live=live,
                            language=language)
            if page.put():
                return redirect('admin/page')
        return self.get(**kwargs)

    @cached_property
    def form(self):
        """Form instance as cached_property"""
        return PageForm(self.request)
Esempio n. 53
0
def submitnewpage(request, parentid):
    if request.user.is_authenticated() and request.method == "POST":
        if (not parentid and user.is_staff()) or parentid:
            form = PageForm(request.POST, request.FILES)
            if form.is_valid():
                page = Page()
                if int(parentid):
                    page.parent = Page.objects.all().get(id=parentid)
                else:
                    page.parent = None
                page.author = request.user
                page.short_desc = form.cleaned_data['short_desc']
                page.illustration = request.FILES['illustration']
                page.long_desc = form.cleaned_data['long_desc']
                page.save()
                return HttpResponseRedirect("/page:" + str(page.id) + "/")
            else:
                return render_to_response(
                    "writinganewpage.html", {
                        'form': form,
                        'parentid': parentid
                    },
                    context_instance=RequestContext(request))
    return goHome()
Esempio n. 54
0
def editpage(request, pageid):
    page = findPage(pageid)
    if not page:
        return go404()
    if request.user.is_staff or page.author == findUser(request.user):
        already_written = {
            'short_desc': page.short_desc,
            'long_desc': page.long_desc
        }
        form = PageForm(already_written)
        return render_to_response("editingapage.html", {
            'form': form,
            'page': page
        },
                                  context_instance=RequestContext(request))
    return goHome()
Esempio n. 55
0
def add_page(request):
    context = RequestContext(request)

    if request.method == 'POST':
        form = PageForm(request.POST)

        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print form.errors
    else:
        form = PageForm()

    return render_to_response('rango/add_page.html', {'form': form}, context)
    def setUp(self):
        self.client = Client()
        try:
            populate()
        except ImportError:
            print('The module populate_rango does not exist')
        except NameError:
            print('The function populate() does not exist or is not correct')
        except:
            print('Something went wrong in the populate() function :-(')

        # Check forms are defined
        try:
            from forms import PageForm
            from forms import CategoryForm
            PageForm()
            CategoryForm()
        except ImportError:
            print('The module forms does not exist')
        except NameError:
            print('The class PageForm does not exist or is not correct')
        except Exception:
            print('Something else went wrong :-(')
Esempio n. 57
0
def add_page(request, category_name_url):
    """
    Add page to category if it doesn't exist,
    :param request
    :param category_name_url
    """
    category_name = Category._encode_url_name(category_name_url,
                                              Category._url_decode_rules_dict)
    # category_name = "ooops"
    cat = None
    if request.method == "POST":
        form = PageForm(request.POST)

        if form.is_valid():
            # Cannot commit straight away, not all fields automatically populated
            page = form.save(commit=False)

            # Retrieve the associated Category object so we can add it
            # Handle exception for Model.DoesNotExist, Go back and render the add category form
            try:
                cat = Category.objects.get(url=category_name_url)
                page.category = cat
            except Category.DoesNotExist:
                # Category does not exist, Go back and the render the add_category form
                return _process_request(request, {}, "rango/add_category.html")
            # set default value for number of views, and save new model instance
            page.views = 0
            page.save()

            # Now that the page is saved, display the category instead.
            return category(request, category_name_url)
        else:
            print form.errors
    else:
        form = PageForm()

    context_dict = {
        "category_name_url": category_name_url,
        "category_name": category_name,
        "form": form,
    }
    return _process_request(request, context_dict, "rango/add_page.html")
Esempio n. 58
0
def add_page(request, category_slug):
    context_dict = {}
    cat = Category.objects.get(slug=category_slug)
    context_dict['category'] = cat
    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if cat:
                page = form.save(commit=False)
                page.category = cat
                page.views = 0
                page.save()
                return category(request, category_slug)
        else:
            print form.errors
    else:
        form = PageForm()
        context_dict['form'] = form

    return render(request, 'rango/add_page.html', context_dict)
Esempio n. 59
0
def add_page(request, category_name_url):
    context = RequestContext(request)
    cat_list = get_category_list()
    context_dict = {}
    context_dict['cat_list'] = cat_list

    category_name = decode_url(category_name_url)
    if request.method == 'POST':
        form = PageForm(request.POST)

        if form.is_valid():
            # This time we cannot commit straight away.
            # Not all fields are automatically populated!
            page = form.save(commit=False)

            # Retrieve the associated Category object so we can add it.
            try:
                cat = Category.objects.get(name=category_name)
                page.category = cat
            except Category.DoesNotExist:
                return render_to_response('rango/add_page.html', context_dict,
                                          context)

            # Also, create a default value for the number of views.
            page.views = 0

            # With this, we can then save our new model instance.
            page.save()

            # Now that the page is saved, display the category instead.
            return category(request, category_name_url)
        else:
            print form.errors
    else:
        form = PageForm()

    context_dict['category_name_url'] = category_name_url
    context_dict['category_name'] = category_name
    context_dict['form'] = form

    return render_to_response('rango/add_page.html', context_dict, context)