def resource_page(self, context): self.load_visit(context) page_context = self.new_page_context(context) if context.group is None: # we require a group data = self.render_template(context, 'notices/no_context.html', page_context) context.set_status(200) return self.html_response(context, data) notices = [] with context.group['Notices'].open() \ as collection: collection.set_orderby( odata.Parser('Updated desc').parse_orderby_option()) collection.set_expand({'User': None}) for entity in collection.itervalues(): notice = {} user = entity['User'].get_entity() can_edit = False can_delete = False logging.debug("OwnerID: %s", user['UserID'].value) logging.debug("UserID: %s", context.user['UserID'].value if context.user else "None") logging.debug("Permissions: %i", context.permissions) if (context.user and context.user == user): can_edit = True can_delete = True elif (context.permissions & self.WRITE_PERMISSION): can_delete = True notice['title'] = entity['Title'].value notice['description'] = entity['Description'].value notice['owner'] = self.get_user_display_name(context, user) notice['updated'] = int( entity['Updated'].value.with_zone(0).get_unixtime() * 1000) - self.js_origin notice['can_edit'] = can_edit logging.debug('ID = %s', odata.FormatURILiteral(entity['ID'])) notice['edit_link_attr'] = ( 'edit?id=%s' % odata.FormatURILiteral(entity['ID'])) notice['can_delete'] = can_delete notice['delete_link_attr'] = ( 'delete?id=%s' % odata.FormatURILiteral(entity['ID'])) notices.append(notice) page_context['notices'] = notices title = "this page" if context.group is not None: title = context.group['Title'].value page_context['course_name'] = title data = self.render_template(context, 'notices/index.html', page_context) context.set_status(200) return self.html_response(context, data)
def consumers_page(self, context): page_context = self.new_page_context(context) # add errors errors = set(('duplicate_key', )) query = context.get_query() error = query.get('error', '') for e in errors: page_context[e] = (e == error) owner = context.session.get_owner() if owner is None: # we require an owner to be logged in raise wsgi.PageNotAuthorized page_context['user_name'] = owner['FullName'].value silo = owner['Silo'].get_entity() page_context['silo'] = silo consumer_list = [] with silo['Consumers'].open() as collection: collection.set_orderby( odata.Parser('Handle asc').parse_orderby_option()) for consumer in collection.itervalues(): citem = {} consumer = lti.ToolConsumer(consumer, self.app_cipher) query = urllib.urlencode({ 'cid': odata.ODataURI.format_literal(consumer.entity['ID']) }) citem['consumer'] = consumer citem['cedit_link'] = xml.escape_char_data7( 'edit?' + query, True) citem['cdel_link'] = xml.escape_char_data7( 'del?' + query, True) consumer_list.append(citem) query = urllib.urlencode( {'silo': odata.ODataURI.format_literal(silo['ID'])}) page_context['cadd_link'] = xml.escape_char_data7( 'add?' + query, True) page_context['consumers'] = consumer_list page_context[self.csrf_token] = context.session.sid() data = self.render_template(context, 'consumers/index.html', page_context) context.set_status(200) return self.html_response(context, data)