def urlize_safe(url): """Returns an urlized version of an url. Args: url: an already escaped url """ return lists.urlize(url)
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: original_params: a dict with params for this View """ from soc.views.models import program as program_view rights = access.Checker(params) rights['any_access'] = ['allow'] rights['show'] = ['allow'] rights['create'] = ['checkIsDeveloper'] rights['edit'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic.logic,), ('checkGroupIsActiveForLinkId', org_logic.logic)] rights['delete'] = ['checkIsDeveloper'] rights['home'] = ['allow'] rights['public_list'] = ['allow'] rights['apply_mentor'] = ['checkIsUser'] rights['list_requests'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic.logic)] rights['list_roles'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic.logic)] new_params = {} new_params['logic'] = soc.logic.models.organization.logic new_params['rights'] = rights new_params['scope_view'] = program_view new_params['scope_redirect'] = redirects.getCreateRedirect new_params['name'] = "Organization" new_params['url_name'] = "org" new_params['document_prefix'] = "org" new_params['sidebar_grouping'] = 'Organizations' new_params['public_template'] = 'soc/organization/public.html' new_params['home_template'] = 'soc/organization/home.html' new_params['sans_link_id_public_list'] = True patterns = [] patterns += [ (r'^%(url_name)s/(?P<access_type>apply_mentor)/%(scope)s$', '%(module_package)s.%(module_name)s.apply_mentor', "List of all %(name_plural)s you can apply to"), (r'^%(url_name)s/(?P<access_type>list_proposals)/%(key_fields)s$', '%(module_package)s.%(module_name)s.list_proposals', "List of all Student Proposals for "), (r'^%(url_name)s/(?P<access_type>applicant)/%(scope)s$', '%(module_package)s.%(module_name)s.applicant', "%(name)s Creation via Accepted Application"), ] new_params['extra_django_patterns'] = patterns new_params['create_dynafields'] = [ {'name': 'link_id', 'base': forms.fields.CharField, 'label': 'Organization Link ID', }, ] new_params['create_extra_dynaproperties'] = { 'scope_path': forms.CharField(widget=forms.HiddenInput, required=True), 'description': forms.fields.CharField( widget=helper.widgets.FullTinyMCE( attrs={'rows': 25, 'cols': 100})), 'clean_description': cleaning.clean_html_content('description'), 'clean_ideas': cleaning.clean_url('ideas'), 'clean': cleaning.validate_new_group('link_id', 'scope_path', soc.logic.models.organization), } new_params['edit_extra_dynaproperties'] = { 'clean': cleaning.clean_refs(params if params else new_params, ['home_link_id']) } new_params['public_field_extra'] = lambda entity: { 'ideas': lists.urlize(entity.ideas, 'Click Here'), } params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params) self._params['public_field_keys'] = self._params['select_field_keys'] = [ "name", "link_id", "short_name", "ideas" ] self._params['public_field_names'] = self._params['select_field_names'] = [ "Name", "Link ID", "Short Name", "Ideas Page" ] self._params['select_field_extra'] = self._params['public_field_extra'] self._params['select_row_action'] = { "type": "redirect_custom", "parameters": dict(new_window=True), } self._params['select_row_extra'] = lambda entity: { "link": redirects.getRequestRedirectForRole( entity, params['mentor_url_name']) }
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 """ new_params = {} new_params['logic'] = org_app_logic new_params['name'] = "Org Application Survey" new_params['url_name'] = 'org_app' new_params['extra_dynaexclude'] = ['taking_access'] new_params['survey_take_form'] = OrgAppSurveyForm new_params['survey_record_form'] = OrgAppRecordForm new_params['extra_django_patterns'] = [ (r'^%(url_name)s/(?P<access_type>list_self)/%(key_fields)s$', '%(module_package)s.%(module_name)s.list_self', 'Overview of %(name_plural)s Taken by You'), (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$', '%(module_package)s.%(module_name)s.review', 'Review %(name)s from '), (r'^%(url_name)s/(?P<access_type>review_overview)/%(key_fields)s$', '%(module_package)s.%(module_name)s.review_overview', 'Overview of %(name_plural)s for Review') ] new_params['review_template'] = 'soc/org_app_survey/review.html' new_params['successful_take_message'] = ugettext( 'Organization Application submitted.') params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params) # create the form to review an Organization Application dynaproperties = { 'status': forms.fields.ChoiceField(required=True, label='New Status', choices=[ ('accepted', 'Accept'), ('pre-accepted', 'Pre-Accept'), ('rejected', 'Reject'), ('pre-rejected', 'Pre-Reject'), ('ignored', 'Ignore'), ]) } review_form = dynaform.newDynaForm( dynabase=self._params['dynabase'], dynaproperties=dynaproperties, ) self._params['review_form'] = review_form # define the params for the OrgAppSurveyRecord listing record_list_params = {} record_list_params['logic'] = self._params['logic'].getRecordLogic() record_list_params['js_uses_all'] = self._params['js_uses_all'] record_list_params['list_template'] = self._params['list_template'] # define the fields for the public list record_list_params['public_field_keys'] = ['name', 'home_page'] record_list_params['public_field_names'] = ['Name', 'Home Page'] record_list_params['public_field_extra'] = lambda entity: { 'home_page': lists.urlize(entity.home_page, 'Click Here'), } # define the fields for the self list record_list_params['self_field_keys'] = [ 'name', 'main_admin', 'backup_admin' ] record_list_params['self_field_names'] = [ 'Organization Name', 'Main Admin', 'Backup Admin' ] record_list_params['self_field_prefetch'] = [ 'main_admin', 'backup_admin' ] record_list_params['self_field_extra'] = lambda entity: { 'main_admin': entity.main_admin.name, 'backup_admin': entity.backup_admin.name } record_list_params['self_row_action'] = { "type": "redirect_custom", "parameters": dict(new_window=False), } self._params['record_list_params'] = record_list_params
def __init__(self, params=None): """Defines the fields and methods required for the program View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = gci_access.GCIChecker(params) rights['create'] = ['checkIsDeveloper'] rights['edit'] = [('checkHasRoleForKeyFieldsAsScope', gci_org_admin_logic.logic), ('checkGroupIsActiveForLinkId', gci_org_logic.logic)] rights['delete'] = ['checkIsDeveloper'] rights['home'] = ['allow'] rights['public_list'] = ['allow'] rights['applicant'] = [('checkIsOrgAppAccepted', org_app_logic)] rights['apply_mentor'] = ['checkIsUser'] rights['list_requests'] = [('checkHasRoleForKeyFieldsAsScope', gci_org_admin_logic.logic)] rights['list_roles'] = [('checkHasRoleForKeyFieldsAsScope', gci_org_admin_logic.logic)] rights['request_task'] = [ ('checkHasRoleForScope', gci_student_logic.logic), 'checkOrgHasNoOpenTasks', ('checkIsAfterEvent', ['tasks_publicly_visible', 'scope_path', gci_program_logic.logic]), ('checkIsBeforeEvent', ['task_claim_deadline', 'scope_path', gci_program_logic.logic]), ] new_params = {} new_params['logic'] = soc.modules.gci.logic.models.organization.logic new_params['rights'] = rights new_params['scope_view'] = gci_program_view new_params['name'] = "GCI Organization" new_params['module_name'] = "organization" new_params['sidebar_grouping'] = 'GCI Organizations' new_params['public_template'] = 'modules/gci/organization/public.html' new_params['home_template'] = 'modules/gci/organization/home.html' new_params['module_package'] = 'soc.modules.gci.views.models' new_params['url_name'] = 'gci/org' new_params['document_prefix'] = 'gci_org' new_params['extra_dynaexclude'] = [ 'slots', 'slots_calculated', 'nr_applications', 'nr_mentors', 'slots_desired', 'ideas', 'task_quota_limit' ] new_params['mentor_role_name'] = 'gci_mentor' new_params['mentor_url_name'] = 'gci/mentor' new_params['org_admin_role_name'] = 'gci_org_admin' new_params['org_app_logic'] = org_app_logic patterns = [] patterns += [ (r'^%(url_name)s/(?P<access_type>request_task)/%(key_fields)s$', '%(module_package)s.%(module_name)s.request_task', 'Request more tasks'), ] new_params['extra_django_patterns'] = patterns params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params) # The organization view manually overwrites public_field_extra, # so we must do the same (or be overwritten by them). self._params['public_field_extra'] = lambda entity: { "home_page": lists.urlize(entity.home_page), } import settings self._params['public_field_keys'] = self._params[ 'select_field_keys'] = [ "name", "short_name", "home_page", ] self._params['public_field_names'] = self._params[ 'select_field_names'] = [ "Name", "Short Name", "Home Page", ] self._params['select_field_extra'] = self._params['public_field_extra'] if settings.GCI_TASK_QUOTA_LIMIT_ENABLED: self._params['public_field_keys'].append("task_quota_limit") self._params['public_field_names'].append("Tasks Quota")
def reviewOverview(self, request, access_type, page_name=None, params=None, **kwargs): """Displays a list of applications that are in a different status of the application process. """ survey_logic = params['logic'] entity = survey_logic.getFromKeyFieldsOr404(kwargs) if request.POST: # POST request received, check and respond to button actions post_dict = request.POST if post_dict.get('button_id') == 'bulk_process': params['bulk_process_task'].start(entity.scope) if post_dict.get( 'button_id') == 'save_status' and 'data' in request.POST: self.processSaveReview(request.POST['data']) return http.HttpResponse() list_params = params['record_list_params'].copy() list_params['list_description'] = ( 'List of all the Organization Applications made to the %s program. ' 'Click an application to review it, or use the buttons on the top of ' 'the list for bulk actions.' % (entity.scope.name)) info = {'url_name': params['url_name'], 'survey': entity} choices = org_app_record.OrgAppRecord.status.choices values = ";".join("%s:%s" % (i, i.capitalize()) for i in choices) list_params['overview_field_props'] = { 'status': { 'editable': True, 'edittype': "select", 'editoptions': { 'value': values } } } # define the basic fields for the overview list list_params['overview_field_keys'] = [ 'name', 'home_page', 'details', 'status', ] list_params['overview_field_names'] = [ 'Organization Name', 'Home Page', 'Details', 'Application Status', ] list_params['overview_field_extra'] = lambda entity: { 'home_page': lists.urlize(entity.home_page), 'status': entity.status.capitalize(), 'details': lists.urlize(redirects.getReviewOrgAppSurvey(entity, info), name="[details]"), } list_params['overview_button_global'] = [ { 'bounds': [0, 'all'], 'id': 'bulk_process', 'caption': 'Bulk Accept/Reject Organizations', 'type': 'post', 'parameters': { 'url': '' }, }, { 'id': 'save_status', 'caption': 'Save status', 'type': 'post_edit', 'parameters': { 'url': '', 'keys': ['key'], 'refresh': 'current', }, }, ] list_params['overview_row_action'] = { "type": "redirect_custom", "parameters": dict(new_window=False), } self._extendListWithSurveyAnswers(list_params, entity, 'overview') if lists.isDataRequest(request): # get all records for the entity specified in the URL fields = {'survey': entity} # use the overview visibility to show the correct columns to the Host contents = lists.getListData(request, list_params, fields, visibility='overview') return lists.getResponse(request, contents) overview_list = lists.getListGenerator(request, list_params, visibility='overview', idx=0) contents = [overview_list] return self._list(request, list_params, contents, page_name)
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['any_access'] = ['allow'] rights['show'] = ['allow'] rights['create'] = ['checkIsDeveloper'] rights['edit'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic), ('checkGroupIsActiveForLinkId', org_logic)] rights['delete'] = ['checkIsDeveloper'] rights['home'] = ['allow'] rights['public_list'] = ['allow'] rights['applicant'] = [('checkIsOrgAppAccepted', org_app_logic)] rights['apply_mentor'] = ['checkIsUser'] rights['list_requests'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic)] rights['list_roles'] = [('checkHasRoleForKeyFieldsAsScope', org_admin_logic)] rights['list_proposals'] = [ ('checkHasAny', [[('checkHasRoleForKeyFieldsAsScope', [org_admin_logic, ['active', 'inactive']]), ('checkHasRoleForKeyFieldsAsScope', [mentor_logic, ['active', 'inactive']])]]) ] new_params = {} new_params['logic'] = org_logic new_params['rights'] = rights new_params['scope_view'] = program_view new_params['name'] = "GSoC Organization" new_params['module_name'] = "organization" new_params['sidebar_grouping'] = 'Organizations' new_params['module_package'] = 'soc.modules.gsoc.views.models' new_params['url_name'] = 'gsoc/org' new_params['document_prefix'] = 'gsoc_org' new_params['mentor_role_name'] = 'gsoc_mentor' new_params['mentor_url_name'] = 'gsoc/mentor' new_params['org_admin_role_name'] = 'gsoc_org_admin' patterns = [] patterns += [ (r'^org_tags/(?P<access_type>pick)$', '%(module_package)s.%(module_name)s.pick_suggested_tags', "Pick a list of suggested tags."), ] new_params['extra_django_patterns'] = patterns new_params['extra_dynaexclude'] = [ 'slots', 'slots_calculated', 'nr_applications', 'nr_mentors' ] new_params['create_extra_dynaproperties'] = { 'tags': widgets.ReferenceField( required=False, reference_url='org_tags', label=ugettext('Tags'), help_text=ugettext("A list of comma seperated tags"), example_text="e.g. python, django, appengine", filter=['scope_path'], group="1. Public Info"), 'clean_tags': gsoc_cleaning.cleanTagsList('tags', gsoc_cleaning.COMMA_SEPARATOR), 'contrib_template': forms.fields.CharField(widget=helper.widgets.FullTinyMCE( attrs={ 'rows': 25, 'cols': 100 })), 'clean_contrib_template': cleaning.clean_html_content('contrib_template'), 'clean_facebook': cleaning.clean_url('facebook'), 'clean_twitter': cleaning.clean_url('twitter'), 'clean_blog': cleaning.clean_url('blog'), } new_params['org_app_logic'] = org_app_logic params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params) self._params['public_field_keys'].append('tags') self._params['public_field_names'].append("Tags") self._params['public_field_extra'] = lambda entity: { 'ideas': lists.urlize(entity.ideas, 'Click Here'), 'tags': entity.tags_string(entity.org_tag), } self._params['select_field_extra'] = self._params['public_field_extra']
def __init__(self, params=None): """Defines the fields and methods required for the program View class to provide the user with list, public, create, edit and delete views. Params: params: a dict with params for this View """ rights = ghop_access.GHOPChecker(params) rights['create'] = ['checkIsDeveloper'] rights['edit'] = [( 'checkHasRoleForKeyFieldsAsScope', ghop_org_admin_logic.logic, ), ('checkGroupIsActiveForLinkId', ghop_org_logic.logic)] rights['delete'] = ['checkIsDeveloper'] rights['home'] = ['allow'] rights['public_list'] = ['allow'] rights['apply_mentor'] = ['checkIsUser'] rights['list_requests'] = [('checkHasRoleForKeyFieldsAsScope', ghop_org_admin_logic.logic)] rights['list_roles'] = [('checkHasRoleForKeyFieldsAsScope', ghop_org_admin_logic.logic)] new_params = {} new_params['logic'] = soc.modules.ghop.logic.models.organization.logic new_params['rights'] = rights new_params['scope_view'] = ghop_program_view new_params['name'] = "GHOP Organization" new_params['module_name'] = "organization" new_params['sidebar_grouping'] = 'Organizations' new_params['public_template'] = 'modules/ghop/organization/public.html' new_params['list_row'] = 'modules/ghop/organization/list/row.html' new_params[ 'list_heading'] = 'modules/ghop/organization/list/heading.html' new_params['home_template'] = 'modules/ghop/organization/home.html' new_params['module_package'] = 'soc.modules.ghop.views.models' new_params['url_name'] = 'ghop/org' new_params['document_prefix'] = 'ghop_org' new_params['extra_dynaexclude'] = [ 'slots', 'slots_calculated', 'nr_applications', 'nr_mentors', 'slots_desired', 'ideas', 'task_quota_limit' ] new_params['mentor_role_name'] = 'ghop_mentor' new_params['mentor_url_name'] = 'ghop/mentor' new_params['edit_extra_dynaproperties'] = { 'clean': cleaning.clean_refs(new_params, ['home_link_id']) } new_params['public_field_extra'] = lambda entity: { "open_tasks": str( len( ghop_task_logic.logic.getForFields({ 'scope': entity, 'status': ['Open', 'Reopened'] }))), "claimed_tasks": str( len( ghop_task_logic.logic.getForFields({ 'scope': entity, 'status': [ 'ClaimRequested', 'Claimed', 'ActionNeeded', 'NeedsReview', 'NeedsWork' ], }))), "closed_tasks": str( len( ghop_task_logic.logic.getForFields({ 'scope': entity, 'status': ['AwaitingRegistration', 'Closed'], }))), "home_page": lists.urlize(entity.home_page), } new_params['public_field_keys'] = [ "name", "task_quota_limit", "open_tasks", "claimed_tasks", "closed_tasks", "home_page", ] new_params['public_field_names'] = [ "Name", "Tasks Quota", "Open Tasks", "Claimed Tasks", "Closed Tasks", "Home Page", ] params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params)
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 """ new_params = {} new_params['logic'] = group_app_logic new_params['name'] = "Group Application" new_params['name_short'] = "Group App" # use the twoline templates for these questionnaires new_params['create_template'] = 'soc/models/twoline_edit.html' new_params['edit_template'] = 'soc/models/twoline_edit.html' patterns = [(r'^%(url_name)s/(?P<access_type>list_self)/%(scope)s$', 'soc.views.models.%(module_name)s.list_self', 'List my %(name_plural)s'), (r'^%(url_name)s/(?P<access_type>review_overview)/%(scope)s$', 'soc.views.models.%(module_name)s.review_overview', 'List of %(name_plural)s for reviewing'), (r'^%(url_name)s/(?P<access_type>review)/%(key_fields)s$', 'soc.views.models.%(module_name)s.review', 'Review %(name_short)s')] new_params['extra_django_patterns'] = patterns new_params['extra_dynaexclude'] = ['applicant', 'backup_admin', 'status', 'created_on', 'last_modified_on'] new_params['create_dynafields'] = [ {'name': 'backup_admin_link_id', 'base': widgets.ReferenceField, 'passthrough': ['reference_url', 'required', 'label'], 'reference_url': 'user', 'required': False, 'label': params['logic'].getModel().backup_admin.verbose_name, 'example_text': ugettext('The link_id of the backup admin'), }, ] new_params['create_extra_dynaproperties'] = { 'email': forms.fields.EmailField(required=True), 'clean_backup_admin_link_id': cleaning.clean_users_not_same('backup_admin_link_id'), } new_params['edit_extra_dynaproperties'] = { 'clean_link_id' : cleaning.clean_link_id('link_id'), } new_params['public_field_extra'] = lambda entity: { 'ideas': list_helper.urlize(entity.ideas), } new_params['public_field_keys'] = new_params['self_field_keys'] = [ "name", "link_id", "ideas", "status", ] new_params['public_field_names'] = new_params['self_field_names'] = [ "Name", "Link ID", "Ideas Page", "Status", ] new_params['self_field_extra'] = lambda entity: { 'ideas': list_helper.urlize(entity.ideas), 'status': "accepted" if entity.status == "accepted" else "rejected" if entity.status == "rejected" else "under review", } params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params)
def manage(self, request, access_type, page_name=None, params=None, **kwargs): """View that allows Organization Admins to manage their Student Projects. For params see base.View().public() """ import soc.logic.lists from soc.modules.gsoc.views.models.grading_project_survey import view as \ grading_survey_view from soc.modules.gsoc.views.models.project_survey import view as \ project_survey_view entity = self._logic.getFromKeyFieldsOr404(kwargs) template = params['manage_template'] # get the context for this webpage context = responses.getUniversalContext(request) responses.useJavaScript(context, params['js_uses_all']) context['page_name'] = "%s '%s' from %s" % (page_name, entity.title, entity.student.name()) context['entity'] = entity if project_logic.canChangeMentors(entity): # only accepted project can have their mentors managed self._enableMentorManagement(entity, params, context) # list all surveys for this Project's Program gps_params = grading_survey_view.getParams().copy() gps_params['list_description'] = \ 'List of all Mentor Evaluations for this Project' gps_params['public_row_extra'] = lambda entity, *args: {} gps_params['public_row_action'] = {} gps_params['public_field_keys'] = [ "title", "taken_by", "taken_on", "record_url", "take_url" ] gps_params['public_field_names'] = [ "Title", "Taken by", "Taken on", "View", "(Re) Take", ] no_record = self.DEF_NO_RECORD_AVAILABLE_MSG # TODO(SRabbelier): use buttons instead project_entity = entity getExtra = lambda params: lambda entity, re: { "taken_by": no_record if not re(entity) else re(entity).user.name, "taken_on": no_record if not re(entity) else str(re(entity).modified), "record_url": no_record if not re(entity) else lists.urlize( redirects.getViewSurveyRecordRedirect(re(entity), params), name=self.DEF_VIEW_RECORD_MSG), "take_url": lists.urlize(redirects.getTakeProjectSurveyRedirect( project_entity, { 'survey': entity, 'params': params }), name=self.DEF_TAKE_SURVEY_MSG), } gps_params['public_field_extra'] = getExtra(gps_params) # get the ProjectSurvey list ps_params = project_survey_view.getParams().copy() ps_params['list_description'] = \ 'List of all Student Evaluations for this Project' ps_params['public_row_extra'] = lambda entity, *args: {} ps_params['public_row_action'] = {} ps_params['public_field_keys'] = gps_params['public_field_keys'] ps_params['public_field_names'] = gps_params['public_field_names'] ps_params['public_field_ignore'] = ["take_url"] ps_params['public_field_extra'] = getExtra(ps_params) if lists.isDataRequest(request): return self._getManageData(request, gps_params, ps_params, entity) gps_list = lists.getListGenerator(request, gps_params, idx=0) ps_list = lists.getListGenerator(request, ps_params, idx=1) # store both lists in the content content = [gps_list, ps_list] context['evaluation_list'] = soc.logic.lists.Lists(content) if request.POST: return self.managePost(request, template, context, params, entity, **kwargs) else: #request.GET return self.manageGet(request, template, context, params, entity, **kwargs)