How to use init_role method in molecule

Best Python code snippet using molecule_python

roles.py

Source:roles.py Github

copy

Full Screen

...25from dms.views_error import show_error26# -----------------------------------------------------27# Festlegung der Rollen und Rechte28# -----------------------------------------------------29def init_role(name):30 """ """31 perm = DmsRoles.objects.select_related().filter(name=name)[0]32 return { 'name': name,33 'description': perm.description,34 'perm_read': perm.perm_read,35 'perm_add': perm.perm_add,36 'perm_add_folderish': perm.perm_add_folderish,37 'perm_edit': perm.perm_edit,38 'perm_edit_own': perm.perm_edit_own,39 'perm_edit_folderish': perm.perm_edit_folderish,40 'perm_manage': perm.perm_manage,41 'perm_manage_own': perm.perm_manage_own,42 'perm_manage_folderish': perm.perm_manage_folderish,43 'perm_manage_site': perm.perm_manage_site,44 'perm_manage_user': perm.perm_manage_user,45 'perm_manage_user_new': perm.perm_manage_user_new46 }47the_manager = init_role(name='the_manager')48top_manager = init_role(name='top_manager')49manager = init_role(name='manager')50co_manager = init_role(name='co_manager')51worker = init_role(name='worker')52worker_reader = init_role(name='worker_reader')53worker_writer = init_role(name='worker_writer')54no_rights_mini = init_role(name='no_rights_mini')55no_rights_micro = init_role(name='no_rights_micro')56no_rights = init_role(name='no_rights')57roles = (the_manager, top_manager, manager, co_manager, worker, worker_reader, worker_writer, 58 no_rights_mini, no_rights_micro, no_rights)59# -----------------------------------------------------60# Hilfsfunktionen61# -----------------------------------------------------62def get_user_roles(username, path):63 """ liefert die Rollen, die <user> in <path> zugewiesen wurden"""64 items = User.objects.filter(username=username)65 if len(items) == 0:66 return []67 user_id = items[0].id68 n_pos = string.rfind(path, 'acl_users')69 if n_pos > 0:70 path = path[:n_pos]...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1"""Module contain function for db initializations"""2from datetime import date3import logging4from flaskr import utils5from flaskr import db6from flaskr.model import director7from flaskr.model import genre8from flaskr.model import role9from flaskr.model import user10from flaskr.model import movie11log = logging.getLogger(utils.LOGGER_NAME)12def init_db():13 """Creates tables in db"""14 db.create_all()15 log.info("Database table created")16 init_data()17def init_data():18 """Adds initial data in table"""19 if user.User.query.first() or role.Role.query.first() or director.Director.query.first():20 return21 log.info("Database seed begin")22 init_user = user.User()23 init_user.email = "admin@admin.com"24 init_user.password = "pbkdf2:sha256:260000$9gtt930HqsTDK7z6$3f562f64fb5ed9" \25 "02a3221245ebb726b9f8479884d067501f3531ac1864f69fda"26 init_role = role.Role()27 init_role.title = "Admin"28 init_user.role_id = 129 init_director = director.Director()30 init_director.first_name = "unknown"31 init_director.last_name = "unknown"32 init_director.date_of_birth = date(year=1800, month=1, day=1)33 db.session.add(init_role)34 db.session.commit()35 init_role = role.Role()36 init_role.id = 237 init_role.title = "User"38 db.session.add(init_role)39 db.session.add(init_user)40 db.session.add(init_director)41 db.session.commit()42 for i in range(1, 31):43 genre_ = genre.Genre()44 genre_.title = "genre" + str(i)45 db.session.add(genre_)46 director_ = director.Director()47 director_.first_name = "First name " + str(i)48 director_.last_name = "Last name " + str(i)49 director_.date_of_birth = date(year=2000, month=1, day=1+i)50 db.session.add(director_)51 movie_ = movie.Movie()52 movie_.title = f"Title {i + 1}"53 movie_.genre.append(genre_)54 movie_.director.append(director_)55 movie_.release_date = date(year=2000, month=10, day=i)56 movie_.poster = "Poster"57 movie_.rate = i % 11 if i % 11 != 0 else 1058 movie_.description = f"Description {i}"59 movie_.user_id = 160 db.session.add(movie_)61 db.session.commit()...

Full Screen

Full Screen

manage.py

Source:manage.py Github

copy

Full Screen

...29 traceback.print_exc()30 db.create_all()313233def init_role():34 role = db.session.query(Role).filter(Role.name=='管理员').first()35 if role:36 return True37 role = Role(name='管理员')38 db.session.add(role)39 db.session.commit()404142def init_admin_user():43 role = db.session.query(Role).first()44 if not role:45 print('no role init')46 raise Exception('no role init')4748 user = User(name='admin')49 db.session.flush()50 user_role = UserRole(user_id=user.id, role_id=role.id)515253@manager.command54def init():5556 try:5758 # 1. 创建数据库59 init_database_and_tables()6061 # 2. 初始化用户角色62 init_role()6364 # 3.创建管理员用户65 init_admin_user()6667 except:6869 traceback.print_exc()70 db.session.rollback()7172if __name__ == '__main__': ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful