def org_list(): set_menu() lang = get_admin_lang() permission_content(lang) orgs = Organisation.query.filter_by(lang=lang, current=True) orgs = orgs.order_by('name') for org in orgs: p = Organisation.query.filter_by( org_id=org.org_id, lang=lang, status='publish' ).first() org.has_published = bool(p) if lang == 'en': missing = [] trans = {} else: # missing orgs trans = db.session.query(Organisation.org_id).filter_by( lang=lang, current=True ) missing = db.session.query(Organisation).filter_by( lang='en', current=True ) missing = missing.filter(db.not_(Organisation.org_id.in_(trans))) missing = missing.order_by('name') status = list_status() return render_template('admin/org_list.html', orgs=orgs, lang=lang, missing=missing, trans=trans, status=status)
def org_list(): set_menu() lang = get_admin_lang() permission_content(lang) orgs = Organisation.query.filter_by(lang=lang, current=True) orgs = orgs.order_by('name') for org in orgs: p = Organisation.query.filter_by(org_id=org.org_id, lang=lang, status='publish').first() org.has_published = bool(p) if lang == 'en': missing = [] trans = {} else: # missing orgs trans = db.session.query(Organisation.org_id).filter_by(lang=lang, current=True) missing = db.session.query(Organisation).filter_by(lang='en', current=True) missing = missing.filter(db.not_(Organisation.org_id.in_(trans))) missing = missing.order_by('name') status = list_status() return render_template('admin/org_list.html', orgs=orgs, lang=lang, missing=missing, trans=trans, status=status)
def cms_list(): set_menu() lang = get_admin_lang() permission_content(lang) pages = Cms.query.filter_by(lang=lang, current=True) pages = pages.order_by('title') for page in pages: p = Cms.query.filter_by(page_id=page.page_id, lang=lang, status='publish').first() page.has_published = bool(p) if lang == 'en': missing = [] trans = {} else: # missing pages trans = db.session.query(Cms.page_id).filter_by(lang=lang) missing = db.session.query(Cms).filter_by(lang='en', current=True) missing = missing.filter(db.not_(Cms.page_id.in_(trans))) missing = missing.order_by('title') status = list_status() return render_template('admin/cms_list.html', pages=pages, lang=lang, missing=missing, trans=trans, status=status)
def menu_list(): set_menu() lang = get_admin_lang() permission_content(lang) menu_items = MenuItem.query.filter_by(lang=lang, parent_menu_id=None) menu_items = menu_items.order_by('"order"', 'title') if lang == 'en': missing = [] trans = {} else: # missing menu_items trans = db.session.query(MenuItem.menu_id).filter_by(lang=lang) missing = db.session.query(MenuItem).filter_by(lang='en') missing = missing.filter(db.not_(MenuItem.menu_id.in_(trans))) status = list_status() return render_template('admin/menu_list.html', menu_items=menu_items, lang=lang, missing=missing, trans=trans, status=status)
def cms_preview(id): set_menu() lang = get_admin_lang() permission_content(lang) page = Cms.query.filter_by(page_id=id, lang=lang, current=True).first() if not page: page = Cms.query.filter_by(page_id=id, lang='en', current=True).first() if not page: abort(404) page = None translations = get_trans(id) ctx = _request_ctx_stack.top if ctx: ctx.babel_locale = lang return render_template('admin/cms_preview.html', page=page, translations=translations)
def org_preview(id): set_menu() lang = get_admin_lang() permission_content(lang) org = Organisation.query.filter_by(org_id=id, lang=lang, current=True).first() if not org: org = Organisation.query.filter_by(org_id=id, lang='en', current=True).first() if not org: abort(404) translations = get_trans(id) cat_codes = org_cat_codes(lang, id) ctx = _request_ctx_stack.top if ctx: ctx.babel_locale = lang return render_template('admin/org_preview.html', org=org, cat_codes=cat_codes, translations=translations)
def cms_state(id, state): lang = get_admin_lang() permission_content(lang) if state not in STATES: abort(403) page = Cms.query.filter_by(page_id=id, status=STATES[state], lang=lang, current=True).first() if not page: abort(403) if state == 'publish': page.published = True old_page = Cms.query.filter_by(page_id=id, status='publish', lang=lang).first() if old_page: old_page.status = 'archive' db.session.add(old_page) page.status = state db.session.add(page) db.session.commit() return redirect(url_for_admin('cms_preview', id=id))
def org_preview(id): set_menu() lang = get_admin_lang() permission_content(lang) org = Organisation.query.filter_by( org_id=id, lang=lang, current=True ).first() if not org: org = Organisation.query.filter_by( org_id=id, lang='en', current=True ).first() if not org: abort(404) translations = get_trans(id) cat_codes = org_cat_codes(lang, id) ctx = _request_ctx_stack.top if ctx: ctx.babel_locale = lang return render_template('admin/org_preview.html', org=org, cat_codes=cat_codes, translations=translations)
def org_state(id, state): lang = get_admin_lang() permission_content(lang) if state not in STATES: abort(403) org = Organisation.query.filter_by( org_id=id, status=STATES[state], lang=lang, current=True ).first() if not org: abort(403) if state == 'publish': org.published = True old_org = Organisation.query.filter_by( org_id=id, status='publish', lang=lang ).first() if old_org: old_org.status = 'archive' db.session.add(old_org) org.status = state db.session.add(org) db.session.commit() return redirect(url_for_admin('org_preview', id=id))
def org_state(id, state): lang = get_admin_lang() permission_content(lang) if state not in STATES: abort(403) org = Organisation.query.filter_by(org_id=id, status=STATES[state], lang=lang, current=True).first() if not org: abort(403) if state == 'publish': org.published = True old_org = Organisation.query.filter_by(org_id=id, status='publish', lang=lang).first() if old_org: old_org.status = 'archive' db.session.add(old_org) org.status = state db.session.add(org) db.session.commit() return redirect(url_for_admin('org_preview', id=id))
def org_edit(id): set_menu() lang = get_admin_lang() permission_content(lang) errors = [] org = Organisation.query.filter_by(org_id=id, lang=lang, current=True).first() if not org and lang != 'en': org = Organisation.query.filter_by(org_id=id, lang='en', current=True).first() if not org: abort(404) if not org: abort(404) if request.method == 'POST' and 'name' in request.form: if org.lang != lang: # No translation org = org_reedit(org) if (org.name != get_str('name') or org.description != get_str('description')): if org.status == 'publish': org = org_reedit(org) org.name = get_str('name') org.description = get_str('description') org.status = 'edit' trans_need_update(org) if lang == 'en': org.address = get_str('address') org.contact = get_str('contact') org.phone = get_str('phone') org.email = get_str('email') org.pgp_key = get_str('pgp_key') org.website = get_str('website') org.private = get_bool('private') org.active = get_bool('active') if get_bool('logo_remove'): org.image = None logo = request.files['logo'] if logo: extension = os.path.splitext(logo.filename)[1] if extension and extension.lower( ) in config.ALLOWED_IMAGE_TYPES: filename = unicode(uuid.uuid4()) filename += extension logo.save( os.path.join(app.config['UPLOAD_FOLDER'], filename)) org.image = filename else: errors.append( 'The image uploaded is not of an allowed type') db.session.add(org) if lang == 'en': # codes codes_data = all_codes('en', 'org') cats = [cat for cat in codes_data if cat['active']] cat_codes = [] for cat in cats: cat_codes += cat['codes'] codes = [code['code'] for code in cat_codes if code['active']] c_in = [] c_out = [] for code in codes: if get_bool(code): c_in.append(code) else: c_out.append(code) current = [ c.code for c in OrgCodes.query.filter_by(org_id=id).all() ] for code in c_in: if code not in current: code = OrgCodes(org_id=id, code=code) db.session.add(code) for code in c_out: OrgCodes.query.filter_by(org_id=id, code=code).delete() db.session.commit() if lang == 'en': update_translations(org) if not errors: return redirect(url_for_admin('org_preview', id=id)) if lang != 'en': trans = Organisation.query.filter_by(org_id=org.org_id, lang='en', current=True).first() else: trans = {} if lang == 'en': codes = all_codes('en', 'org') current = [c.code for c in OrgCodes.query.filter_by(org_id=id).all()] else: codes = [] current = [] translations = get_trans(id) if lang != org.lang: org = {} return render_template('admin/org_edit.html', org=org, trans=trans, codes=codes, current=current, errors=errors, translations=translations)
def cms_edit(id): set_menu() lang = get_admin_lang() permission_content(lang) errors = [] page = Cms.query.filter_by(page_id=id, lang=lang, current=True) page = page.first() if not page and lang != 'en': page = Cms.query.filter_by(page_id=id, lang='en', current=True) page = page.first() if not page: abort(404) if not page: abort(404) if request.method == 'POST' and 'title' in request.form: if page.lang != lang: # no translation page = page_reedit(page) if (page.title != get_str('title') or page.content != get_str('content')): if page.status == 'publish': page = page_reedit(page) page.title = get_str('title') page.content = get_str('content') page.status = 'edit' trans_need_update(page) if lang == 'en': page.active = get_bool('active') page.private = get_bool('private') url = get_str('url') if url: check = Cms.query.filter(Cms.page_id != id, Cms.url == url) check = check.filter( db.or_(Cms.status == 'publish', Cms.current == True)) if check.count(): errors.append( 'The url is already used by another page choose ' + \ 'a new url or change the url of the existing page ' + \ 'first. The url has been reset in this form.' ) elif url in config.DISALLOWED_URLS: errors.append( 'The url provided is not allowed please choose ' + \ 'a new one. The url has been reset in this form.' ) else: page.url = url if get_bool('logo_remove'): page.image = None logo = request.files['logo'] if logo: extension = os.path.splitext(logo.filename)[1] if extension and extension.lower( ) in config.ALLOWED_IMAGE_TYPES: filename = unicode(uuid.uuid4()) filename += extension logo.save( os.path.join(app.config['UPLOAD_FOLDER'], filename)) page.image = filename else: errors.append( 'The image uploaded is not of an allowed type') db.session.add(page) db.session.commit() if lang == 'en': update_translations(page) if not errors: return redirect(url_for_admin('cms_preview', id=id)) if lang != 'en': trans = Cms.query.filter_by(page_id=id, lang='en', current=True).first() else: trans = {} if lang != page.lang: page = {} translations = get_trans(id) return render_template('admin/cms_edit.html', page=page, trans=trans, translations=translations, errors=errors)
def org_edit(id): set_menu() lang = get_admin_lang() permission_content(lang) errors = [] org = Organisation.query.filter_by( org_id=id, lang=lang, current=True ).first() if not org and lang != 'en': org = Organisation.query.filter_by( org_id=id, lang='en', current=True ).first() if not org: abort(404) if not org: abort(404) if request.method == 'POST' and 'name' in request.form: if org.lang != lang: # No translation org = org_reedit(org) if (org.name != get_str('name') or org.description != get_str('description')): if org.status == 'publish': org = org_reedit(org) org.name = get_str('name') org.description = get_str('description') org.status = 'edit' trans_need_update(org) if lang == 'en': org.address = get_str('address') org.contact = get_str('contact') org.phone = get_str('phone') org.email = get_str('email') org.pgp_key = get_str('pgp_key') org.website = get_str('website') org.private = get_bool('private') org.active = get_bool('active') if get_bool('logo_remove'): org.image = None logo = request.files['logo'] if logo: extension = os.path.splitext(logo.filename)[1] if extension and extension.lower() in config.ALLOWED_IMAGE_TYPES: filename = unicode(uuid.uuid4()) filename += extension logo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) org.image = filename else: errors.append( 'The image uploaded is not of an allowed type' ) db.session.add(org) if lang == 'en': # codes codes_data = all_codes('en', 'org') cats = [cat for cat in codes_data if cat['active']] cat_codes = [] for cat in cats: cat_codes += cat['codes'] codes = [code['code'] for code in cat_codes if code['active']] c_in = [] c_out = [] for code in codes: if get_bool(code): c_in.append(code) else: c_out.append(code) current = [ c.code for c in OrgCodes.query.filter_by(org_id=id).all() ] for code in c_in: if code not in current: code = OrgCodes(org_id=id, code=code) db.session.add(code) for code in c_out: OrgCodes.query.filter_by(org_id=id, code=code).delete() db.session.commit() if lang == 'en': update_translations(org) if not errors: return redirect(url_for_admin('org_preview', id=id)) if lang != 'en': trans = Organisation.query.filter_by( org_id=org.org_id, lang='en', current=True ).first() else: trans = {} if lang == 'en': codes = all_codes('en', 'org') current = [ c.code for c in OrgCodes.query.filter_by(org_id=id).all() ] else: codes = [] current = [] translations = get_trans(id) if lang != org.lang: org = {} return render_template('admin/org_edit.html', org=org, trans=trans, codes=codes, current=current, errors=errors, translations=translations)
def cms_edit(id): set_menu() lang = get_admin_lang() permission_content(lang) errors = [] page = Cms.query.filter_by(page_id=id, lang=lang, current=True) page = page.first() if not page and lang != 'en': page = Cms.query.filter_by(page_id=id, lang='en', current=True) page = page.first() if not page: abort(404) if not page: abort(404) if request.method == 'POST' and 'title' in request.form: if page.lang != lang: # no translation page = page_reedit(page) if (page.title != get_str('title') or page.content != get_str('content')): if page.status == 'publish': page = page_reedit(page) page.title = get_str('title') page.content = get_str('content') page.status = 'edit' trans_need_update(page) if lang == 'en': page.active = get_bool('active') page.private = get_bool('private') url = get_str('url') if url: check = Cms.query.filter(Cms.page_id != id, Cms.url == url) check = check.filter(db.or_( Cms.status == 'publish', Cms.current == True )) if check.count(): errors.append( 'The url is already used by another page choose ' + \ 'a new url or change the url of the existing page ' + \ 'first. The url has been reset in this form.' ) elif url in config.DISALLOWED_URLS: errors.append( 'The url provided is not allowed please choose ' + \ 'a new one. The url has been reset in this form.' ) else: page.url = url if get_bool('logo_remove'): page.image = None logo = request.files['logo'] if logo: extension = os.path.splitext(logo.filename)[1] if extension and extension.lower() in config.ALLOWED_IMAGE_TYPES: filename = unicode(uuid.uuid4()) filename += extension logo.save( os.path.join(app.config['UPLOAD_FOLDER'], filename) ) page.image = filename else: errors.append( 'The image uploaded is not of an allowed type' ) db.session.add(page) db.session.commit() if lang == 'en': update_translations(page) if not errors: return redirect(url_for_admin('cms_preview', id=id)) if lang != 'en': trans = Cms.query.filter_by(page_id=id, lang='en', current=True).first() else: trans = {} if lang != page.lang: page = {} translations = get_trans(id) return render_template('admin/cms_edit.html', page=page, trans=trans, translations=translations, errors=errors)