def test_basic_page(self):
     with app.test_request_context():
         page = Page(name='abc', url='abc')
         save_to_db(page)
         page2 = Page(name='def', url='http://def.com')
         save_to_db(page2)
     resp = self.app.get('/sitemaps/pages.xml.gz')
     #self.assertIn('localhost/abc', resp.data)
     self.assertIn('<loc>http://def.com', resp.data)
Beispiel #2
0
def edit_page(path=''):

    page = page_service.get_page_by_path(path)

    if page:
        revision = page.get_latest_revision()
        revision.read_groups = page_service.get_read_permission_groups_by_page(
            page)
        revision.needs_paid = page.needs_paid
        revision.custom_read_permission = page.custom_read_permission
    else:
        revision = None

    form = init_form(PageForm, obj=revision)

    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
        page.custom_read_permission = form.custom_read_permission.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()

        if form.custom_read_permission.data:
            page_service.set_read_page_permissions(page, form.read_groups.data)
        else:
            page_service.delete_read_page_permission(page)

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

        # redirect (newly) created page revision
        return redirect(url_for('page.get_page', path=path))

    return render_template('page/edit_page.htm', page=page, form=form)
Beispiel #3
0
 def run(self):
     #for i in range(2):
     Contributor.fake_feed()
     Collective.fake_feed()
     Channel.fake_feed()
     Tag.fake_feed()
     BlogPost.fake_feed()
     Podcast.fake_feed()
     Section.fake_feed()
     Page.fake_feed()
     Event.fake_feed()
Beispiel #4
0
    def get_challenge_description():
        """ Get the description page for challenges """
        page = Page.get_by_path(Page.strip_path("challenge_description"))

        if not page:
            revision = PageRevision(None, None, None, None, None)
            revision.title = 'Not found!'
            revision.content = 'Description not found'
        else:
            revision = page.get_latest_revision()

        return revision
Beispiel #5
0
    def get_current_user_guide():
        module_name = request.blueprint

        """ Get the user guide for a specific module """
        user_guide = Page.get_by_path('guides/user/' + module_name)

        if not user_guide:
            user_revision = PageRevision(None, None, None, None, None, None, None)
            user_revision.title = 'Er is geen user handleiding beschikbaar voor ' +\
                module_name

            if ModuleAPI.can_write('page') and\
                    ModuleAPI.can_write(module_name):
                user_revision.content = 'Voeg ' +\
                    '<a href="/edit/guides/user/' + module_name + '"> hier </a>' +\
                    ' een user handleiding toe.'
            else:
                user_revision.content = ''
        else:
            user_revision = user_guide.get_latest_revision()
            if ModuleAPI.can_write('page') and\
                    ModuleAPI.can_write(module_name):
                user_revision.title += '<a href="/edit/guides/user/' + module_name +\
                    '"> (bewerk) </a>'

        return user_revision
Beispiel #6
0
    def get_current_admin_guide():
        module_name = request.blueprint

        admin_guide = Page.get_by_path('guides/admin/' + module_name)

        if not admin_guide or not ModuleAPI.can_write(module_name):
            admin_revision = PageRevision(None, None, None, None, None, None, None)
            if ModuleAPI.can_write(module_name):
                admin_revision.title = 'Er is geen admin handleiding beschikbaar voor ' +\
                    module_name
                if ModuleAPI.can_write('page'):
                    admin_revision.content = 'Voeg ' +\
                        '<a href="/edit/guides/admin/' + module_name + '"> hier </a>' +\
                        ' een admin handleiding toe.'
                else:
                    admin_revision.content = ''
            else:
                admin_revision.title = ''
                admin_revision.content = ''
        else:
            admin_revision = admin_guide.get_latest_revision()
            if ModuleAPI.can_write('page') and\
                    ModuleAPI.can_write(module_name):
                admin_revision.title += '<a href="/edit/guides/admin/' + module_name +\
                    '"> (bewerk) </a>'

        return admin_revision
Beispiel #7
0
    def create_page(form):

        page = Page(name=form.get('name', ''), title=form.get('title', ''), description=form.get('description', ''),
                    url=form.get('url', ''), place=form.get('place', ''), index=form.get('index', 0),
                    language=form.get('language', 'en'))
        save_to_db(page, "Page created")
        cache.delete('pages')
Beispiel #8
0
    def delete(cls, id: int):
        page = PageModel.find_by_id(id)
        if page:
            page.delete_from_db()
            return {"message": "Page deleted"}, 200

        return {"message": "Page not found"}, 404
Beispiel #9
0
 def get(cls, id: int):
     page = PageModel.find_by_id(id)
     if not page:
         return {'message': 'Notebook not found'}, 404
     args = request.args
     if 'mode' in args and args['mode'] == 'editor':
         return page_editor_shema.dump(page), 200
     return page_schema.dump(page), 200
Beispiel #10
0
    def remove_page(path):
        page = Page.get_by_path(path)
        if not page:
            return False

        db.session.delete(page)
        db.session.commit()

        return True
Beispiel #11
0
    def put(cls, id: int):
        page = PageModel.find_by_id(id)
        if not page:
            return {'message': 'Notebook not found'}, 404

        page_json = request.get_json()
        page = page_editor_shema.load(page_json, instance=page)
        page.save_to_db()
        return {"message": "Updated"}, 200
Beispiel #12
0
    def get(cls, id: int):
        notebook = NotebookModel.find_by_id(id)
        if not notebook:
            return {'message': 'Notebook not found'}, 404

        return {
            "pages":
            page_list_schema.dump(PageModel.find_all_pages_of_notebook(id))
        }, 200
Beispiel #13
0
    def get_footer():
        footer = Page.query.filter(Page.path == 'footer').first()

        if not footer:
            footer = Page('footer')

        revision = footer.get_latest_revision()

        if revision:
            exists = True
        else:
            title = 'Footer'
            content = '<strong>No footer found</strong>'
            revision = PageRevision(footer, title, title, '', current_user,
                                    content, content)
            exists = False

        return render_template('page/get_footer.htm', footer_revision=revision,
                               footer=footer, exists=exists)
Beispiel #14
0
def get_revisions(data):
    pages = []
    revisions = []

    for path in data:
        if path == 'activities':
            revision = PageRevision(None, None, None, None, None, None, None)

            activities = Activity.query \
                .filter(Activity.end_time > datetime.now()) \
                .order_by(Activity.start_time.asc())
            revision.activity = \
                render_template('activity/view_simple.htm',
                                activities=activities.paginate(1, 4, False))

            revisions.append(revision)

            continue

        page = Page.get_by_path(Page.strip_path(path))
        pages.append(page)

        if not page:
            revision = PageRevision(None, None, None, None, None, None, None)
            revision.title = _('Not found!')
            revision.content = _('Page not found')

            revisions.append(revision)

            continue

        revision = page.get_latest_revision()
        revision.test = path
        if not revision:
            return abort(500)

        revisions.append(revision)

    return revisions
Beispiel #15
0
def get_page(path=''):
    path = Page.strip_path(path)
    page = page_service.get_page_by_path(path)

    if not page:
        # Try if this might be a redirect.
        redirection = Redirect.query.filter(Redirect.fro == path).first()
        if redirection:

            # get GET parameters so they can be applied to the redirected
            # URL
            if request.args:
                redir_url = redirection.to + '?'
                for key in request.args:
                    redir_url += key + '=' + \
                        request.args[key] + '&'

                # this is necssary to prevent incorrect escaping
                return redirect(iri_to_uri(redir_url))

            return redirect(redirection.to)

        return abort(404)

    if not page_service.can_user_read_page(page, current_user):
        return abort(403)

    revision = page.get_latest_revision()

    if not revision:
        return abort(500)

    # Check if the current user has already entered data in this custom
    # form
    if getattr(revision, 'custom_form', False):
        if current_user.is_authenticated and current_user.has_paid:
            all_form_results = CustomFormResult.query \
                .filter(CustomFormResult.form_id == revision.custom_form.id)
            form_result = all_form_results \
                .filter(CustomFormResult.owner_id == current_user.id).first()

            if form_result:
                revision.custom_form_data = form_result.data.replace('"', "'")
    can_write = role_service.user_has_role(current_user, Roles.PAGE_WRITE)
    return render_template('%s/view_single.htm' % (page.type), page=page,
                           revision=revision, title=revision.title,
                           context=revision.__class__.context,
                           can_write=can_write)
Beispiel #16
0
def edit(entry_id=None, parent_id=None):
    if not ModuleAPI.can_read('navigation'):
        return abort(403)

    if entry_id:
        entry = db.session.query(NavigationEntry)\
            .filter_by(id=entry_id).first()
        if not entry:
            return abort(404)
    else:
        entry = None
    form = NavigationEntryForm(request.form, entry)

    if parent_id:
        parent = NavigationEntry.query.filter_by(id=parent_id).first()
        if not parent:
            flash(_('Cannot find parent navigation entry.'), 'danger')
            return redirect(url_for('navigation.view'))

    if form.validate_on_submit():
        url = form.url.data
        if not re.compile('^/').match(url):
            url = '/' + url

        if entry:
            entry.nl_title = form.nl_title.data
            entry.en_title = form.en_title.data
            entry.url = url
            entry.external = form.external.data
            entry.activity_list = form.activity_list.data
        else:
            # If there is no parent position the new entry at the end of the
            # top level entry.
            if not parent_id:
                parent = None

                last_entry = db.session.query(NavigationEntry)\
                    .filter_by(parent_id=None)\
                    .order_by(NavigationEntry.position.desc()).first()

                position = last_entry.position + 1
            else:
                last_entry = db.session.query(NavigationEntry)\
                    .filter_by(parent_id=parent_id)\
                    .order_by(NavigationEntry.position.desc()).first()
                if last_entry:
                    position = last_entry.position + 1
                else:
                    position = 0

            entry = NavigationEntry(parent,
                                    form.nl_title.data,
                                    form.en_title.data,
                                    url,
                                    form.external.data,
                                    form.activity_list.data,
                                    position)

        db.session.add(entry)
        db.session.commit()
        flash(_('The navigation entry has been saved.'), 'success')

        if not form.external.data:

            # Check if the page exists, if not redirect to create it
            path = form.url.data.lstrip('/')
            page = Page.get_by_path(path)
            if url.rstrip('/') in get_all_routes():
                return redirect(url_for('navigation.view'))
            if not page and form.url.data != '/':
                flash(_('The link refers to a page that does not exist, please'
                        'create the page!'), 'warning')
                return redirect(url_for('page.edit_page', path=path))

        return redirect(url_for('navigation.view'))

    else:
        flash_form_errors(form)

    parents = db.session.query(NavigationEntry).filter_by(parent_id=None)

    if entry:
        parents = parents.filter(NavigationEntry.id != entry.id)

    parents = parents.all()

    return render_template('navigation/edit.htm', entry=entry, form=form,
                           parents=parents)
Beispiel #17
0
def edit_committee(committee=''):
    path = 'commissie/' + committee

    page = page_service.get_page_by_path(path)
    revision = page.get_latest_revision() if page else None

    form = init_form(CommitteeForm, obj=revision)

    try:
        url_group_id = int(request.args.get('group_id', None))
    except (TypeError, ValueError):
        url_group_id = None

    if len(request.form) == 0:
        if revision:
            selected_group_id = revision.group_id
        elif url_group_id is not None:
            selected_group_id = url_group_id
        else:
            selected_group_id = form.group_id.choices[0][0]
    else:
        selected_group_id = int(form.group_id.data)

    form.group_id.data = selected_group_id

    selected_group = Group.query.get(selected_group_id)
    form.coordinator_id.choices = [
        (user.id, user.name) for user in
        selected_group.users.order_by(User.first_name, User.last_name).all()]

    if form.validate_on_submit():
        committee_nl_title = form.nl_title.data.strip()
        committee_en_title = form.en_title.data.strip()

        if not page:
            root_entry_url = url_for('committee.list').rstrip('/')
            root_entry = NavigationEntry.query\
                .filter(NavigationEntry.url == root_entry_url)\
                .first()

            # Check whether the root navigation entry exists.
            if not root_entry:
                last_root_entry = NavigationEntry.query\
                    .filter(NavigationEntry.parent_id == None)\
                    .order_by(NavigationEntry.position.desc()).first()  # noqa

                root_entry_position = 1
                if last_root_entry:
                    root_entry_position = last_root_entry.position + 1

                root_entry = NavigationEntry(
                    None, 'Commissies', 'Committees', root_entry_url, False,
                    False, root_entry_position)

                db.session.add(root_entry)
                db.session.commit()

            page = Page(path, 'committee')

            # Never needs paid.
            page.needs_paid = False

            # Create a navigation entry for the new committee.
            last_navigation_entry = NavigationEntry.query\
                .filter(NavigationEntry.parent_id == root_entry.id)\
                .first()

            entry_position = 1
            if last_navigation_entry:
                entry_position = last_navigation_entry.position + 1

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

            navigation_entry = NavigationEntry(
                root_entry, committee_nl_title, committee_en_title, None,
                page.id, False, False, entry_position)

            db.session.add(navigation_entry)
            db.session.commit()

            # Sort these navigation entries.
            NavigationAPI.alphabeticalize(root_entry)
        else:
            # If the committee's title has changed, the navigation needs to be
            # updated. Look for the entry, compare the titles, and change where
            # necessary.
            if page.navigation_entry:
                entry = page.navigation_entry[0]
                entry.nl_title = committee_nl_title
                entry.en_title = committee_en_title
                db.session.add(entry)

        group_id = int(form.group_id.data)
        coordinator_id = int(form.coordinator_id.data)

        # Add coordinator to BC
        bc_group = Group.query.filter(Group.name == "BC").first()
        if bc_group is not None:
            new_coordinator = User.query.filter(
                User.id == coordinator_id).first()
            bc_group.add_user(new_coordinator)

        new_revision = CommitteeRevision(
            page, committee_nl_title, committee_en_title,
            form.comment.data.strip(), current_user.id,
            form.nl_description.data.strip(), form.en_description.data.strip(),
            group_id, coordinator_id, form.interim.data,
            form.open_new_members.data)

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

        flash(_('The committee has been saved.'), 'success')

        return redirect(url_for('page.get_page', path=path))

    return render_template('committee/edit.htm', page=page,
                           form=form, path=path)
Beispiel #18
0
 def get(cls):
     return {"pages": page_list_schema.dump(PageModel.find_all())}, 200