Пример #1
0
    def __init__(self, params):
        """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['extra_dynaexclude'] = ['tos']

        new_params['edit_extra_dynaproperties'] = {
            'tos_link_id':
            widgets.ReferenceField(
                reference_url='document',
                filter=['scope_path'],
                required=False,
                filter_fields={'prefix': params['document_prefix']},
                label=ugettext('Terms of Service Document link ID'),
                help_text=soc.models.work.Work.link_id.help_text),
            'clean':
            cleaning.clean_refs(params, ['home_link_id', 'tos_link_id']),
        }

        params = dicts.merge(params, new_params, sub_merge=True)

        super(View, self).__init__(params=params)
Пример #2
0
  def __init__(self, params):
    """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['extra_dynaexclude'] = ['tos']

    new_params['edit_extra_dynaproperties'] = {
        'tos_link_id': widgets.ReferenceField(
            reference_url='document', filter=['scope_path'], required=False,
            filter_fields={'prefix': params['document_prefix']},
            label=ugettext('Terms of Service Document link ID'),
            help_text=soc.models.work.Work.link_id.help_text),
        'clean': cleaning.clean_refs(params,
                                     ['home_link_id', 'tos_link_id']),
        }

    params = dicts.merge(params, new_params, sub_merge=True)

    super(View, self).__init__(params=params)
Пример #3
0
  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.Checker(params)
    rights['any_access'] = ['allow']
    rights['show'] = ['allow']
    rights['create'] = [('checkSeeded', ['checkHasActiveRoleForScope', 
        host_logic.logic])]
    rights['edit'] = ['checkIsHostForProgram']
    rights['delete'] = ['checkIsDeveloper']
    rights['assign_slots'] = ['checkIsHostForProgram']
    rights['slots'] = ['checkIsHostForProgram']
    rights['show_duplicates'] = ['checkIsHostForProgram']
    rights['assigned_proposals'] = ['checkIsHostForProgram']
    rights['accepted_orgs'] = [('checkIsAfterEvent',
        ['accepted_organization_announced_deadline', '__all__'])]
    rights['list_projects'] = [('checkIsAfterEvent',
        ['accepted_students_announced_deadline', '__all__'])]

    new_params = {}
    new_params['logic'] = soc.logic.models.program.logic
    new_params['rights'] = rights

    new_params['scope_view'] = sponsor_view
    new_params['scope_redirect'] = redirects.getCreateRedirect

    new_params['name'] = "Program"
    new_params['sidebar_grouping'] = 'Programs'
    new_params['document_prefix'] = "program"

    new_params['extra_dynaexclude'] = ['timeline', 'org_admin_agreement',
        'mentor_agreement', 'student_agreement', 'slots_allocation']

    patterns = []
    patterns += [
        (r'^%(url_name)s/(?P<access_type>assign_slots)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.assign_slots',
          'Assign slots'),
        (r'^%(url_name)s/(?P<access_type>slots)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.slots',
          'Assign slots (JSON)'),
        (r'^%(url_name)s/(?P<access_type>show_duplicates)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.show_duplicates',
          'Show duplicate slot assignments'),
        (r'^%(url_name)s/(?P<access_type>assigned_proposals)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.assigned_proposals',
          "Assigned proposals for multiple organizations"),
        (r'^%(url_name)s/(?P<access_type>accepted_orgs)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.accepted_orgs',
          "List all accepted organizations"),
        (r'^%(url_name)s/(?P<access_type>list_projects)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.list_projects',
          "List all student projects"),
        ]

    new_params['extra_django_patterns'] = patterns

    new_params['create_dynafields'] = [
        {'name': 'link_id',
         'base': forms.fields.CharField,
         'label': 'Program Link ID',
         },
        ]

    # TODO add clean field to check for uniqueness in link_id and scope_path
    new_params['create_extra_dynaproperties'] = {
        'description': forms.fields.CharField(widget=helper.widgets.TinyMCE(
            attrs={'rows':10, 'cols':40})),
        'accepted_orgs_msg': forms.fields.CharField(
            widget=helper.widgets.TinyMCE(attrs={'rows':10, 'cols':40})),
        'scope_path': forms.CharField(widget=forms.HiddenInput, required=True),
        'workflow': forms.ChoiceField(choices=[('gsoc','Project-based'),
            ('ghop','Task-based')], required=True),
        }

    reference_fields = [
        ('org_admin_agreement_link_id', soc.models.work.Work.link_id.help_text,
         ugettext('Organization Admin Agreement Document link ID')),
        ('mentor_agreement_link_id', soc.models.work.Work.link_id.help_text,
         ugettext('Mentor Agreement Document link ID')),
        ('student_agreement_link_id', soc.models.work.Work.link_id.help_text,
         ugettext('Student Agreement Document link ID')),
        ('home_link_id', soc.models.work.Work.link_id.help_text,
         ugettext('Home page Document link ID')),
        ]

    result = {}

    for key, help_text, label in reference_fields:
      result[key] = widgets.ReferenceField(
          reference_url='document', filter=['__scoped__'],
          filter_fields={'prefix': new_params['document_prefix']},
          required=False, label=label, help_text=help_text)

    result['workflow'] = forms.CharField(widget=widgets.ReadOnlyInput(),
                                         required=True)
    result['clean'] = cleaning.clean_refs(new_params,
                                          [i for i,_,_ in reference_fields])

    new_params['edit_extra_dynaproperties'] = result

    document_references = [
        ('org_admin_agreement_link_id', 'org_admin_agreement',
         lambda x: x.org_admin_agreement),
        ('mentor_agreement_link_id', 'mentor_agreement',
         lambda x: x.mentor_agreement),
        ('student_agreement_link_id', 'student_agreement',
         lambda x: x.student_agreement),
        ]

    new_params['references'] = document_references

    params = dicts.merge(params, new_params, sub_merge=True)

    super(View, self).__init__(params=params)
Пример #4
0
  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'])
    }
Пример #5
0
  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'] = [('checkHasActiveRoleForKeyFieldsAsScope',
                           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'] = [('checkHasActiveRoleForKeyFieldsAsScope',
                                org_admin_logic.logic)]
    rights['list_roles'] = [('checkHasActiveRoleForKeyFieldsAsScope',
                             org_admin_logic.logic)]
    rights['applicant'] = [('checkIsApplicationAccepted',
                            org_app_logic.logic)]
    rights['list_proposals'] = [('checkHasAny', [
        [('checkHasActiveRoleForKeyFieldsAsScope', [org_admin_logic.logic]),
         ('checkHasActiveRoleForKeyFieldsAsScope', [mentor_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['list_row'] = 'soc/organization/list/row.html'
    new_params['list_heading'] = 'soc/organization/list/heading.html'
    new_params['home_template'] = 'soc/organization/home.html'

    new_params['application_logic'] = org_app_logic
    new_params['group_applicant_url'] = True
    new_params['sans_link_id_public_list'] = True

    new_params['extra_dynaexclude'] = ['slots', 'slots_calculated',
                                       'nr_applications', 'nr_mentors']

    patterns = []

    patterns += [
        (r'^%(url_name)s/(?P<access_type>apply_mentor)/%(scope)s$',
        'soc.views.models.%(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$',
        'soc.views.models.%(module_name)s.list_proposals',
        "List of all Student Proposals for this %(name)s"),
        ]

    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})),
        'contrib_template': forms.fields.CharField(
            widget=helper.widgets.FullTinyMCE(
                attrs={'rows': 25, 'cols': 100})),
        'clean_description': cleaning.clean_html_content('description'),
        'clean_contrib_template': cleaning.clean_html_content(
            'contrib_template'),
        'clean_ideas': cleaning.clean_url('ideas'),
        'clean': cleaning.validate_new_group('link_id', 'scope_path',
            soc.logic.models.organization, org_app_logic)
        }

    new_params['edit_extra_dynaproperties'] = {
        'clean': cleaning.clean_refs(new_params, ['home_link_id'])
        }

    params = dicts.merge(params, new_params)

    super(View, self).__init__(params=params)

    # create and store the special form for applicants
    updated_fields = {
        'link_id': forms.CharField(widget=widgets.ReadOnlyInput(),
            required=False),
        'clean_link_id': cleaning.clean_link_id('link_id')
        }

    applicant_create_form = dynaform.extendDynaForm(
        dynaform = self._params['create_form'],
        dynaproperties = updated_fields)

    self._params['applicant_create_form'] = applicant_create_form
Пример #6
0
    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.Checker(params)
        rights['any_access'] = ['allow']
        rights['show'] = ['allow']
        rights['create'] = [('checkSeeded',
                             ['checkHasRoleForScope', host_logic.logic])]
        rights['edit'] = ['checkIsHostForProgram']
        rights['delete'] = ['checkIsDeveloper']
        rights['accepted_orgs'] = [('checkIsAfterEvent', [
            'accepted_organization_announced_deadline', '__all__',
            program_logic.logic
        ])]

        new_params = {}
        new_params['logic'] = soc.logic.models.program.logic
        new_params['rights'] = rights

        new_params['scope_view'] = sponsor_view
        new_params['scope_redirect'] = redirects.getCreateRedirect

        new_params['name'] = "Program"
        new_params['sidebar_grouping'] = 'Programs'
        new_params['document_prefix'] = 'program'

        new_params['extra_dynaexclude'] = [
            'timeline', 'org_admin_agreement', 'mentor_agreement',
            'student_agreement', 'about_page', 'events_page',
            'connect_with_us_page', 'privacy_policy'
        ]

        patterns = []
        patterns += [
            (r'^%(url_name)s/(?P<access_type>assign_slots)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.assign_slots',
             'Assign slots'),
            (r'^%(url_name)s/(?P<access_type>slots)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.slots',
             'Assign slots (JSON)'),
            (r'^%(url_name)s/(?P<access_type>show_duplicates)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.show_duplicates',
             'Show duplicate slot assignments'),
            (r'^%(url_name)s/(?P<access_type>assigned_proposals)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.assigned_proposals',
             "Assigned proposals for multiple organizations"),
            (r'^%(url_name)s/(?P<access_type>accepted_orgs)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.accepted_orgs',
             "List all accepted organizations"),
            (r'^%(url_name)s/(?P<access_type>list_projects)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.list_projects',
             "List all Student Projects"),
            (r'^%(url_name)s/(?P<access_type>list_participants)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.list_participants',
             "List all Participants for"),
        ]

        new_params['extra_django_patterns'] = patterns

        new_params['create_dynafields'] = [
            {
                'name': 'link_id',
                'base': forms.fields.CharField,
                'label': 'Program Link ID',
            },
        ]

        # TODO: add clean field to check for uniqueness in link_id and scope_path
        new_params['create_extra_dynaproperties'] = {
            'description':
            forms.fields.CharField(widget=helper.widgets.TinyMCE(attrs={
                'rows': 10,
                'cols': 40
            })),
            'accepted_orgs_msg':
            forms.fields.CharField(required=False,
                                   widget=helper.widgets.TinyMCE(attrs={
                                       'rows': 10,
                                       'cols': 40
                                   })),
            'scope_path':
            forms.CharField(widget=forms.HiddenInput, required=True),
            'is_active':
            forms.BooleanField(required=False),
        }

        params = dicts.merge(params, new_params, sub_merge=True)

        new_params = {}

        reference_fields = [
            ('org_admin_agreement_link_id',
             soc.models.work.Work.link_id.help_text,
             ugettext('Organization Admin Agreement Document link ID')),
            ('mentor_agreement_link_id',
             soc.models.work.Work.link_id.help_text,
             ugettext('Mentor Agreement Document link ID')),
            ('student_agreement_link_id',
             soc.models.work.Work.link_id.help_text,
             ugettext('Student Agreement Document link ID')),
            ('home_link_id', soc.models.work.Work.link_id.help_text,
             ugettext('Home page Document link ID')),
            ('about_page_link_id', soc.models.work.Work.link_id.help_text,
             ugettext('About Page Document link ID')),
            ('events_page_link_id', soc.models.work.Work.link_id.help_text,
             ugettext('Events Page Document link ID')),
            ('connect_with_us_page_link_id',
             soc.models.work.Work.link_id.help_text,
             ugettext('Connect With Us Page Document link ID')),
            ('privacy_policy_link_id', soc.models.work.Work.link_id.help_text,
             ugettext('Privacy Policy Page Document link ID')),
        ]

        result = {}

        for key, help_text, label in reference_fields:
            result[key] = widgets.ReferenceField(
                reference_url='document',
                filter=['__scoped__'],
                filter_fields={'prefix': params['document_prefix']},
                required=False,
                label=label,
                help_text=help_text)

        result['clean'] = cleaning.clean_refs(
            params, [i for i, _, _ in reference_fields])

        new_params['edit_extra_dynaproperties'] = result

        document_references = [
            ('org_admin_agreement_link_id', 'org_admin_agreement',
             lambda x: x.org_admin_agreement),
            ('mentor_agreement_link_id', 'mentor_agreement',
             lambda x: x.mentor_agreement),
            ('student_agreement_link_id', 'student_agreement',
             lambda x: x.student_agreement),
            ('about_page_link_id', 'about_page', lambda x: x.about_page),
            ('events_page_link_id', 'events_page', lambda x: x.events_page),
            ('connect_with_us_page_link_id', 'connect_with_us_page',
             lambda x: x.connect_with_us_page),
            ('privacy_policy_link_id', 'privacy_policy',
             lambda x: x.privacy_policy),
        ]

        new_params['references'] = document_references

        new_params['public_field_keys'] = ["name", "scope_path"]
        new_params['public_field_names'] = ["Program Name", "Program Owner"]

        params = dicts.merge(params, new_params, sub_merge=True)

        super(View, self).__init__(params=params)
Пример #7
0
 def testCleanRefs(self):
     """Tests that references can be cleaned.
 """
     document_prefix = 'site'
     params = {'logic': site_logic, 'document_prefix': document_prefix}
     fields = ['ref']
     clean_field = cleaning.clean_refs(params, fields)
     # Test that the format of the value of field is not validated, i.e.
     # no exception is raised even if the filled document link_id
     # is not a valid link_id
     document_link_id = 'v1_@?'
     site = site_logic.getSingleton()
     self.form.cleaned_data = {
         'link_id': site.link_id,
         'scope_path': site.scope_path,
         'ref': document_link_id,
     }
     self.form._errors = {fields[0]: None}
     clean_field(self.form)
     # Test that the value of field will be removed and error information
     # will be added to _errors field if it is a valid but nonexistent
     # document link_id
     document_link_id = 'a_document'
     site = site_logic.getSingleton()
     self.form.cleaned_data = {
         'link_id': site.link_id,
         'scope_path': site.scope_path,
         'ref': document_link_id,
     }
     self.form._errors = {fields[0]: None}
     after_cleaned_data = clean_field(self.form)
     self.assertEqual(after_cleaned_data.get('ref', None), None)
     self.assertNotEqual(self.form._errors[fields[0]], None)
     # Test that the value of field will be returned, a field named resolved_ref
     # containing the document will be added and no error messges will be added
     # if it is a valid and exisiting document link_id
     document_link_id = 'a_document'
     site = site_logic.getSingleton()
     self.form.cleaned_data = {
         'link_id': site.link_id,
         'scope_path': site.scope_path,
         'ref': document_link_id,
     }
     self.form._errors = {fields[0]: None}
     document_properties = {
         'link_id': document_link_id,
         'scope_path': site.link_id,
         'scope': site,
         'prefix': document_prefix,
         'author': self.user,
         'title': 'Home Page',
         'short_name': 'Home',
         'content': 'This is the Home Page',
         'modified_by': self.user,
     }
     document = document_logic.updateOrCreateFromFields(document_properties)
     after_cleaned_data = clean_field(self.form)
     self.assertEqual(after_cleaned_data['ref'], document_link_id)
     self.assertEqual(after_cleaned_data['resolved_ref'].link_id,
                      document_link_id)
     self.assertEqual(self.form._errors[fields[0]], None)
Пример #8
0
 def testCleanRefs(self):
   """Tests that references can be cleaned.
   """
   document_prefix = 'site'
   params = {'logic': site_logic, 'document_prefix': document_prefix}
   fields = ['ref']
   clean_field = cleaning.clean_refs(params, fields)
   # Test that the format of the value of field is not validated, i.e. 
   # no exception is raised even if the filled document link_id 
   # is not a valid link_id
   document_link_id = 'v1_@?'
   site = site_logic.getSingleton()
   self.form.cleaned_data = {
       'link_id': site.link_id,
       'scope_path': site.scope_path,
       'ref': document_link_id,
       }
   self.form._errors = {fields[0]: None}
   clean_field(self.form)
   # Test that the value of field will be removed and error information 
   # will be added to _errors field if it is a valid but nonexistent 
   # document link_id
   document_link_id = 'a_document'
   site = site_logic.getSingleton()
   self.form.cleaned_data = {
       'link_id': site.link_id,
       'scope_path': site.scope_path,
       'ref': document_link_id,
       }
   self.form._errors = {fields[0]: None}
   after_cleaned_data = clean_field(self.form)
   self.assertEqual(after_cleaned_data.get('ref', None), None)
   self.assertNotEqual(self.form._errors[fields[0]], None)
   # Test that the value of field will be returned, a field named resolved_ref
   # containing the document will be added and no error messges will be added 
   # if it is a valid and exisiting document link_id
   document_link_id = 'a_document'
   site = site_logic.getSingleton()
   self.form.cleaned_data = {
       'link_id': site.link_id,
       'scope_path': site.scope_path,
       'ref': document_link_id,
       }
   self.form._errors = {fields[0]: None}
   document_properties = {
       'link_id': document_link_id,
       'scope_path': site.link_id,
       'scope': site,
       'prefix': document_prefix,
       'author': self.user,
       'title': 'Home Page',
       'short_name': 'Home',
       'content': 'This is the Home Page',
       'modified_by': self.user,
       }
   document = document_logic.updateOrCreateFromFields(document_properties)
   after_cleaned_data = clean_field(self.form)
   self.assertEqual(after_cleaned_data['ref'], document_link_id)
   self.assertEqual(after_cleaned_data['resolved_ref'].link_id, 
                    document_link_id)
   self.assertEqual(self.form._errors[fields[0]], None)
Пример #9
0
    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)