本文整理汇总了Python中models.roles.Roles类的典型用法代码示例。如果您正苦于以下问题:Python Roles类的具体用法?Python Roles怎么用?Python Roles使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Roles类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: init_template_values
def init_template_values(self, environ, prefs=None):
"""Initializes template variables with common values."""
self.template_value[COURSE_INFO_KEY] = environ
self.template_value[
'page_locale'] = self.app_context.get_current_locale()
self.template_value['html_hooks'] = HtmlHooks(
self.get_course(), prefs=prefs)
self.template_value['is_course_admin'] = Roles.is_course_admin(
self.app_context)
self.template_value['can_see_drafts'] = (
courses_module.courses.can_see_drafts(self.app_context))
self.template_value[
'is_read_write_course'] = self.app_context.fs.is_read_write()
self.template_value['is_super_admin'] = Roles.is_super_admin()
self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
self.template_value['left_links'] = []
for func in self.LEFT_LINKS:
self.template_value['left_links'].extend(func(self.app_context))
self.template_value['right_links'] = []
for func in self.RIGHT_LINKS:
self.template_value['right_links'].extend(func(self.app_context))
if not prefs:
prefs = models.StudentPreferencesDAO.load_or_create()
self.template_value['student_preferences'] = prefs
if (Roles.is_course_admin(self.app_context) and
not appengine_config.PRODUCTION_MODE and
prefs and prefs.show_jinja_context):
@jinja2.contextfunction
def get_context(context):
return context
self.template_value['context'] = get_context
if CAN_PUT_DEBUG_INFO_INTO_PAGES.value:
self.template_value['debug_info'] = self.debug_info()
self.template_value[
'extra_global_css_urls'] = self.EXTRA_GLOBAL_CSS_URLS
self.template_value[
'extra_global_js_urls'] = self.EXTRA_GLOBAL_JS_URLS
# Common template information for the locale picker (only shown for
# user in session)
can_student_change_locale = (
self.get_course().get_course_setting('can_student_change_locale')
or self.get_course().app_context.can_pick_all_locales())
if can_student_change_locale:
self.template_value['available_locales'] = [
{
'name': locales.get_locale_display_name(loc),
'value': loc
} for loc in self.app_context.get_allowed_locales()]
self.template_value['locale_xsrf_token'] = (
XsrfTokenManager.create_xsrf_token(
StudentLocaleRESTHandler.XSRF_TOKEN_NAME))
self.template_value['selected_locale'] = self.get_locale_for(
self.request, self.app_context, prefs=prefs)
开发者ID:ehiller,项目名称:course-builder,代码行数:59,代码来源:utils.py
示例2: get_public_courses
def get_public_courses(self):
"""Get all the public courses."""
public_courses = []
for course in sites.get_all_courses():
if ((course.now_available and Roles.is_user_whitelisted(course))
or Roles.is_course_admin(course)):
public_courses.append(course)
return public_courses
开发者ID:CSCI1200Course,项目名称:csci1200OnlineCourse,代码行数:8,代码来源:student.py
示例3: get_template
def get_template(self, template_file, additional_dirs=None):
"""Computes location of template files for the current namespace."""
self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
self.template_value["is_course_admin"] = Roles.is_course_admin(self.app_context)
self.template_value["is_super_admin"] = Roles.is_super_admin()
self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
return self.app_context.get_template_environ(
self.template_value[COURSE_INFO_KEY]["course"]["locale"], additional_dirs
).get_template(template_file)
开发者ID:sesamesushi,项目名称:satisrevude,代码行数:9,代码来源:utils.py
示例4: get_template
def get_template(self, template_file, additional_dirs=None):
"""Computes location of template files for the current namespace."""
self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
self.template_value["is_course_admin"] = Roles.is_course_admin(self.app_context)
self.template_value["is_read_write_course"] = self.app_context.fs.is_read_write()
self.template_value["is_super_admin"] = Roles.is_super_admin()
self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
template_environ = self.app_context.get_template_environ(
self.template_value[COURSE_INFO_KEY]["course"]["locale"], additional_dirs
)
template_environ.filters["gcb_tags"] = jinja_utils.get_gcb_tags_filter(self)
return template_environ.get_template(template_file)
开发者ID:nicholaschris,项目名称:massive-wight,代码行数:12,代码来源:utils.py
示例5: get
def get(self):
param_map = {}
for k in self.request.arguments():
param_map[k] = self.request.get(k)
client_id = param_map.get('client_id', 0)
logging.debug("vanilla request: " + str(param_map))
user = users.get_current_user()
if Roles.is_course_admin(self.app_context):
role= "administrator"
else:
role="member"
logging.debug(str(user))
if user:
student = Student.get_enrolled_student_by_email(user.email())
user = {
"name": student.name,
"email": user.email(),
"uniqueid": user.user_id(),
"photourl": "",
}
course = self.app_context.get_environ()['course']
client_id = course['VANILLA_CLIENT_ID']
secret_key = course['VANILLA_SECRET_KEY']
jsconn_str = get_jsconnect_string(user, param_map, client_id, secret_key)
logging.debug("mooc-ed response: " + jsconn_str)
self.response.out.write(jsconn_str)
开发者ID:barkinet,项目名称:coursebuilder_plugin_vanilla,代码行数:34,代码来源:vanilla.py
示例6: get
def get(self):
if not Roles.is_course_admin(self.app_context):
self.error(403)
self.response.write("NO")
return
nav = self._get_nav()
if not nav:
self.render_choices_page()
return
query_class = analytics_queries.get(nav['query'], None)
if not query_class:
logging.warn("Unrecognized query")
self.abort(404, "I couldn't find the query that you requested.")
try:
query = query_class(self)
except ValueError as e:
self.render_choices_page(error=e.message)
return
if nav['view'] == 'csv':
self.render_as_csv(query.fields, query.run())
elif nav['view'] == 'debug':
i = query.run()
for x in i:
pass
else:
iterator = query.run()
if hasattr(query_class, 'htmlize_row'):
iterator = [query.htmlize_row(r) for r in iterator]
self.render_as_table(query.fields, iterator)
开发者ID:twiffy,项目名称:eabooc,代码行数:33,代码来源:student_csv.py
示例7: get_schema
def get_schema(cls):
"""Return the InputEx schema for the roles editor."""
schema = schema_fields.FieldRegistry(
'Role', description='role')
schema.add_property(schema_fields.SchemaField(
'version', '', 'string', optional=True, hidden=True))
schema.add_property(schema_fields.SchemaField(
'name', 'Name', 'string', optional=False,
description=messages.ROLE_NAME_DESCRIPTION))
schema.add_property(schema_fields.SchemaField(
'description', 'Description', 'text', optional=True,
description=messages.ROLE_DESCRIPTION_DESCRIPTION))
# TODO(gdejonghe) Use user.id instead of user.email
schema.add_property(schema_fields.SchemaField(
'users', 'User Emails', 'text',
description=messages.ROLE_USER_EMAILS_DESCRIPTION))
subschema = schema.add_sub_registry('modules', 'Permission Modules')
for module in Roles.get_modules():
cls._add_module_permissions_schema(subschema, module.name)
cls._add_module_permissions_schema(subschema, cls.INACTIVE_MODULES)
return schema
开发者ID:2023SS,项目名称:coursebuilder-core,代码行数:25,代码来源:role_editor.py
示例8: get
def get(self):
"""Handles GET requests."""
if not Roles.is_course_admin(self.app_context):
self.redirect('/preview')
return
student = self.personalize_page_and_get_enrolled(
supports_transient_student=True)
if not student:
return
else:
# Set template value for progress bar that shows on the top navigation(header.html)
total_progress = (self.get_progress_tracker().get_overall_progress_score(student))
self.template_value['progress_value'] = total_progress.get('progress_score', 0)
self.template_value['complete_value'] = total_progress.get('completed_score', 0)
self.template_value['percentage'] = total_progress.get('percentage', '')
# Set template value for Google Community ID
self.set_google_community_template_value()
all_students = self.get_students()
i = 0
for s in all_students:
i = i + 1
self.template_value['navbar'] = {'students': True}
self.template_value['total_students'] = i
self.template_value['students_data'] = all_students
self.render('students.html')
开发者ID:cglmoocs,项目名称:cgl-mooc-builder,代码行数:28,代码来源:utils.py
示例9: insert
def insert(self, name):
# Do we want page markup to permit course admins to edit hooks?
show_admin_content = False
if (self.prefs and self.prefs.show_hooks and
Roles.is_course_admin(self.course.app_context)):
show_admin_content = True
if self.course.version == courses.CourseModel12.VERSION:
show_admin_content = False
# Look up desired content chunk in course.yaml dict/sub-dict.
content = ''
environ = self.course.app_context.get_environ()
for part in name.split(':'):
if part in environ:
item = environ[part]
if type(item) == str:
content = item
else:
environ = item
if show_admin_content and not self._has_visible_content(content):
content += name
# Add the content to the page in response to the hook call.
hook_div = safe_dom.Element('div', className='gcb-html-hook',
id=re.sub('[^a-zA-Z-]', '-', name))
hook_div.add_child(tags.html_to_safe_dom(content, self))
# Mark up content to enable edit controls
if show_admin_content:
hook_div.add_attribute(onclick='gcb_edit_hook_point("%s")' % name)
hook_div.add_attribute(className='gcb-html-hook-edit')
return jinja2.Markup(hook_div.sanitized)
开发者ID:Rosebotics,项目名称:RoseboticsWeb,代码行数:32,代码来源:utils.py
示例10: get_template
def get_template(self, template_file, additional_dirs=None):
"""Computes location of template files for the current namespace."""
self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
self.template_value["is_course_admin"] = Roles.is_course_admin(self.app_context)
self.template_value["is_read_write_course"] = self.app_context.fs.is_read_write()
self.template_value["is_super_admin"] = Roles.is_super_admin()
self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
template_environ = self.app_context.get_template_environ(
self.template_value[COURSE_INFO_KEY]["course"]["locale"], additional_dirs
)
template_environ.filters["gcb_tags"] = jinja_utils.get_gcb_tags_filter(self)
course = sites.get_course_for_current_request()
if course.get_slug().split("_")[-1] == "DFR":
self.template_value["gDefier_enabled"] = True
return template_environ.get_template(template_file)
开发者ID:diego-G,项目名称:gdefier,代码行数:17,代码来源:utils.py
示例11: get_template
def get_template(self, template_file, additional_dirs=None):
"""Computes location of template files for the current namespace."""
self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
self.template_value['is_course_admin'] = Roles.is_course_admin(
self.app_context)
self.template_value[
'is_read_write_course'] = self.app_context.fs.is_read_write()
self.template_value['is_super_admin'] = Roles.is_super_admin()
self.template_value['ga_analytics_key'] = GOOGLE_ANALYTICS_KEY.value
self.template_value['ga_analytics_site'] = self.request.host
self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
environ = self.app_context.get_template_environ(
self.template_value[COURSE_INFO_KEY]['course']['locale'],
additional_dirs
)
self.mess_with_template_environ(environ)
return environ.get_template(template_file)
开发者ID:twiffy,项目名称:eabooc,代码行数:17,代码来源:utils.py
示例12: get
def get(self):
if not(Roles.is_course_admin(self.app_context)):
self.redirect("preview")
self.response.headers['Content-type'] = 'text/csv'
self.response.headers['Content-disposition'] = 'attachment; filename=students.csv'
course = self.get_course()
assessments=[]
for unit in course.get_units():
if (unit.type=="A"):
assessments.append(str(unit.unit_id))
writer = UnicodeWriter(self.response.out)
keys = Student.all(keys_only=True).run()
rows=[]
for key in keys:
student=Student.get_by_key_name(key.name())
rec={"email": key.name(), "name": student.name, "enrolled": unicode(student.is_enrolled), "dateEnrolled": unicode(student.enrolled_on) }
if (student.scores):
scores=json.loads(student.scores)
for assessmentName, score in scores.iteritems():
rec[assessmentName]=str(score)
rows.append(rec)
headerRow = ["Email", "Name", "Is Enrolled", "Enrolled On"]
for assessmentName in assessments:
headerRow.append(course.find_unit_by_id(assessmentName).title)
writer.writerow(headerRow)
for row in rows:
renderedRow=[row["email"],row["name"],row["enrolled"],row["dateEnrolled"]]
for assessmentName in assessments:
if (assessmentName in row):
renderedRow.append(row[assessmentName])
else:
renderedRow.append("")
writer.writerow(renderedRow)
开发者ID:graemian,项目名称:ami-mooc-pilot,代码行数:58,代码来源:utils.py
示例13: get
def get(self):
user = self.personalize_page_and_get_enrolled()
if not user:
return
if not Roles.is_course_admin(self.app_context):
self.abort(403)
self.template_value['student_count'] = get_student_count()
self.template_value['navbar'] = {'booctools': True}
self.render('booctools.html')
开发者ID:twiffy,项目名称:eabooc,代码行数:9,代码来源:booctools.py
示例14: _update_dict_with_permissions
def _update_dict_with_permissions(self, dictionary):
app_context = self.get_course().app_context
modules = {}
for (module, callback) in Roles.get_permissions():
modules[module.name] = []
for (permission, description) in callback(app_context):
modules[module.name].append(
self._generate_permission(permission, description, False))
dictionary['modules'] = modules
return dictionary
开发者ID:kingctan,项目名称:course-builder,代码行数:10,代码来源:role_editor.py
示例15: get_view
def get_view(self):
if not Roles.is_course_admin(self.app_context):
self.abort(403)
job_id = self.request.GET.get('job_id', None)
if not job_id:
self.abort(404)
result = TableMakerResult(job_id)
fields = result.fields
self.render_as_table(fields, result)
开发者ID:twiffy,项目名称:eabooc,代码行数:11,代码来源:student_csv.py
示例16: post_save
def post_save(self):
if not Roles.is_course_admin(self.app_context):
self.abort(403, 'You are not an admin :(')
user = self.personalize_page_and_get_enrolled()
student_email = self.request.GET.get('email', None)
if not student_email:
self.abort(404, 'email= parameter required')
student = Student.get_enrolled_student_by_email(student_email)
if not student:
self.abort(404, Markup('Could not find a student with email "%s"') % student_email)
badge_slug = custom_badge_name(student)
badge = Badge.get_or_insert(badge_slug)
badge_form = BadgeForm(self.request.POST, badge)
comments_form = CommentsForm(self.request.POST)
if not (badge_form.validate() and comments_form.validate()):
self.render_edit(badge_form, comments_form)
return
comments_form.validate()
reviewer = Student.get_by_email(comments_form.review_source.data)
if not reviewer:
comments_form.review_source.errors.append("Could not find a user with that e-mail address")
self.render_edit(badge_form, comments_form)
return
page = WikiPage.get_page(student, unit=UNIT_NUMBER)
if not page:
self.abort(404, Markup('Could not find unit %d wikifolio for student "%s"') % (UNIT_NUMBER, student_email))
old_reviews = Annotation.reviews(whose=student, unit=UNIT_NUMBER).run()
db.delete(old_reviews)
Annotation.review(page, who=reviewer, text=comments_form.public_comments.data)
if not Annotation.endorsements(what=page, who=user).count(limit=1):
Annotation.endorse(page, who=user, optional_done=True)
badge_form.populate_obj(badge)
badge.put()
report = PartReport.on(student, self.get_course(), 4, force_re_run=True, put=False)
for rep in report.unit_reports:
rep._run()
rep.put()
report.slug = badge_slug
report.put()
assertion = Badge.issue(badge, student, put=False)
assertion.evidence = urljoin(self.request.host_url, '/badges/evidence?id=%d' % report.key().id())
assertion.put()
self.response.write(
Markup("Issued badge %s to %s, evidence %s") % (
badge.key().name(), student_email, assertion.evidence))
开发者ID:twiffy,项目名称:eabooc,代码行数:54,代码来源:custom_badge.py
示例17: initialize_page_and_get_user
def initialize_page_and_get_user(self):
"""Add basic fields to template and return user."""
self.template_values['course_info'] = Courses.COURSE_TEMPLATE_DICT
self.template_values['course_info']['course'] = {'locale': LOCALE}
user = users.get_current_user()
if not user:
self.template_values['loginUrl'] = users.create_login_url('/')
else:
self.template_values['email'] = user.email()
self.template_values['is_super_admin'] = Roles.is_super_admin()
self.template_values['logoutUrl'] = users.create_logout_url('/')
return user
开发者ID:Domofera,项目名称:Domofera_MOOC,代码行数:12,代码来源:student.py
示例18: test_editor_hooks
def test_editor_hooks(self):
module1 = Module('module1', '', [], [])
module2 = Module('module2', '', [], [])
module3 = Module('module3', '', [], [])
module4 = Module('module4', '', [], [])
Roles.register_permissions(module1, lambda unused: [
Permission('permissiona', 'a'), Permission('permissionb', 'b')])
Roles.register_permissions(module2, lambda unused: [
Permission('permissionc', 'c'), Permission('permissiond', 'd')])
Roles.register_permissions(module4, lambda unused: [
Permission('permissiong', 'g'), Permission('permissiond', 'h')])
handler = RoleRESTHandler()
handler.course = self.course
datastore_permissions = {
module1.name: ['permission', 'permissiona', 'permissionb'],
module2.name: ['permissionc', 'permissiond'],
module3.name: ['permissione', 'permissionf']
}
datastore_dict = {
'name': 'Role Name',
'users': ['[email protected]', '[email protected]'],
'permissions': datastore_permissions
}
editor_dict = handler.transform_for_editor_hook(datastore_dict)
self.assertEquals(editor_dict['name'], 'Role Name')
self.assertEquals(editor_dict['users'], '[email protected], [email protected]')
modules = editor_dict['modules']
# Test registered assigned permission
permissionc = modules[module2.name][0]
self.assertEquals(permissionc['assigned'], True)
self.assertEquals(permissionc['name'], 'permissionc')
self.assertEquals(permissionc['description'], 'c')
# Test unregistered module with assigned permission
permissionsf = modules[RoleRESTHandler.INACTIVE_MODULES][1]
self.assertEquals(permissionsf['assigned'], True)
self.assertEquals(permissionsf['name'], 'permissionf')
self.assertEquals(
permissionsf['description'],
'This permission was set by the module "module3" which is '
'currently not registered.'
)
# Test registered module with assigned unregistered permission
permission = modules[module1.name][2]
self.assertEquals(permission['assigned'], True)
self.assertEquals(permission['name'], 'permission')
self.assertEquals(
permission['description'],
'This permission is currently not registered.'
)
# Test registered unassigned permissions
permissiong = editor_dict['modules'][module4.name][0]
self.assertEquals(permissiong['assigned'], False)
self.assertEquals(permissiong['name'], 'permissiong')
self.assertEquals(permissiong['description'], 'g')
# Call the hook which gets called when saving
new_datastore_dict = handler.transform_after_editor_hook(datastore_dict)
# If original dict matches new dict then both hooks work correctly
self.assertEquals(datastore_dict, new_datastore_dict)
开发者ID:jomolinare,项目名称:course-builder,代码行数:60,代码来源:modules_dashboard.py
示例19: get_template
def get_template(self, template_file, additional_dir=None):
"""Computes location of template files for the current namespace."""
self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
self.template_value['is_course_admin'] = Roles.is_course_admin(
self.app_context)
self.template_value['is_super_admin'] = Roles.is_super_admin()
self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
template_dir = self.app_context.get_template_home()
dirs = [template_dir]
if additional_dir:
dirs += additional_dir
jinja_environment = jinja2.Environment(
extensions=['jinja2.ext.i18n'],
loader=jinja2.FileSystemLoader(dirs))
jinja_environment.install_gettext_translations(i18n)
locale = self.template_value[COURSE_INFO_KEY]['course']['locale']
i18n.get_i18n().set_locale(locale)
return jinja_environment.get_template(template_file)
开发者ID:ksh,项目名称:gpitraining,代码行数:22,代码来源:utils.py
示例20: post_start
def post_start(self):
if not Roles.is_course_admin(self.app_context):
self.abort(403)
form = self.NavForm(self.request.POST)
if not form.validate():
self.render_form(form)
return
query_class = mapper_queries[form.query.data]
mapper = query_class(course=self.get_course(), unit=form.unit.data, host_url=self.request.host_url)
assert isinstance(mapper, TableMakerMapper)
job_id = mapper.job_id
deferred.defer(mapper.run, batch_size=50)
self.redirect(self._action_url('watch', job_id=job_id))
开发者ID:twiffy,项目名称:eabooc,代码行数:15,代码来源:student_csv.py
注:本文中的models.roles.Roles类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论