app/soc/views/models/role.py
changeset 1722 7f285e96cb17
parent 1660 1b8e2917f6a7
child 1723 259bba384c60
equal deleted inserted replaced
1721:9acf4fe1b9bb 1722:7f285e96cb17
   137        'latitude':forms.fields.FloatField(widget=forms.HiddenInput,
   137        'latitude':forms.fields.FloatField(widget=forms.HiddenInput,
   138                                           required=False),
   138                                           required=False),
   139        'longitude': forms.fields.FloatField(widget=forms.HiddenInput,
   139        'longitude': forms.fields.FloatField(widget=forms.HiddenInput,
   140                                             required=False),
   140                                             required=False),
   141        'clean_link_id': cleaning.clean_existing_user('link_id'),
   141        'clean_link_id': cleaning.clean_existing_user('link_id'),
       
   142        'clean_res_street': cleaning.clean_ascii_only('res_street'),
       
   143        'clean_res_city': cleaning.clean_ascii_only('res_city'),
       
   144        'clean_res_state': cleaning.clean_ascii_only('res_state'),
       
   145        'clean_res_postalcode': cleaning.clean_ascii_only('res_postalcode'),
       
   146        'clean_ship_street': cleaning.clean_ascii_only('ship_street'),
       
   147        'clean_ship_city': cleaning.clean_ascii_only('ship_city'),
       
   148        'clean_ship_state': cleaning.clean_ascii_only('ship_state'),
       
   149        'clean_ship_postalcode': cleaning.clean_ascii_only('ship_postalcode'),
   142        'clean_home_page': cleaning.clean_url('home_page'),
   150        'clean_home_page': cleaning.clean_url('home_page'),
   143        'clean_blog': cleaning.clean_url('blog'),
   151        'clean_blog': cleaning.clean_url('blog'),
   144        'clean_photo_url': cleaning.clean_url('photo_url'),
   152        'clean_photo_url': cleaning.clean_url('photo_url'),
   145        'scope_path': forms.CharField(widget=forms.HiddenInput,
   153        'scope_path': forms.CharField(widget=forms.HiddenInput,
   146                                   required=True),
   154                                   required=True),
   147        }
   155        }
   148 
   156 
   149     new_params['extra_dynaexclude'] = ['user', 'status', 'agreed_to_tos_on']
   157     new_params['extra_dynaexclude'] = ['user', 'status', 'agreed_to_tos_on']
       
   158 
       
   159     new_params['disallow_last_resign'] = False
   150 
   160 
   151     params = dicts.merge(params, new_params, sub_merge=True)
   161     params = dicts.merge(params, new_params, sub_merge=True)
   152 
   162 
   153     super(View, self).__init__(params=params)
   163     super(View, self).__init__(params=params)
   154 
   164 
   424     # check to see if resign is true
   434     # check to see if resign is true
   425     get_dict = request.GET
   435     get_dict = request.GET
   426     resign = get_dict.get('resign')
   436     resign = get_dict.get('resign')
   427 
   437 
   428     if resign == 'true':
   438     if resign == 'true':
   429       # change the status of this role_entity to invalid
   439 
   430       fields = {'status': 'invalid'}
   440       if params.get('disallow_last_resign'):
   431       logic.updateEntityProperties(role_entity, fields)
   441         # check if the current role is the last for this scope
   432 
   442         fields = {'scope': role_entity.scope,
   433       # redirect to the roles listing
   443             'status': 'active'}
   434       return http.HttpResponseRedirect(redirect)
   444         roles = logic.getForFields(fields, limit=2)
       
   445 
       
   446         # if there is more then one left we can safely resign
       
   447         resign = len(roles) > 1
       
   448       else:
       
   449         resign = True
       
   450 
       
   451       if resign:
       
   452         # change the status of this role_entity to invalid
       
   453         fields = {'status': 'invalid'}
       
   454         logic.updateEntityProperties(role_entity, fields)
       
   455 
       
   456         # redirect to the roles listing
       
   457         return http.HttpResponseRedirect(redirect)
       
   458       else:
       
   459         # show error to the user
       
   460         context['not_allowed_to_resign'] = ugettext("This user can't be "
       
   461             "resigned, please make sure it's not the last %(name)s." % params)
   435 
   462 
   436     # set the appropriate context
   463     # set the appropriate context
   437     context['entity'] = role_entity
   464     context['entity'] = role_entity
   438     context['url_name'] = params['url_name']
   465     context['url_name'] = params['url_name']
   439     context['cancel_redirect'] = redirect
   466     context['cancel_redirect'] = redirect