app/soc/views/models/request.py
changeset 562 1bf2beedda03
parent 561 4db464032b25
child 569 96d9655a7538
equal deleted inserted replaced
561:4db464032b25 562:1bf2beedda03
    52 
    52 
    53   class Meta:
    53   class Meta:
    54     model = soc.models.request.Request
    54     model = soc.models.request.Request
    55 
    55 
    56     #: list of model fields which will *not* be gathered by the form 
    56     #: list of model fields which will *not* be gathered by the form 
    57     exclude = ['inheritance_line', 'requester', 'to', 'role', 'declined']
    57     exclude = ['inheritance_line', 'scope', 'scope_path', 'link_id', 'role', 'declined']
    58 
    58 
    59   role = forms.CharField(widget=helper.widgets.ReadOnlyInput())
    59   role = forms.CharField(widget=helper.widgets.ReadOnlyInput())
    60 
    60 
    61   user = forms.CharField(
    61   user = forms.CharField(
    62       label=soc.models.request.Request.requester.verbose_name,
    62       label=soc.models.request.Request.link_id.verbose_name,
    63       help_text=soc.models.request.Request.requester.help_text,
    63       help_text=soc.models.request.Request.link_id.help_text,
    64       widget=helper.widgets.ReadOnlyInput())  
    64       widget=helper.widgets.ReadOnlyInput())
    65 
    65 
    66   group = forms.CharField(
    66   group = forms.CharField(
    67       label=soc.models.request.Request.to.verbose_name,
    67       label=soc.models.request.Request.scope.verbose_name,
    68       help_text=soc.models.request.Request.to.help_text,
    68       help_text=soc.models.request.Request.scope.help_text,
    69       widget=helper.widgets.ReadOnlyInput())
    69       widget=helper.widgets.ReadOnlyInput())
    70 
    70 
    71   def clean_user(self):
    71   def clean_user(self):
    72     self.cleaned_data['requester'] =  user_logic.logic.getForFields(
    72     self.cleaned_data['requester'] =  user_logic.logic.getForFields(
    73         {'link_id': self.cleaned_data['user']}, unique=True)
    73         {'link_id': self.cleaned_data['user']}, unique=True)
   145     user_entity = user_logic.logic.getForFields(properties, unique=True)
   145     user_entity = user_logic.logic.getForFields(properties, unique=True)
   146 
   146 
   147     # construct the Unhandled Requests list
   147     # construct the Unhandled Requests list
   148 
   148 
   149     # only select the requests for this user that haven't been handled yet
   149     # only select the requests for this user that haven't been handled yet
   150     filter = {'requester': user_entity,
   150     filter = {'link_id': user_entity.link_id,
   151               'declined' : None}
   151               'group_accepted' : True}
   152     
   152     
   153     uh_params = params.copy()
   153     uh_params = params.copy()
   154     uh_params['list_action'] = (self.inviteAcceptedRedirect, None)
   154     uh_params['list_action'] = (self.inviteAcceptedRedirect, None)
   155     uh_params['list_description'] = ugettext_lazy(
   155     uh_params['list_description'] = ugettext_lazy(
   156         "An overview of your unhandled requests")
   156         "An overview of your unhandled requests")
   159 
   159 
   160     # construct the Open Requests list
   160     # construct the Open Requests list
   161     
   161     
   162     # only select the requests for the user
   162     # only select the requests for the user
   163     # that haven't been accepted by an admin yet
   163     # that haven't been accepted by an admin yet
   164     filter = {'requester' : user_entity,
   164     filter = {'link_id' : user_entity.link_id,
   165               'accepted' : None}
   165               'group_accepted' : False}
   166     
   166     
   167     ar_params = params.copy()
   167     ar_params = params.copy()
   168     ar_params['list_description'] = ugettext_lazy(
   168     ar_params['list_description'] = ugettext_lazy(
   169         "An overview of your requests, that haven't been handled by an admin yet")
   169         "An overview of your requests, that haven't been handled by an admin yet")
   170     
   170     
   179   def inviteAcceptedRedirect(self, entity, _):
   179   def inviteAcceptedRedirect(self, entity, _):
   180     """Returns the redirect for accepting a request
   180     """Returns the redirect for accepting a request
   181     """
   181     """
   182 
   182 
   183     return '/%s/create/%s/%s' % (
   183     return '/%s/create/%s/%s' % (
   184         entity.role, entity.to.link_id, entity.requester.link_id)
   184         entity.role, entity.scope_path, entity.link_id)
   185 
   185 
   186   def _editSeed(self, request, seed):
   186   def _editSeed(self, request, seed):
   187     """See base.View._editGet().
   187     """See base.View._editGet().
   188     """
   188     """
   189 
   189 
   190     # fill in the email field with the data from the entity
   190     # fill in the email field with the data from the entity
   191     seed['user'] = seed['user_ln']
   191     seed['user'] = seed['link_id']
   192     seed['group'] = seed['group_ln']
   192     seed['group'] = seed['scope_path']
   193 
   193 
   194   def _editGet(self, request, entity, form):
   194   def _editGet(self, request, entity, form):
   195     """See base.View._editGet().
   195     """See base.View._editGet().
   196     """
   196     """
   197 
   197 
   198     # fill in the email field with the data from the entity
   198     # fill in the email field with the data from the entity
   199     form.fields['user'].initial = entity.requester.link_id
   199     form.fields['user'].initial = entity.link_id
   200     form.fields['group'].initial = entity.to.link_id 
   200     form.fields['group'].initial = entity.scope_path
   201 
   201 
   202   def _editPost(self, request, entity, fields):
   202   def _editPost(self, request, entity, fields):
   203     """See base.View._editPost().
   203     """See base.View._editPost().
   204     """
   204     """
   205 
   205 
   206     # fill in the account field with the user created from email
   206     # fill in the account field with the user created from email
   207     fields['user_ln'] = fields['requester'].link_id
   207     fields['link_id'] = fields['requester'].link_id
   208     fields['group_ln'] = fields['to'].link_id
   208     fields['scope_path'] = fields['to'].link_id
       
   209     fields['scope'] = fields['to']
   209 
   210 
   210 
   211 
   211 view = View()
   212 view = View()
   212 
   213 
   213 create = view.create
   214 create = view.create