예제 #1
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
예제 #2
0
파일: page.py 프로젝트: viaict/viaduct
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)
예제 #3
0
파일: home.py 프로젝트: viaict/viaduct
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_service.get_page_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