def test_permissions_all_accounts_groups(): from models.account import Account title = 'Testing | Permissions | Listed per-account-role permissions' data = '<table class="table" width="100%">' employees = [employee for employee in Account.all()] roles = g._var(name='roles', scope='permissions', default={}).keys() data = data + '<tr>' data = data + '<th> </th>' for role in roles: data = data + '<th>'+role+'</th>' data = data + '</tr>' for employee in employees: data = data + '<tr>' data = data + '<th>'+employee+'</th>' for role in roles: is_permitted = app.access('role', account=employee, role_id=role) data = data + (is_permitted and '<td class="alert alert-success">yes</td>' or '<td class="alert alert-danger">no</td>') data = data + '</tr>' data = data + '</table>' data = Markup(data) return render_template( 'test/index.html', title=title, data=data )
def translation_edit(name=None): from models.translation import Translation import urllib localeList = g._var("languages", scope="translation", default=[]) translationList = {} for language in localeList: translation = None if name: name = urllib.unquote_plus(name) translation = Translation.query.filter_by( name=urllib.unquote_plus(name), language=language ).first() or Translation(name=urllib.unquote_plus(name), language=language) if not translation: translation = Translation(language=language) translationList[language] = translation if request.method == "POST" and request.form.get("csrf_token", None): for language in localeList: translationList[language].name = request.form.get("translation_name", None) translationList[language].value = request.form.get("translation_language_" + language, None) translationList[language].save() flash(g._t("translation submit success")) return redirect(url_for("translation_index")) if name: title = g._t("edit") else: title = g._t("add") breadcrumbs = ( (g._t("administration"), url_for("administration_index")), (g._t("translations"), url_for("translation_index")), (title, "#"), ) return render_template( "administration/translation/edit.html", title=title, breadcrumbs=breadcrumbs, localeList=localeList, translationList=translationList, name=name, )
def translation_index(): from models.translation import Translation title = g._t("translations") breadcrumbs = ((g._t("administration"), url_for("administration_index")), (title, "#")) translationList = {} for translation in Translation.query.all(): if not translationList.has_key(translation.name): translationList[translation.name] = {} translationList[translation.name][translation.language] = translation.value localeList = g._var("languages", scope="translation", default=[]) return render_template( "administration/translation/index.html", title=title, breadcrumbs=breadcrumbs, translationList=translationList, localeList=localeList, )
def test_data_projects(): from models.account import Account from models.project import Project title = 'Testing | Data | Listed per-account-project membership' employees = [account for account in Account.all() if account.id.startswith('test.')] projects = [project for project in Project.all() if project.id.startswith('TEST/')] data = _test_data_menu() data = data + '<table class="table" width="100%">' roles = g._var(name='roles', scope='permissions', default={}).keys() data = data + '<tr>' data = data + '<th> </th>' for project in projects: data = data + '<th>'+project.id+'</th>' data = data + '</tr>' for employee in employees: data = data + '<tr>' data = data + '<th>'+employee.id+'</th>' for project in projects: #data = data + (project.hasMember(employee.id) and '<td class="alert alert-success">'+project.members.get(employee.id, '---')+'</td>' or '<td class="alert alert-danger">no</td>') details = {} details['class'] = project.hasMember(employee.id) and 'success' or 'danger' details['label'] = project.hasMember(employee.id) and project.members.get(employee.id, '?') or '-' details['label'] = details['label'] + '<div class="pull-right">' details['label'] = details['label'] + (app.access('project', action='read', project=project, account=employee) and '<i class="icon icon-eye-open text-info"></i> | ' or '<i style="opacity:0.2" class="icon icon-eye-open muted"></i> | ') details['label'] = details['label'] + (app.access('project', action='update', project=project, account=employee) and '<i class="icon icon-edit text-info"></i> | ' or '<i style="opacity:0.2" class="icon icon-edit muted"></i> | ') details['label'] = details['label'] + (app.access('project', action='delete', project=project, account=employee) and '<i class="icon icon-trash text-info"></i>' or '<i style="opacity:0.2" class="icon icon-trash muted"></i>') details['label'] = details['label'] + '</div>' data = data + '<td class="alert alert-'+details['class']+'">'+details['label']+'</td>' data = data + '</tr>' data = data + '</table>' data = Markup(data) return render_template('test/index.html', title=title, data=data)