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
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
def remove_page(path): page = Page.get_by_path(path) if not page: return False db.session.delete(page) db.session.commit() return True
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
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
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)