def test_rule_macro(): app, db, admin = setup() Model1, _ = create_models(db) db.create_all() view = CustomModelView( Model1, db.session, create_template="macro.html", form_create_rules=( rules.Macro("test", arg="foobar"), rules.Macro("test_lib.another_test"), ), ) admin.add_view(view) client = app.test_client() rv = client.get("/admin/model1/new/") eq_(rv.status_code, 200) data = rv.data.decode("utf-8") ok_("Value = foobar" in data) ok_("Hello another_test" in data)
class ConferenceUser(UserModelView, ConferenceAdmin): column_list = ['number', 'name', 'is_public', 'is_locked', 'participant_count', 'invited_participant_count'] form_create_rules = form_edit_rules = [ rules.FieldSet( ('number', 'name', 'conference_profile'), _('Basic Settings') ), rules.FieldSet( ('is_public', 'public_participant_profile'), _('Open Access') ), rules.FieldSet( (rules.Macro('conference_participants_link'),), _('Participants') ), ] @expose('/details/') def details_view(self): conf = Conference.query.get_or_404(request.args.get('id', 0)) self._template_args['confbridge_participants'] = \ confbridge_list_participants(conf.number) self._template_args['confbridge'] = confbridge_get(conf.number) return super(ModelView, self).details_view()
def test_rule_container(): app, db, admin = setup() Model1, _ = create_models(db) db.create_all() view = CustomModelView(Model1, db.session, create_template='macro.html', form_create_rules=(rules.Container( 'wrap', rules.Macro('test_lib.another_test')), )) admin.add_view(view) client = app.test_client() rv = client.get('/admin/model1/new/') eq_(rv.status_code, 200) data = rv.data.decode('utf-8') pos1 = data.find('<wrapper>') pos2 = data.find('another_test') pos3 = data.find('</wrapper>') ok_(pos1 != -1) ok_(pos2 != -1) ok_(pos3 != -1) ok_(pos1 < pos2 < pos3)
def test_rule_container(): app, db, admin = setup() Model1, _ = create_models(db) db.create_all() view = CustomModelView( Model1, db.session, create_template="macro.html", form_create_rules=(rules.Container( "wrap", rules.Macro("test_lib.another_test")), ), ) admin.add_view(view) client = app.test_client() rv = client.get("/admin/model1/new/") eq_(rv.status_code, 200) data = rv.data.decode("utf-8") pos1 = data.find("<wrapper>") pos2 = data.find("another_test") pos3 = data.find("</wrapper>") ok_(pos1 != -1) ok_(pos2 != -1) ok_(pos3 != -1) ok_(pos1 < pos2 < pos3)
def test_rule_macro(): app, db, admin = setup() Model1, _ = create_models(db) db.create_all() view = CustomModelView(Model1, db.session, create_template='macro.html', form_create_rules=(rules.Macro('test', arg='foobar'), rules.Macro('test_lib.another_test'))) admin.add_view(view) client = app.test_client() rv = client.get('/admin/model1/new/') eq_(rv.status_code, 200) data = rv.data.decode('utf-8') ok_('Value = foobar' in data) ok_('Hello another_test' in data)
class ConferenceAdmin(MyModelView, AuthBaseView): """ This is active conference started in a room. """ form_base_class = ConferenceForm can_view_details = True details_template = 'conference_details.html' edit_template = 'conference_edit.html' create_template = 'conference_create.html' column_list = [ 'number', 'name', 'is_public', 'is_locked', 'participant_count', 'invited_participant_count', 'user' ] column_labels = { 'number': _('Conference Number'), 'name': _('Conference Name'), 'participant_count': _('Participants'), 'invited_participant_count': _('Invited Participants'), 'online_participant_count': _('Participants Online'), 'is_locked': _('Locked'), 'is_public': _('Public'), 'conference_profile': _('Conference Profile'), 'public_participant_profile': _('Public Participant Profile'), } form_create_rules = form_edit_rules = [ rules.FieldSet(('number', 'name', 'conference_profile'), _('Basic Settings')), rules.FieldSet(('is_public', 'public_participant_profile', 'user'), _('Open Access')), rules.FieldSet((rules.Macro('conference_participants_link'), ), _('Participants')), ] column_formatters = { 'legend': lambda v, c, m, n: legend_formatter(v, c, m, n), } form_args = { 'number': dict(validators=[Required(), is_number]), 'name': dict(validators=[Required()]), 'conference_profile': dict(validators=[Required()]), 'public_participant_profile': dict(validators=[Required()]), } def is_accessible(self): return super( AuthBaseView, self).is_accessible() and current_user.has_role('admin') or False @expose('/details/') def details_view(self): conf = Conference.query.get_or_404(request.args.get('id', 0)) self._template_args['confbridge_participants'] = \ confbridge_list_participants(conf.number) self._template_args['confbridge'] = confbridge_get(conf.number) return super(ModelView, self).details_view() @expose('/contacts/', methods=['POST']) def add_contacts(self): if request.method == 'POST': if not request.form.get('conference') or not request.form.get( 'profile'): flash('You must select Conference and Profile') if current_user.has_role('admin'): return redirect(url_for('contact_admin.index_view')) else: return redirect(url_for('contact_user.index_view')) conference = Conference.query.filter_by( id=request.form['conference']).first_or_404() profile = ParticipantProfile.query.filter_by( id=request.form['profile']).first_or_404() contacts = Contact.query.filter( Contact.id.in_(request.form['ids'].split(','))) for c in contacts: if Participant.query.filter_by(phone=c.phone, conference=conference).first(): flash(gettext('%(contact)s is already there.', contact=c)) continue p = Participant(phone=c.phone, name=c.name, user=current_user, profile=profile, conference=conference) flash(gettext('%(contact)s added.', contact=c)) db.session.add(p) db.session.commit() return redirect(url_for('.edit_view', id=conference.id)) @expose('/<int:conf_id>/invite_guest') def invite_guest(self, conf_id): conf = Conference.query.get_or_404(conf_id) phone = request.args.get('phone', None) if phone and phone.isdigit(): originate(conf.number, phone, bridge_options=conf.conference_profile. get_confbridge_options(), user_options=conf.public_participant_profile. get_confbridge_options()) flash( gettext('Number %(phone)s is called for conference.', phone=phone)) time.sleep(1) return redirect(url_for('.details_view', id=conf_id)) @expose('/<int:conf_id>/invite_participants') def invite_participants(self, conf_id): conf = Conference.query.get_or_404(conf_id) conf.invite_participants() flash(gettext('All the participants where invited to the conference')) time.sleep(1) return redirect(url_for('.details_view', id=conf.id)) @expose('/kick/<conf_id>') @expose('/kick/<conf_id>/channel/<path:channel>') def kick(self, conf_id, channel=None): conf = Conference.query.filter_by(id=conf_id).first_or_404() if channel: confbridge_kick(conf.number, channel) msg = gettext('Channel %(channel)s is kicked.', channel=channel) flash(msg) conf.log(msg) else: confbridge_kick_all(conf.number) msg = gettext( 'All participants have been kicked from the conference.') conf.log(msg) flash(msg) sse_notify(conf.id, 'update_participants') time.sleep(1) return redirect(url_for('.details_view', id=conf.id)) @expose('/mute/<conf_id>') @expose('/mute/<conf_id>/channel/<path:channel>') def mute(self, conf_id, channel=None): conf = Conference.query.get_or_404(conf_id) if channel: confbridge_mute(conf.number, channel) msg = gettext('Participant %(channel)s muted.', channel=channel) flash(msg) conf.log(msg) else: # Mute all for p in confbridge_list_participants(conf.number): confbridge_mute(conf.number, p['channel']) msg = gettext('Conference muted.') flash(msg) conf.log(msg) sse_notify(conf.id, 'update_participants') time.sleep(1) return redirect(url_for('.details_view', id=conf_id)) @expose('/unmute/<conf_id>') @expose('/unmute/<conf_id>/channel/<path:channel>') def unmute(self, conf_id, channel=None): conf = Conference.query.get_or_404(conf_id) if channel: confbridge_unmute(conf.number, channel) msg = gettext('Participant %(channel)s unmuted.', channel=channel) flash(msg) conf.log(msg) else: # Mute all for p in confbridge_list_participants(conf.number): confbridge_unmute(conf.number, p['channel']) msg = gettext('Conference unmuted.') flash(msg) conf.log(msg) sse_notify(conf.id, 'update_participants') time.sleep(1) return redirect(url_for('.details_view', id=conf_id)) @expose('/<int:conf_id>/record_start') def record_start(self, conf_id): conf = Conference.query.get_or_404(conf_id) confbridge_record_start(conf.number) msg = gettext('The conference recording has been started.') flash(msg) conf.log(msg) return redirect(url_for('.details_view', id=conf_id)) @expose('/<int:conf_id>/record_stop') def record_stop(self, conf_id): conf = Conference.query.get_or_404(conf_id) confbridge_record_stop(conf.number) msg = gettext('The conference recording has been stopped.') flash(msg) conf.log(msg) return redirect(url_for('.details_view', id=conf_id)) @expose('/<int:conf_id>/lock') def lock(self, conf_id): conf = Conference.query.get_or_404(conf_id) confbridge_lock(conf.number) msg = gettext('The conference has been locked.') flash(msg) conf.log(msg) sse_notify(conf.id, 'update_participants') time.sleep(1) return redirect(url_for('.details_view', id=conf_id)) @expose('/<int:conf_id>/unlock') def unlock(self, conf_id): conf = Conference.query.get_or_404(conf_id) confbridge_unlock(conf.number) msg = gettext('The conference has been unlocked.') flash(msg) conf.log(msg) sse_notify(conf.id, 'update_participants') time.sleep(1) return redirect(url_for('.details_view', id=conf_id)) @expose('/<int:conf_id>/clear_log') def clear_log(self, conf_id): logs = ConferenceLog.query.filter_by(conference_id=conf_id) for log in logs: db.session.delete(log) db.session.commit() return redirect(url_for('.details_view', id=conf_id))