def _getHostEntries(self, entity, params, prefix): """Returns a list with menu items for program host. Args: entity: program entity to get the entries for params: view specific params prefix: module prefix for the program entity """ items = [] # add link to edit Program Profile items += [(redirects.getEditRedirect(entity, params), 'Edit Program Profile', 'any_access')] # add link to edit Program Timeline items += [ (redirects.getEditRedirect(entity, {'url_name': prefix + '/timeline'}), "Edit Program Timeline", 'any_access') ] # add link to create a new Program Document items += [ (redirects.getCreateDocumentRedirect(entity, params['document_prefix']), "Create a New Document", 'any_access') ] # add link to list all Program Document items += [ (redirects.getListDocumentsRedirect(entity, params['document_prefix']), "List Documents", 'any_access') ] # add link to list all participants items += [(redirects.getListParticipantsRedirect(entity, params), "List Participants", 'any_access')] # add link to Manage Statistics items += [(statistic_redirects.getManageRedirect(entity, params), 'Manage Statistics', 'any_access')] org_app_logic = params['org_app_logic'] org_app_survey = org_app_logic.getForProgram(entity) # add link to create/edit OrgAppSurvey items += [(redirects.getCreateSurveyRedirect(entity, params['document_prefix'], prefix + '/org_app'), 'Edit Org Application Survey', 'any_access')] if org_app_survey: # add link to Review Org Applications items += [(redirects.getReviewOverviewRedirect( org_app_survey, params['org_app_view'].getParams()), 'Review Organization Applications', 'any_access')] return items
def _getHostEntries(self, entity, params, prefix): """Returns a list with menu items for program host. Args: entity: program entity to get the entries for params: view specific params prefix: module prefix for the program entity """ items = [] # add link to edit Program Profile items += [(redirects.getEditRedirect(entity, params), 'Edit Program Profile', 'any_access')] # add link to edit Program Timeline items += [(redirects.getEditRedirect(entity, {'url_name': prefix + '/timeline'}), "Edit Program Timeline", 'any_access')] # add link to create a new Program Document items += [(redirects.getCreateDocumentRedirect( entity, params['document_prefix']), "Create a New Document", 'any_access')] # add link to list all Program Document items += [(redirects.getListDocumentsRedirect( entity, params['document_prefix']), "List Documents", 'any_access')] # add link to list all participants items += [(redirects.getListParticipantsRedirect(entity, params), "List Participants", 'any_access')] # add link to Manage Statistics items += [(statistic_redirects.getManageRedirect(entity, params), 'Manage Statistics', 'any_access')] org_app_logic = params['org_app_logic'] org_app_survey = org_app_logic.getForProgram(entity) # add link to create/edit OrgAppSurvey items += [(redirects.getCreateSurveyRedirect( entity, params['document_prefix'], prefix + '/org_app'), 'Edit Org Application Survey','any_access')] if org_app_survey: # add link to Review Org Applications items += [(redirects.getReviewOverviewRedirect( org_app_survey, params['org_app_view'].getParams()), 'Review Organization Applications', 'any_access')] return items
def updatePublicContext(self, context, entity, params): """Updates the context for the public page with information from the entity. Args: context: the context that should be updated entity: a student proposal_entity used to set context params: dict with params for the view using this context """ from soc.logic.models.review import logic as review_logic from soc.logic.models.review_follower import logic as review_follower_logic student_entity = entity.scope context['student'] = student_entity context['student_name'] = student_entity.name() user_entity = user_logic.logic.getForCurrentAccount() # check if the current user is the student if user_entity.key() == student_entity.user.key(): # show the proposal edit link context['edit_link'] = redirects.getEditRedirect(entity, params) # check if the current user is subscribed to this proposal's public reviews fields = {'user': user_entity, 'scope': entity, 'subscribed_public': True} context['is_subscribed'] = review_follower_logic.getForFields(fields, unique=True) context['public_reviews'] = review_logic.getReviewsForEntity(entity, is_public=True, order=['created'])
def _public(self, request, entity, context): """Performs any processing needed for the Document's public page. For args see base.View._public(). """ # check if the current user is allowed to visit the edit page rights = self._params['rights'] allowed_to_edit = False try: # use the IsDocumentWritable check because we have no django args rights.checkIsDocumentWritable( { 'key_name': entity.key().name(), 'prefix': entity.prefix, 'scope_path': entity.scope_path, 'link_id': entity.link_id }, 'key_name') allowed_to_edit = True except: pass if allowed_to_edit: # add the document edit redirect to the context context['edit_redirect'] = redirects.getEditRedirect( entity, {'url_name': 'document'}) return super(View, self)._public(request, entity, context)
def as_comment(context, comment): """Returns a HTML representation of a comment. """ edit_link = '' current_user = user_logic.logic.getCurrentUser() # pylint: disable=E1103 if current_user and comment.author.key() == current_user.key(): params = {'url_name': context['comment_on_url_name']} edit_link = redirects.getEditRedirect(comment, params) context.update({ 'author': comment.author.name, 'content': comment.content, 'created': comment.created, 'edit_link': edit_link, 'modified_on': comment.modified, 'modified_by': comment.modified_by.name if comment.modified_by else '', 'comment_class': "public" if comment.is_public else "private", }) return context
def create(self, request, access_type, page_name=None, params=None, **kwargs): """Displays the create page for this entity type. If an OrgAppSurvey already exists it will redirect to the edit page. """ params = dicts.merge(params, self._params) program_view = params['scope_view'] program_logic = program_view.getParams()['logic'] program_entity = program_logic.getFromKeyName(kwargs['scope_path']) org_app = org_app_logic.getForProgram(program_entity) if org_app: # redirect to edit page return http.HttpResponseRedirect( redirects.getEditRedirect(org_app, params)) else: # show create page return super(View, self).create(request, access_type, page_name=page_name, params=params, **kwargs)
def _getStudentEntries(self, program_entity, student_entity, params, id, user): """Returns a list with menu items for students in a specific program. """ items = [] timeline_entity = program_entity.timeline if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'): items += [('/student_proposal/list_orgs/%s' % ( student_entity.key().id_or_name()), "Submit your Student Proposal", 'any_access')] if timeline_helper.isAfterEvent(timeline_entity, 'student_signup_start'): items += [(redirects.getListSelfRedirect(student_entity, {'url_name':'student_proposal'}), "List my Student Proposals", 'any_access')] items += [(redirects.getEditRedirect(student_entity, {'url_name': 'student'}), "Edit my Student Profile", 'any_access')] if timeline_helper.isAfterEvent(timeline_entity, 'accepted_students_announced_deadline'): # add a link to show all projects items += [(redirects.getListProjectsRedirect(program_entity, {'url_name':'student'}), "List my Student Projects", 'any_access')] return items
def _public(self, request, entity, context): """Performs any processing needed for the Document's public page. For args see base.View._public(). """ # check if the current user is allowed to visit the edit page rights = self._params['rights'] allowed_to_edit = False try: # use the IsDocumentWritable check because we have no django args rights.checkIsDocumentWritable({'key_name': entity.key().name(), 'prefix': entity.prefix, 'scope_path': entity.scope_path, 'link_id': entity.link_id}, 'key_name') allowed_to_edit = True except: pass if allowed_to_edit: # add the document edit redirect to the context context['edit_redirect'] = redirects.getEditRedirect( entity, {'url_name': 'document'}) return super(View, self)._public(request, entity, context)
def _getHostEntries(self, entity, params, prefix): """Returns a list with menu items for program host. Args: entity: program entity to get the entries for params: view specific params prefix: module prefix for the program entity """ items = [] # add link to edit Program Profile items += [(redirects.getEditRedirect(entity, params), 'Edit Program Profile', 'any_access')] # add link to edit Program Timeline items += [ (redirects.getEditRedirect(entity, {'url_name': prefix + '/timeline'}), "Edit Program Timeline", 'any_access') ] # add link to create a new Program Document items += [ (redirects.getCreateDocumentRedirect(entity, params['document_prefix']), "Create a New Document", 'any_access') ] # add link to list all Program Document items += [ (redirects.getListDocumentsRedirect(entity, params['document_prefix']), "List Documents", 'any_access') ] timeline_entity = entity.timeline if not timeline_helper.isAfterEvent(timeline_entity, 'org_signup'): # add link to create/edit OrgAppSurvey org_app_survey = org_app_logic.getForProgram(entity) items += [ (redirects.getCreateSurveyRedirect(entity, params['document_prefix'], prefix + '/org_app'), 'Edit Org Application Survey', 'any_access') ] return items
def _getExtraMenuItems(self, role_description, params=None): """Used to create the specific Sponsor menu entries. For args see group.View._getExtraMenuItems(). """ submenus = [] group_entity = role_description['group'] roles = role_description['roles'] if roles.get('host'): # add a link to create a new program submenu = (redirects.getCreateRedirect(group_entity, {'url_name': 'program'}),"Create a New Program", 'any_access') submenus.append(submenu) # add a link to the management page submenu = (redirects.getListRolesRedirect(group_entity, params), "Manage Program Administrators", 'any_access') submenus.append(submenu) # add a link to invite an a host submenu = (redirects.getInviteRedirectForRole(group_entity, 'host'), "Invite a Program Administrator", 'any_access') submenus.append(submenu) # add a link to the request page submenu = (redirects.getListRequestsRedirect(group_entity, params), "List Program Administrator Invites", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(group_entity, params), "Edit Program Owner Profile", 'any_access') submenus.append(submenu) # add a link to resign as a host submenu = (redirects.getManageRedirect(roles['host'], {'url_name': 'host'}), "Resign as Program Administrator", 'any_access') submenus.append(submenu) # add a link to create a new document submenu = (redirects.getCreateDocumentRedirect(group_entity, 'sponsor'), "Create a New Document", 'any_access') submenus.append(submenu) # add a link to list all documents submenu = (redirects.getListDocumentsRedirect(group_entity, 'sponsor'), "List Documents", 'any_access') submenus.append(submenu) return submenus
def _getStudentEntries(self, program_entity, student_entity, params, id, user, prefix): """Returns a list with menu items for students in a specific program. """ items = [] if timeline_helper.isBeforeEvent(program_entity.timeline, 'program_end') \ and student_entity.status == 'active': items += [(redirects.getEditRedirect(student_entity, {'url_name': prefix + '/student'}), "Edit my Student Profile", 'any_access')] return items
def _getStudentEntries(self, program_entity, student_entity, params, id, user, prefix): """Returns a list with menu items for students in a specific program. """ items = [] if timeline_helper.isBeforeEvent(program_entity.timeline, 'program_end') \ and student_entity.status == 'active': items += [ (redirects.getEditRedirect(student_entity, {'url_name': prefix + '/student'}), "Edit my Student Profile", 'any_access') ] return items
def _public(self, request, entity, context): """See base.View._public(). """ if not entity: return news_feed = NewsFeed(entity) context['news_feed'] = news_feed.getFeed() try: home_doc = entity.home except db.Error: home_doc = None if not home_doc: return False home_doc.content = helper.templates.unescape(home_doc.content) context['home_document'] = home_doc # check if the current user is allowed edit the home document rights = self._params['rights'] allowed_to_edit = False try: # use the IsDocumentWritable check because we have no django args rights.checkIsDocumentWritable({'key_name': home_doc.key().name(), 'prefix': home_doc.prefix, 'scope_path': home_doc.scope_path, 'link_id': home_doc.link_id}, 'key_name') allowed_to_edit = True except: pass if allowed_to_edit: # put the link to edit to home document in context context['home_document_edit_redirect'] = redirects.getEditRedirect( home_doc, {'url_name': 'document'}) return super(View, self)._public(request, entity, context)
def _public(self, request, entity, context): """See base.View._public(). """ if not entity: return try: home_doc = entity.home except db.Error: home_doc = None if not home_doc: return False home_doc.content = helper.templates.unescape(home_doc.content) context['home_document'] = home_doc # check if the current user is allowed edit the home document rights = self._params['rights'] allowed_to_edit = False try: # use the IsDocumentWritable check because we have no django args rights.checkIsDocumentWritable({'key_name': home_doc.key().name(), 'prefix': home_doc.prefix, 'scope_path': home_doc.scope_path, 'link_id': home_doc.link_id}, 'key_name') allowed_to_edit = True except: pass if allowed_to_edit: # put the link to edit to home document in context context['home_document_edit_redirect'] = redirects.getEditRedirect( home_doc, {'url_name': 'document'}) return super(View, self)._public(request, entity, context)
def updatePublicContext(self, context, entity, params): """Updates the context for the public page with information from the entity. Args: context: the context that should be updated entity: a student proposal_entity used to set context params: dict with params for the view using this context """ from soc.modules.gsoc.logic.models.review import logic as review_logic from soc.modules.gsoc.logic.models.review_follower import logic as \ review_follower_logic student_entity = entity.scope context['student'] = student_entity context['student_name'] = student_entity.name() user_entity = user_logic.logic.getForCurrentAccount() # check if the current user is the student # pylint: disable-msg=E1103 if user_entity.key() == student_entity.user.key(): # show the proposal edit link context['edit_link'] = redirects.getEditRedirect(entity, params) # check if the current user is subscribed to this proposal's public reviews fields = { 'user': user_entity, 'scope': entity, 'subscribed_public': True } context['is_subscribed'] = review_follower_logic.getForFields( fields, unique=True) context['public_reviews'] = review_logic.getReviewsForEntity( entity, is_public=True, order=['created'])
def _getExtraMenuItems(self, role_description, params=None): """Used to create the specific Organization menu entries. For args see group.View._getExtraMenuItems(). """ submenus = [] group_entity = role_description['group'] program_entity = group_entity.scope roles = role_description['roles'] mentor_entity = roles.get('mentor') admin_entity = roles.get('org_admin') is_active_mentor = mentor_entity and mentor_entity.status == 'active' is_active_admin = admin_entity and admin_entity.status == 'active' if admin_entity or mentor_entity: # add a link to view all the student proposals submenu = (redirects.getListProposalsRedirect( group_entity, params), "View all Student Proposals", 'any_access') submenus.append(submenu) if admin_entity: # add a link to manage student projects after they have been announced if timeline_helper.isAfterEvent( program_entity.timeline, 'accepted_students_announced_deadline'): submenu = (redirects.getManageOverviewRedirect( group_entity, {'url_name': 'gsoc/student_project'}), "Manage Student Projects", 'any_access') submenus.append(submenu) if is_active_admin: # add a link to the management page submenu = (redirects.getListRolesRedirect(group_entity, params), "Manage Admins and Mentors", 'any_access') submenus.append(submenu) # add a link to invite an org admin submenu = (redirects.getInviteRedirectForRole( group_entity, 'gsoc/org_admin'), "Invite an Admin", 'any_access') submenus.append(submenu) # add a link to invite a member submenu = (redirects.getInviteRedirectForRole( group_entity, 'gsoc/mentor'), "Invite a Mentor", 'any_access') submenus.append(submenu) # add a link to the request page submenu = (redirects.getListRequestsRedirect(group_entity, params), "List Requests and Invites", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(group_entity, params), "Edit Organization Profile", 'any_access') submenus.append(submenu) if is_active_admin or is_active_mentor: submenu = (redirects.getCreateDocumentRedirect( group_entity, params['document_prefix']), "Create a New Document", 'any_access') submenus.append(submenu) submenu = (redirects.getListDocumentsRedirect( group_entity, params['document_prefix']), "List Documents", 'any_access') submenus.append(submenu) if is_active_admin: # add a link to the resign page submenu = (redirects.getManageRedirect( roles['org_admin'], {'url_name': 'gsoc/org_admin'}), "Resign as Admin", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect( roles['org_admin'], {'url_name': 'gsoc/org_admin'}), "Edit My Admin Profile", 'any_access') submenus.append(submenu) if is_active_mentor: # add a link to the resign page submenu = (redirects.getManageRedirect( roles['mentor'], {'url_name': 'gsoc/mentor'}), "Resign as Mentor", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(roles['mentor'], {'url_name': 'gsoc/mentor'}), "Edit My Mentor Profile", 'any_access') submenus.append(submenu) return submenus
def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.GSoCChecker(params) rights['create'] = [('checkIsHostForProgramInScope', program_logic)] rights['edit'] = [('checkIsHostForProgramInScope', program_logic)] rights['delete'] = ['checkIsDeveloper'] rights['show'] = [('checkIsHostForProgramInScope', program_logic)] rights['list'] = [('checkIsHostForProgramInScope', program_logic)] rights['records'] = [('checkIsHostForProgramInScope', program_logic)] rights['edit_record'] = [('checkIsHostForProgramInScope', program_logic)] new_params = {} new_params['logic'] = survey_group_logic new_params['rights'] = rights new_params['name'] = "Grading Survey Group" new_params['url_name'] = 'gsoc/grading_survey_group' new_params['module_package'] = 'soc.modules.gsoc.views.models' new_params['sidebar_grouping'] = "Surveys" new_params['scope_view'] = program_view new_params['scope_redirect'] = redirects.getCreateRedirect new_params['no_admin'] = True new_params['no_create_with_key_fields'] = True new_params['create_extra_dynaproperties'] = { 'grading_survey': djangoforms.ModelChoiceField(GradingProjectSurvey, required=True), 'student_survey': djangoforms.ModelChoiceField(ProjectSurvey, required=False), } new_params['extra_dynaexclude'] = [ 'link_id', 'scope', 'scope_path', 'last_update_started', 'last_update_complete' ] new_params['edit_extra_dynaproperties'] = { 'link_id': forms.CharField(widget=forms.HiddenInput), } # remove the raw list and add the one without the link_id new_params['no_list_raw'] = True new_params['sans_link_id_list'] = True # redefine the developer sidebar so that the list_raw is not shown new_params['sidebar_developer'] = [ # TODO(SRabbelier): remove create once new list code is in ('/%s/create', 'New %(name)s', 'create') ] patterns = [ (r'^%(url_name)s/(?P<access_type>records)/%(key_fields)s$', '%(module_package)s.%(module_name)s.view_records', 'Overview of GradingRecords'), (r'^%(url_name)s/(?P<access_type>edit_record)/%(key_fields)s$', '%(module_package)s.%(module_name)s.edit_record', 'Edit a GradingRecord'), ] new_params['extra_django_patterns'] = patterns new_params['edit_template'] = 'soc/grading_survey_group/edit.html' new_params[ 'view_records_template'] = 'soc/grading_survey_group/records.html' new_params['record_edit_template'] = 'soc/grading_record/edit.html' # create the form that will be used to edit a GradingRecord record_logic = survey_group_logic.getRecordLogic() record_edit_form = dynaform.newDynaForm( dynabase=soc.views.helper.forms.BaseForm, dynamodel=record_logic.getModel(), dynaexclude=[ 'grading_survey_group', 'mentor_record', 'student_record', 'project' ], ) new_params['record_edit_form'] = record_edit_form new_params['public_field_keys'] = [ "name", "last_update_started", "last_update_completed" ] new_params['public_field_names'] = [ "Name", "Last update started", "Last update completed" ] new_params['records_field_prefetch'] = [ 'project', 'mentor_record', 'student_record', # TODO(SRabbelier): Enable when we support multi-level prefetching # 'project.student', 'project.scope', 'project.mentor', ] new_params['records_field_extra'] = lambda entity: { "project_title": entity.project.title, "student_name": entity.project.student.link_id, "student_email": entity.project.student.email, "organization": entity.project.scope.name, "mentor_name": entity.project.mentor.link_id, "mentor_email": entity.project.mentor.email, "final_grade": entity.grade_decision.capitalize(), "mentor_grade": ("Pass" if entity.mentor_record.grade else "Fail") if entity.mentor_record else "Not Available", "student_eval": "Yes" if entity.student_record else "Not Available", } new_params['records_field_keys'] = [ "project_title", "student_name", "student_email", "organization", "mentor_name", "mentor_email", "final_grade", "mentor_grade", "student_eval", "locked", "grade_decision", ] new_params['records_field_names'] = [ "Project Name", "Student link_id", "Student email", "Organization", "Mentor link_id", "Mentor email", "Final Grade", "Mentor Grade", "Student Eval", "Locked", "Grade", ] new_params['records_row_extra'] = lambda entity: { "link": redirects.getEditRedirect(entity, params), } params = dicts.merge(params, new_params) super(View, self).__init__(params=params)
def getExtraMenus(self, id, user, params=None): """Returns the extra menu's for this view. A menu item is generated for each program that is currently running. The public page for each program is added as menu item, as well as all public documents for that program. Args: params: a dict with params for this View. """ from soc.views.models import survey as survey_view from soc.views.models import project_survey as project_survey_view from soc.views.models import grading_project_survey as grading_survey_view logic = params['logic'] rights = params['rights'] # only get all invisible and visible programs fields = {'status': ['invisible', 'visible']} entities = logic.getForFields(fields) menus = [] rights.setCurrentUser(id, user) for entity in entities: items = [] if entity.status == 'visible': # show the documents for this program, even for not logged in users items += document_view.view.getMenusForScope(entity, params) items += survey_view.view.getMenusForScope(entity, params, id, user) items += project_survey_view.view.getMenusForScope( entity, params, id, user) items += grading_survey_view.view.getMenusForScope( entity, params, id, user) items += self._getTimeDependentEntries(entity, params, id, user) try: # check if the current user is a host for this program rights.doCachedCheck('checkIsHostForProgram', {'scope_path': entity.scope_path, 'link_id': entity.link_id}, []) if entity.status == 'invisible': # still add the document links so hosts can see how it looks like items += document_view.view.getMenusForScope(entity, params) items += survey_view.view.getMenusForScope(entity, params, id, user) items += project_survey_view.view.getMenusForScope( entity, params, id, user) items += grading_survey_view.view.getMenusForScope( entity, params, id, user) items += self._getTimeDependentEntries(entity, params, id, user) items += [(redirects.getReviewOverviewRedirect( entity, {'url_name': 'org_app'}), "Review Organization Applications", 'any_access')] # add link to edit Program Profile items += [(redirects.getEditRedirect(entity, params), 'Edit Program Profile', 'any_access')] # add link to Assign Slots items += [(redirects.getAssignSlotsRedirect(entity, params), 'Assign Slots', 'any_access')] # add link to Show Duplicate project assignments items += [(redirects.getShowDuplicatesRedirect(entity, params), 'Show Duplicate Project Assignments', 'any_access')] # add link to edit Program Timeline items += [(redirects.getEditRedirect(entity, {'url_name': 'timeline'}), "Edit Program Timeline", 'any_access')] # add link to create a new Program Document items += [(redirects.getCreateDocumentRedirect(entity, 'program'), "Create a New Document", 'any_access')] # add link to list all Program Document items += [(redirects.getListDocumentsRedirect(entity, 'program'), "List Documents", 'any_access')] # add link to create a new Program Survey items += [(redirects.getCreateSurveyRedirect(entity, 'program', 'survey'), "Create a New Survey", 'any_access')] # add link to list all Program Surveys items += [(redirects.getListSurveysRedirect(entity, 'program', 'survey'), "List Surveys", 'any_access')] # add link to create a new Project Survey items += [(redirects.getCreateSurveyRedirect(entity, 'program', 'project_survey'), "Create a New Project Survey", 'any_access')] # add link to list all Project Surveys items += [(redirects.getListSurveysRedirect(entity, 'program', 'project_survey'), "List Project Surveys", 'any_access')] # add link to create a new Grading Survey items += [(redirects.getCreateSurveyRedirect(entity, 'program', 'grading_project_survey'), "Create a New Grading Survey", 'any_access')] # add link to list all Grading Surveys items += [(redirects.getListSurveysRedirect(entity, 'program', 'grading_project_survey'), "List Grading Surveys", 'any_access')] except out_of_band.Error: pass items = sidebar.getSidebarMenu(id, user, items, params=params) if not items: continue menu = {} menu['heading'] = entity.short_name menu['items'] = items menu['group'] = 'Programs' menus.append(menu) return menus
def constructParams(params): """Constructs a new params dictionary based on params. Params usage: The params dictionary is passed to getCreateForm and getEditForm, see their docstring on how they use it. rights: The rights value is merged with a default rights dictionary and then used as rights value. url_name: The url_name value is used in constructing several redirects as the first part of the url. module_name: The module_name value is used in constructing the location of several templates. It is expected that it matches the part after "/templates/soc/" for this View. name_plural: The name_plural argument is provided to the LIST_DESCRIPTION when constructing the list_description field. extra_dynainclude: The extra_dynainclude value is used when constructing the create_dynainclude value. extra_dynaexclude: The extra_dynaexclude value is used when constructing the create_dynaexclude value. logic: The logic value is used as argument to save the scope_logic and create a create form. """ logic = params['logic'] if params.get('rights'): rights = params['rights'] else: rights = access.Checker(params) rights['unspecified'] = ['deny'] rights['allow'] = ['allow'] rights['any_access'] = ['checkIsLoggedIn'] rights['show'] = ['checkIsUser'] rights['create'] = ['checkIsDeveloper'] rights['edit'] = ['checkIsDeveloper'] rights['delete'] = ['checkIsDeveloper'] rights['list'] = ['checkIsDeveloper'] rights['pick'] = ['checkIsUser'] # TODO(SRabbelier): proper check new_params = {} new_params['scope_logic'] = logic.getScopeLogic() if 'name_short' not in params: params['name_short'] = params['name'] if 'name_plural' not in params: params['name_plural'] = params['name'] + 's' if 'module_name' not in params: params['module_name'] = params['name_short'].replace(' ', '_').lower() if 'url_name' not in params: params['url_name'] = params['module_name'] if 'document_prefix' not in params: params['document_prefix'] = params['url_name'] # Do not expand edit_redirect to allow it to be overwritten without suffix new_params['edit_redirect'] = '/%(url_name)s/edit/%(suffix)s' new_params['missing_redirect'] = '/%(url_name)s/create' % params new_params['delete_redirect'] = '/%(url_name)s/list' % params new_params['invite_redirect'] = '/request/list' # new_params['cancel_redirect'] = '/%(url_name)s/list' % params new_params['public_redirect'] = None new_params['sidebar'] = None new_params['sidebar_grouping'] = 'main' new_params['sidebar_defaults'] = [] new_params['sidebar_developer'] = [ # TODO(SRabbelier): remove create once new list code is in ('/%s/create', 'New %(name)s', 'create'), ('/%s/list', 'List %(name_plural)s', 'list'), ] new_params['sidebar_additional'] = [] names_sans_link_id = [i for i in logic.getKeyFieldNames() if i != 'link_id'] sans_link_id_pattern = getPattern(names_sans_link_id, linkable.SCOPE_PATH_ARG_PATTERN) new_params['link_id_arg_pattern'] = linkable.LINK_ID_ARG_PATTERN new_params['link_id_pattern_core'] = linkable.LINK_ID_PATTERN_CORE new_params['scope_path_pattern'] = getScopePattern(params) new_params['sans_link_id_pattern'] = sans_link_id_pattern new_params['django_patterns'] = None new_params['extra_django_patterns'] = [] new_params['django_patterns_defaults'] = [] # Defines the module package that the view is in. If it is not # already defined in the respective view, it defaults to # soc.views.models if not params.get('module_package'): new_params['module_package'] = 'soc.views.models' if not params.get('no_edit'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>edit)/%(key_fields)s$', '%(module_package)s.%(module_name)s.edit', 'Edit %(name_short)s')] if not params.get('no_delete'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>delete)/%(key_fields)s$', '%(module_package)s.%(module_name)s.delete', 'Delete %(name_short)s')] if not params.get('no_show'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>show)/%(key_fields)s$', '%(module_package)s.%(module_name)s.public', 'Show %(name_short)s')] if not params.get('no_admin'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>admin)/%(key_fields)s$', '%(module_package)s.%(module_name)s.admin', 'Show %(name_short)s (admin)')] if not params.get('no_create_raw'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>create)$', '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')] if not params.get('no_create_with_scope'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>create)/%(scope)s$', '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')] if not params.get('no_create_with_key_fields'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>create)/%(key_fields)s$', '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')] if not params.get('no_list_raw'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>list)$', '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s')] if params.get('pickable'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>pick)$', '%(module_package)s.%(module_name)s.pick', 'Pick %(name_short)s')] if params.get('export_content_type'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>export)/%(key_fields)s$', '%(module_package)s.%(module_name)s.export', 'Export %(name_short)s')] if params.get('sans_link_id_create'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>create)/%(sans_link_id)s$', '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s')] if params.get('sans_link_id_list'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>list)/%(sans_link_id)s$', '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s')] if params.get('sans_link_id_public_list'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>list_public)/%(sans_link_id)s$', '%(module_package)s.%(module_name)s.list_public', 'List %(name_plural)s')] new_params['public_template'] = 'soc/%(module_name)s/public.html' % params new_params['export_template'] = 'soc/export.html' new_params['create_template'] = 'soc/models/edit.html' new_params['edit_template'] = 'soc/models/edit.html' new_params['admin_template'] = 'soc/models/admin.html' new_params['list_template'] = 'soc/models/list.html' new_params['invite_template'] = 'soc/models/invite.html' new_params['context'] = None new_params['cache_pick'] = False new_params['export_content_type'] = None new_params['export_extension'] = '.txt' new_params['csv_fieldnames'] = [] # TODO: Use only the js modules needed instead of js_uses_all new_params['js_uses_all'] = DEF_JS_USES_LIST new_params['js_uses_list'] = ['jq', 'menu'] new_params['js_uses_show'] = ['jq', 'menu'] new_params['js_uses_edit'] = ['jq', 'menu', 'tinymce', 'jq_purr', 'jq_spin', 'jq_autocomplete'] new_params['error_public'] = 'soc/%(module_name)s/error.html' % params new_params['error_export'] = new_params['error_public'] new_params['error_edit'] = new_params['error_public'] new_params['public_row_action'] = { "type": "redirect_custom", "parameters": dict(new_window=False), } new_params['public_row_extra'] = lambda entity, *args: { "link": redirects.getEditRedirect(entity, params), } new_params['list_description'] = DEF_LIST_DESCRIPTION_FMT % params new_params['save_message'] = [ugettext('%(name)s saved.' % params), ugettext('Cannot delete %(name)s.' % params)] new_params['submit_msg_param_name'] = DEF_SUBMIT_MSG_PARAM_NAME new_params['edit_params'] = { DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_PROFILE_SAVED, } new_params['cannot_delete_params'] = { DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_CANNOT_DELETE_ENTITY, } new_params['dynabase'] = helper.forms.BaseForm create_dynaproperties = { 'clean_link_id': cleaning.clean_link_id('link_id'), } create_dynaproperties.update(params.get('create_extra_dynaproperties', {})) # dynafields override any dynaproperties create_dynafields = getDynaFields(params.get('create_dynafields', {})) create_dynaproperties = dicts.merge(create_dynafields, create_dynaproperties) new_params['references'] = [] new_params['create_dynainclude'] = [] + params.get('extra_dynainclude', []) new_params['create_dynaexclude'] = ['scope', 'scope_path'] + \ params.get('extra_dynaexclude', []) new_params['create_dynaproperties'] = create_dynaproperties edit_dynaproperties = { 'clean_link_id': cleaning.clean_link_id('link_id'), 'link_id': forms.CharField(widget=helper.widgets.ReadOnlyInput()), } edit_dynaproperties.update(params.get('edit_extra_dynaproperties', {})) # dynafields override any dynaproperties edit_dynafields = getDynaFields(params.get('edit_dynafields', {})) edit_dynaproperties = dicts.merge(edit_dynafields, edit_dynaproperties) new_params['edit_dynainclude'] = None new_params['edit_dynaexclude'] = None new_params['edit_dynaproperties'] = edit_dynaproperties params = dicts.merge(params, new_params) # These need to be constructed separately, because they require # parameters that can be defined either in params, or new_params. if not 'create_form' in params: params['create_form'] = getCreateForm(params, logic.getModel()) if not 'edit_form' in params: params['edit_form'] = getEditForm(params, params['create_form']) if not 'admin_form' in params: params['admin_form'] = getAdminForm(params['edit_form']) if not 'key_fields_pattern' in params: params['key_fields_pattern'] = getKeyFieldsPattern(params) # merge already done by access.Checker params['rights'] = rights return params
def _getExtraMenuItems(self, role_description, params=None): """Used to create the specific club menu entries. For args see group.View._getExtraMenuItems(). """ submenus = [] group_entity = role_description['group'] roles = role_description['roles'] if roles.get('club_admin'): # add a link to the management page submenu = (redirects.getListRolesRedirect(group_entity, params), "Manage Admins and Members", 'any_access') submenus.append(submenu) # add a link to invite an admin submenu = (redirects.getInviteRedirectForRole( group_entity, 'club_admin'), "Invite an Admin", 'any_access') submenus.append(submenu) # add a link to invite a member submenu = (redirects.getInviteRedirectForRole( group_entity, 'club_member'), "Invite a Member", 'any_access') submenus.append(submenu) # add a link to the request page submenu = (redirects.getListRequestsRedirect(group_entity, params), "List Requests and Invites", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(group_entity, params), "Edit Club Profile", 'any_access') submenus.append(submenu) if roles.get('club_member') or roles.get('club_admin'): submenu = (redirects.getCreateDocumentRedirect( group_entity, 'club'), "Create a New Document", 'any_access') submenus.append(submenu) submenu = (redirects.getListDocumentsRedirect( group_entity, 'club'), "List Documents", 'any_access') submenus.append(submenu) if roles.get('club_admin'): # add a link to resign as club admin submenu = (redirects.getManageRedirect(roles['club_admin'], {'url_name': 'club_admin'}), "Resign as Club Admin", 'any_access') submenus.append(submenu) if roles.get('club_member'): # add a link to resign as club member submenu = (redirects.getManageRedirect( roles['club_member'], {'url_name': 'club_member'}), "Resign as Club Member", 'any_access') submenus.append(submenu) return submenus
def __init__(self, params=None): """Defines the fields and methods required for the base View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = access.GSoCChecker(params) rights['create'] = [('checkIsHostForProgramInScope', program_logic)] rights['edit'] = [('checkIsHostForProgramInScope', program_logic)] rights['delete'] = ['checkIsDeveloper'] rights['show'] = [('checkIsHostForProgramInScope', program_logic)] rights['list'] = [('checkIsHostForProgramInScope', program_logic)] rights['records'] = [('checkIsHostForProgramInScope', program_logic)] rights['edit_record'] = [('checkIsHostForProgramInScope', program_logic)] new_params = {} new_params['logic'] = survey_group_logic new_params['rights'] = rights new_params['name'] = "Grading Survey Group" new_params['url_name'] = 'gsoc/grading_survey_group' new_params['module_package'] = 'soc.modules.gsoc.views.models' new_params['sidebar_grouping'] = "Surveys" new_params['scope_view'] = program_view new_params['scope_redirect'] = redirects.getCreateRedirect new_params['no_admin'] = True new_params['no_create_with_key_fields'] = True new_params['create_extra_dynaproperties'] = { 'grading_survey': djangoforms.ModelChoiceField( GradingProjectSurvey, required=True), 'student_survey': djangoforms.ModelChoiceField(ProjectSurvey, required=False), } new_params['extra_dynaexclude'] = ['link_id', 'scope', 'scope_path', 'last_update_started', 'last_update_complete'] new_params['edit_extra_dynaproperties'] = { 'link_id': forms.CharField(widget=forms.HiddenInput), } # remove the raw list and add the one without the link_id new_params['no_list_raw'] = True new_params['sans_link_id_list'] = True # redefine the developer sidebar so that the list_raw is not shown new_params['sidebar_developer'] = [ # TODO(SRabbelier): remove create once new list code is in ('/%s/create', 'New %(name)s', 'create') ] patterns = [ (r'^%(url_name)s/(?P<access_type>records)/%(key_fields)s$', '%(module_package)s.%(module_name)s.view_records', 'Overview of GradingRecords'), (r'^%(url_name)s/(?P<access_type>edit_record)/%(key_fields)s$', '%(module_package)s.%(module_name)s.edit_record', 'Edit a GradingRecord'), ] new_params['extra_django_patterns'] = patterns new_params['edit_template'] = 'soc/grading_survey_group/edit.html' new_params['view_records_template'] = 'soc/grading_survey_group/records.html' new_params['record_edit_template'] = 'soc/grading_record/edit.html' # create the form that will be used to edit a GradingRecord record_logic = survey_group_logic.getRecordLogic() record_edit_form = dynaform.newDynaForm( dynabase=soc.views.helper.forms.BaseForm, dynamodel=record_logic.getModel(), dynaexclude=['grading_survey_group', 'mentor_record', 'student_record', 'project'], ) new_params['record_edit_form'] = record_edit_form new_params['public_field_keys'] = ["name", "last_update_started", "last_update_completed"] new_params['public_field_names'] = ["Name", "Last update started", "Last update completed"] new_params['records_field_prefetch'] = [ 'project', 'mentor_record', 'student_record', # TODO(SRabbelier): Enable when we support multi-level prefetching # 'project.student', 'project.scope', 'project.mentor', ] new_params['records_field_extra'] = lambda entity: { "project_title": entity.project.title, "student_name": entity.project.student.link_id, "student_email": entity.project.student.email, "organization": entity.project.scope.name, "mentor_name": entity.project.mentor.link_id, "mentor_email": entity.project.mentor.email, "final_grade": entity.grade_decision.capitalize(), "mentor_grade": ("Pass" if entity.mentor_record.grade else "Fail") if entity.mentor_record else "Not Available", "student_eval": "Yes" if entity.student_record else "Not Available", } new_params['records_field_keys'] = [ "project_title", "student_name", "student_email", "organization", "mentor_name", "mentor_email", "final_grade", "mentor_grade", "student_eval", "locked", "grade_decision", ] new_params['records_field_names'] = [ "Project Name", "Student link_id", "Student email", "Organization", "Mentor link_id", "Mentor email", "Final Grade", "Mentor Grade", "Student Eval", "Locked", "Grade", ] new_params['records_row_extra'] = lambda entity: { "link": redirects.getEditRedirect(entity, params), } params = dicts.merge(params, new_params) super(View, self).__init__(params=params)
def _getExtraMenuItems(self, role_description, params=None): """Used to create the specific GCI Organization menu entries. For args see soc.views.models.organization.View._getExtraMenuItems(). """ submenus = [] group_entity = role_description["group"] roles = role_description["roles"] mentor_entity = roles.get("gci_mentor") admin_entity = roles.get("gci_org_admin") is_active_mentor = mentor_entity and mentor_entity.status == "active" is_active_admin = admin_entity and admin_entity.status == "active" if admin_entity or mentor_entity: # add a link to view all the organization tasks. submenu = ( gci_redirects.getListTasksRedirect(group_entity, {"url_name": "gci/task"}), "View all Tasks", "any_access", ) submenus.append(submenu) if is_active_admin: # add a link to create task submenu = ( redirects.getCreateRedirect(group_entity, {"url_name": "gci/task"}), "Create a Task", "any_access", ) submenus.append(submenu) # add a link to bulk create tasks submenu = ( gci_redirects.getBulkCreateRedirect(group_entity, {"url_name": "gci/task"}), "Bulk Create Tasks", "any_access", ) submenus.append(submenu) # add a link to the management page submenu = (redirects.getListRolesRedirect(group_entity, params), "Manage Admins and Mentors", "any_access") submenus.append(submenu) # add a link to invite an org admin submenu = ( redirects.getInviteRedirectForRole(group_entity, "gci/org_admin"), "Invite an Admin", "any_access", ) submenus.append(submenu) # add a link to invite a member submenu = (redirects.getInviteRedirectForRole(group_entity, "gci/mentor"), "Invite a Mentor", "any_access") submenus.append(submenu) # add a link to the request page submenu = ( redirects.getListRequestsRedirect(group_entity, params), "List Requests and Invites", "any_access", ) submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(group_entity, params), "Edit Organization Profile", "any_access") submenus.append(submenu) if is_active_mentor: # add a link to suggest task submenu = ( gci_redirects.getSuggestTaskRedirect(group_entity, {"url_name": "gci/task"}), "Suggest a Task", "any_access", ) submenus.append(submenu) if is_active_admin or is_active_mentor: submenu = ( redirects.getCreateDocumentRedirect(group_entity, "gci_org"), "Create a New Document", "any_access", ) submenus.append(submenu) submenu = (redirects.getListDocumentsRedirect(group_entity, "gci_org"), "List Documents", "any_access") submenus.append(submenu) if is_active_admin: # add a link to the resign page submenu = ( redirects.getManageRedirect(roles["gci_org_admin"], {"url_name": "gci/org_admin"}), "Resign as Admin", "any_access", ) submenus.append(submenu) # add a link to the edit page submenu = ( redirects.getEditRedirect(roles["gci_org_admin"], {"url_name": "gci/org_admin"}), "Edit My Admin Profile", "any_access", ) submenus.append(submenu) if is_active_mentor: # add a link to the resign page submenu = ( redirects.getManageRedirect(roles["gci_mentor"], {"url_name": "gci/mentor"}), "Resign as Mentor", "any_access", ) submenus.append(submenu) # add a link to the edit page submenu = ( redirects.getEditRedirect(roles["gci_mentor"], {"url_name": "gci/mentor"}), "Edit My Mentor Profile", "any_access", ) submenus.append(submenu) return submenus
def _getExtraMenuItems(self, role_description, params=None): """Used to create the specific club menu entries. For args see group.View._getExtraMenuItems(). """ submenus = [] group_entity = role_description['group'] roles = role_description['roles'] if roles.get('club_admin'): # add a link to the management page submenu = (redirects.getListRolesRedirect(group_entity, params), "Manage Admins and Members", 'any_access') submenus.append(submenu) # add a link to invite an admin submenu = (redirects.getInviteRedirectForRole(group_entity, 'club_admin'), "Invite an Admin", 'any_access') submenus.append(submenu) # add a link to invite a member submenu = (redirects.getInviteRedirectForRole(group_entity, 'club_member'), "Invite a Member", 'any_access') submenus.append(submenu) # add a link to the request page submenu = (redirects.getListRequestsRedirect(group_entity, params), "List Requests and Invites", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(group_entity, params), "Edit Club Profile", 'any_access') submenus.append(submenu) if roles.get('club_member') or roles.get('club_admin'): submenu = (redirects.getCreateDocumentRedirect(group_entity, 'club'), "Create a New Document", 'any_access') submenus.append(submenu) submenu = (redirects.getListDocumentsRedirect(group_entity, 'club'), "List Documents", 'any_access') submenus.append(submenu) if roles.get('club_admin'): # add a link to resign as club admin submenu = (redirects.getManageRedirect(roles['club_admin'], {'url_name': 'club_admin'}), "Resign as Club Admin", 'any_access') submenus.append(submenu) if roles.get('club_member'): # add a link to resign as club member submenu = (redirects.getManageRedirect(roles['club_member'], {'url_name' : 'club_member'}), "Resign as Club Member", 'any_access') submenus.append(submenu) return submenus
def _getExtraMenuItems(self, role_description, params=None): """Used to create the specific GCI Organization menu entries. For args see soc.views.models.organization.View._getExtraMenuItems(). """ submenus = [] group_entity = role_description['group'] roles = role_description['roles'] mentor_entity = roles.get('gci_mentor') admin_entity = roles.get('gci_org_admin') is_active_mentor = mentor_entity and mentor_entity.status == 'active' is_active_admin = admin_entity and admin_entity.status == 'active' if admin_entity or mentor_entity: # add a link to view all the organization tasks. submenu = (gci_redirects.getListTasksRedirect( group_entity, {'url_name': 'gci/task'}), "View all Tasks", 'any_access') submenus.append(submenu) if is_active_admin: # add a link to create task submenu = (redirects.getCreateRedirect(group_entity, {'url_name': 'gci/task'}), "Create a Task", 'any_access') submenus.append(submenu) # add a link to bulk create tasks submenu = (gci_redirects.getBulkCreateRedirect( group_entity, {'url_name': 'gci/task'}), "Bulk Create Tasks", 'any_access') submenus.append(submenu) # add a link to the management page submenu = (redirects.getListRolesRedirect(group_entity, params), "Manage Admins and Mentors", 'any_access') submenus.append(submenu) # add a link to invite an org admin submenu = (redirects.getInviteRedirectForRole( group_entity, 'gci/org_admin'), "Invite an Admin", 'any_access') submenus.append(submenu) # add a link to invite a member submenu = (redirects.getInviteRedirectForRole( group_entity, 'gci/mentor'), "Invite a Mentor", 'any_access') submenus.append(submenu) # add a link to the request page submenu = (redirects.getListRequestsRedirect(group_entity, params), "List Requests and Invites", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(group_entity, params), "Edit Organization Profile", 'any_access') submenus.append(submenu) if is_active_mentor: # add a link to suggest task submenu = (gci_redirects.getSuggestTaskRedirect( group_entity, {'url_name': 'gci/task'}), "Suggest a Task", 'any_access') submenus.append(submenu) if is_active_admin or is_active_mentor: submenu = (redirects.getCreateDocumentRedirect( group_entity, 'gci_org'), "Create a New Document", 'any_access') submenus.append(submenu) submenu = (redirects.getListDocumentsRedirect( group_entity, 'gci_org'), "List Documents", 'any_access') submenus.append(submenu) if is_active_admin: # add a link to the resign page submenu = (redirects.getManageRedirect( roles['gci_org_admin'], {'url_name': 'gci/org_admin'}), "Resign as Admin", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect( roles['gci_org_admin'], {'url_name': 'gci/org_admin'}), "Edit My Admin Profile", 'any_access') submenus.append(submenu) if is_active_mentor: # add a link to the resign page submenu = (redirects.getManageRedirect(roles['gci_mentor'], {'url_name': 'gci/mentor'}), "Resign as Mentor", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(roles['gci_mentor'], {'url_name': 'gci/mentor'}), "Edit My Mentor Profile", 'any_access') submenus.append(submenu) return submenus
def constructParams(params): """Constructs a new params dictionary based on params. Params usage: The params dictionary is passed to getCreateForm and getEditForm, see their docstring on how they use it. rights: The rights value is merged with a default rights dictionary and then used as rights value. url_name: The url_name value is used in constructing several redirects as the first part of the url. module_name: The module_name value is used in constructing the location of several templates. It is expected that it matches the part after "/templates/soc/" for this View. name_plural: The name_plural argument is provided to the LIST_DESCRIPTION when constructing the list_description field. extra_dynainclude: The extra_dynainclude value is used when constructing the create_dynainclude value. extra_dynaexclude: The extra_dynaexclude value is used when constructing the create_dynaexclude value. logic: The logic value is used as argument to save the scope_logic and create a create form. """ logic = params['logic'] if params.get('rights'): rights = params['rights'] else: rights = access.Checker(params) rights['unspecified'] = [] rights['any_access'] = ['checkIsLoggedIn'] rights['show'] = ['checkIsUser'] rights['create'] = ['checkIsDeveloper'] rights['edit'] = ['checkIsDeveloper'] rights['delete'] = ['checkIsDeveloper'] rights['list'] = ['checkIsDeveloper'] rights['pick'] = ['checkIsUser'] # TODO(SRabbelier): proper check new_params = {} new_params['scope_logic'] = logic.getScopeLogic() if 'name_short' not in params: params['name_short'] = params['name'] if 'name_plural' not in params: params['name_plural'] = params['name'] + 's' if 'module_name' not in params: params['module_name'] = params['name_short'].replace(' ', '_').lower() if 'url_name' not in params: params['url_name'] = params['module_name'] if 'document_prefix' not in params: params['document_prefix'] = params['url_name'] # Do not expand edit_redirect to allow it to be overwritten without suffix new_params['edit_redirect'] = '/%(url_name)s/edit/%(suffix)s' new_params['missing_redirect'] = '/%(url_name)s/create' % params new_params['delete_redirect'] = '/%(url_name)s/list' % params new_params['invite_redirect'] = '/request/list' # new_params['cancel_redirect'] = '/%(url_name)s/list' % params new_params['public_redirect'] = None new_params['sidebar'] = None new_params['sidebar_grouping'] = 'main' new_params['sidebar_defaults'] = [] new_params['sidebar_developer'] = [ # TODO(SRabbelier): remove create once new list code is in ('/%s/create', 'New %(name)s', 'create'), ('/%s/list', 'List %(name_plural)s', 'list'), ] new_params['sidebar_additional'] = [] names_sans_link_id = [ i for i in logic.getKeyFieldNames() if i != 'link_id' ] sans_link_id_pattern = getPattern(names_sans_link_id, linkable.SCOPE_PATH_ARG_PATTERN) new_params['link_id_arg_pattern'] = linkable.LINK_ID_ARG_PATTERN new_params['link_id_pattern_core'] = linkable.LINK_ID_PATTERN_CORE new_params['scope_path_pattern'] = getScopePattern(params) new_params['sans_link_id_pattern'] = sans_link_id_pattern new_params['django_patterns'] = None new_params['extra_django_patterns'] = [] new_params['django_patterns_defaults'] = [] # Defines the module package that the view is in. If it is not # already defined in the respective view, it defaults to # soc.views.models if not params.get('module_package'): new_params['module_package'] = 'soc.views.models' if not params.get('no_edit'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>edit)/%(key_fields)s$', '%(module_package)s.%(module_name)s.edit', 'Edit %(name_short)s') ] if not params.get('no_delete'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>delete)/%(key_fields)s$', '%(module_package)s.%(module_name)s.delete', 'Delete %(name_short)s') ] if not params.get('no_show'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>show)/%(key_fields)s$', '%(module_package)s.%(module_name)s.public', 'Show %(name_short)s') ] if not params.get('no_admin'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>admin)/%(key_fields)s$', '%(module_package)s.%(module_name)s.admin', 'Show %(name_short)s (admin)') ] if not params.get('no_create_raw'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>create)$', '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s') ] if not params.get('no_create_with_scope'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>create)/%(scope)s$', '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s') ] if not params.get('no_create_with_key_fields'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>create)/%(key_fields)s$', '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s') ] if not params.get('no_list_raw'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>list)$', '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s') ] if params.get('pickable'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>pick)$', '%(module_package)s.%(module_name)s.pick', 'Pick %(name_short)s') ] if params.get('export_content_type'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>export)/%(key_fields)s$', '%(module_package)s.%(module_name)s.export', 'Export %(name_short)s') ] if params.get('sans_link_id_create'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>create)/%(sans_link_id)s$', '%(module_package)s.%(module_name)s.create', 'Create %(name_short)s') ] if params.get('sans_link_id_list'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>list)/%(sans_link_id)s$', '%(module_package)s.%(module_name)s.list', 'List %(name_plural)s') ] if params.get('sans_link_id_public_list'): new_params['django_patterns_defaults'] += [ (r'^%(url_name)s/(?P<access_type>list_public)/%(sans_link_id)s$', '%(module_package)s.%(module_name)s.list_public', 'List %(name_plural)s') ] new_params['public_template'] = 'soc/%(module_name)s/public.html' % params new_params['export_template'] = 'soc/export.html' new_params['create_template'] = 'soc/models/edit.html' new_params['edit_template'] = 'soc/models/edit.html' new_params['admin_template'] = 'soc/models/admin.html' new_params['list_template'] = 'soc/models/list.html' new_params['invite_template'] = 'soc/models/invite.html' new_params['context'] = None new_params['cache_pick'] = False new_params['export_content_type'] = None new_params['export_extension'] = '.txt' new_params['csv_fieldnames'] = [] # TODO: Use only the js modules needed instead of js_uses_all new_params['js_uses_all'] = DEF_JS_USES_LIST new_params['js_uses_list'] = ['jq', 'menu'] new_params['js_uses_show'] = ['jq', 'menu'] new_params['js_uses_edit'] = [ 'jq', 'menu', 'tinymce', 'jq_purr', 'jq_spin', 'jq_autocomplete' ] new_params['error_public'] = 'soc/%(module_name)s/error.html' % params new_params['error_export'] = new_params['error_public'] new_params['error_edit'] = new_params['error_public'] new_params['list_main'] = 'soc/list/main.html' new_params['list_pagination'] = 'soc/list/pagination.html' new_params['list_row'] = 'soc/%(module_name)s/list/row.html' % params new_params[ 'list_heading'] = 'soc/%(module_name)s/list/heading.html' % params new_params['public_row_action'] = { "type": "redirect_custom", "parameters": dict(new_window=True), } new_params['public_row_extra'] = lambda entity, *args: { "link": redirects.getEditRedirect(entity, params), } new_params['list_params'] = { 'list_description': 'description', 'list_info': 'info', 'list_key_order': 'key_order', 'list_main': 'main', 'list_pagination': 'pagination', 'list_row': 'row', 'list_heading': 'heading', } new_params['list_description'] = DEF_LIST_DESCRIPTION_FMT % params new_params['no_lists_msg'] = "" new_params['save_message'] = [ ugettext('%(name)s saved.' % params), ugettext('Cannot delete %(name)s.' % params) ] new_params['submit_msg_param_name'] = DEF_SUBMIT_MSG_PARAM_NAME new_params['edit_params'] = { DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_PROFILE_SAVED, } new_params['cannot_delete_params'] = { DEF_SUBMIT_MSG_PARAM_NAME: DEF_SUBMIT_MSG_CANNOT_DELETE_ENTITY, } new_params['dynabase'] = helper.forms.BaseForm create_dynaproperties = { 'clean_link_id': cleaning.clean_link_id('link_id'), 'clean_feed_url': cleaning.clean_feed_url, } create_dynaproperties.update(params.get('create_extra_dynaproperties', {})) # dynafields override any dynaproperties create_dynafields = getDynaFields(params.get('create_dynafields', {})) create_dynaproperties = dicts.merge(create_dynafields, create_dynaproperties) new_params['references'] = [] new_params['create_dynainclude'] = [] + params.get('extra_dynainclude', []) new_params['create_dynaexclude'] = ['scope', 'scope_path'] + \ params.get('extra_dynaexclude', []) new_params['create_dynaproperties'] = create_dynaproperties edit_dynaproperties = { 'clean_link_id': cleaning.clean_link_id('link_id'), 'link_id': forms.CharField(widget=helper.widgets.ReadOnlyInput()), } edit_dynaproperties.update(params.get('edit_extra_dynaproperties', {})) # dynafields override any dynaproperties edit_dynafields = getDynaFields(params.get('edit_dynafields', {})) edit_dynaproperties = dicts.merge(edit_dynafields, edit_dynaproperties) new_params['edit_dynainclude'] = None new_params['edit_dynaexclude'] = None new_params['edit_dynaproperties'] = edit_dynaproperties new_params['list_msg'] = None params = dicts.merge(params, new_params) # These need to be constructed separately, because they require # parameters that can be defined either in params, or new_params. if not 'create_form' in params: params['create_form'] = getCreateForm(params, logic.getModel()) if not 'edit_form' in params: params['edit_form'] = getEditForm(params, params['create_form']) if not 'admin_form' in params: params['admin_form'] = getAdminForm(params['edit_form']) if not 'key_fields_pattern' in params: params['key_fields_pattern'] = getKeyFieldsPattern(params) # merge already done by access.Checker params['rights'] = rights return params
def _getExtraMenuItems(self, role_description, params=None): """Used to create the specific Organization menu entries. For args see group.View._getExtraMenuItems(). """ submenus = [] group_entity = role_description['group'] program_entity = group_entity.scope roles = role_description['roles'] if roles.get('org_admin') or roles.get('mentor'): # add a link to view all the student proposals submenu = (redirects.getListProposalsRedirect(group_entity, params), "View all Student Proposals", 'any_access') submenus.append(submenu) if roles.get('org_admin'): # add a link to manage student projects after they have been announced if timeline_helper.isAfterEvent(program_entity.timeline, 'accepted_students_announced_deadline'): submenu = (redirects.getManageOverviewRedirect(group_entity, {'url_name': 'student_project'}), "Manage Student Projects", 'any_access') submenus.append(submenu) # add a link to the management page submenu = (redirects.getListRolesRedirect(group_entity, params), "Manage Admins and Mentors", 'any_access') submenus.append(submenu) # add a link to invite an org admin submenu = (redirects.getInviteRedirectForRole(group_entity, 'org_admin'), "Invite an Admin", 'any_access') submenus.append(submenu) # add a link to invite a member submenu = (redirects.getInviteRedirectForRole(group_entity, 'mentor'), "Invite a Mentor", 'any_access') submenus.append(submenu) # add a link to the request page submenu = (redirects.getListRequestsRedirect(group_entity, params), "List Requests and Invites", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(group_entity, params), "Edit Organization Profile", 'any_access') submenus.append(submenu) if roles.get('org_admin') or roles.get('mentor'): submenu = (redirects.getCreateDocumentRedirect(group_entity, 'org'), "Create a New Document", 'any_access') submenus.append(submenu) submenu = (redirects.getListDocumentsRedirect(group_entity, 'org'), "List Documents", 'any_access') submenus.append(submenu) if roles.get('org_admin'): # add a link to the resign page submenu = (redirects.getManageRedirect(roles['org_admin'], {'url_name': 'org_admin'}), "Resign as Admin", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(roles['org_admin'], {'url_name': 'org_admin'}), "Edit My Admin Profile", 'any_access') submenus.append(submenu) if roles.get('mentor'): # add a link to the resign page submenu = (redirects.getManageRedirect(roles['mentor'], {'url_name' : 'mentor'}), "Resign as Mentor", 'any_access') submenus.append(submenu) # add a link to the edit page submenu = (redirects.getEditRedirect(roles['mentor'], {'url_name': 'mentor'}), "Edit My Mentor Profile", 'any_access') submenus.append(submenu) return submenus