app/soc/views/models/user.py
changeset 481 94834a1e6c01
parent 479 50bab5e71a66
child 482 839740b061ad
equal deleted inserted replaced
480:9b07ddeb1412 481:94834a1e6c01
    41 class CreateForm(helper.forms.BaseForm):
    41 class CreateForm(helper.forms.BaseForm):
    42   """Django form displayed when creating a User.
    42   """Django form displayed when creating a User.
    43   """
    43   """
    44 
    44 
    45   email = forms.EmailField(
    45   email = forms.EmailField(
    46       label=soc.models.user.User.id.verbose_name,
    46       label=soc.models.user.User.account.verbose_name,
    47       help_text=soc.models.user.User.id.help_text)
    47       help_text=soc.models.user.User.account.help_text)
    48 
    48 
    49   link_name = forms.CharField(
    49   link_name = forms.CharField(
    50       label=soc.models.user.User.link_name.verbose_name,
    50       label=soc.models.user.User.link_name.verbose_name,
    51       help_text=soc.models.user.User.link_name.help_text)
    51       help_text=soc.models.user.User.link_name.help_text)
    52 
    52 
    72       raise forms.ValidationError("This link name is already in use.")
    72       raise forms.ValidationError("This link name is already in use.")
    73 
    73 
    74     return link_name
    74     return link_name
    75 
    75 
    76   def clean_email(self):
    76   def clean_email(self):
    77     form_id = users.User(email=self.cleaned_data.get('email'))
    77     form_account = users.User(email=self.cleaned_data.get('email'))
    78     key_name = self.data.get('key_name')
    78     key_name = self.data.get('key_name')
    79     if key_name:
    79     if key_name:
    80       user = user_logic.logic.getFromKeyName(key_name)
    80       user = user_logic.logic.getFromKeyName(key_name)
    81       old_email = user.id.email()
    81       old_email = user.account.email()
    82     else:
    82     else:
    83       old_email = None
    83       old_email = None
    84 
    84 
    85     new_email = form_id.email()
    85     new_email = form_account.email()
    86 
    86 
    87     if new_email != old_email \
    87     if new_email != old_email \
    88         and user_logic.logic.getFromFields(email=new_email):
    88         and user_logic.logic.getFromFields(email=new_email):
    89       raise forms.ValidationError("This account is already in use.")
    89       raise forms.ValidationError("This account is already in use.")
    90 
    90 
   162       kwargs: The Key Fields for the specified entity
   162       kwargs: The Key Fields for the specified entity
   163     """
   163     """
   164 
   164 
   165     params = dicts.merge(params, {'edit_template': 'soc/user/edit_self.html'})
   165     params = dicts.merge(params, {'edit_template': 'soc/user/edit_self.html'})
   166 
   166 
   167     id = users.get_current_user()
   167     properties = {'account': users.get_current_user()}
   168     properties = {'id': id}
       
   169 
   168 
   170     entity = self._logic.getForFields(properties, unique=True)
   169     entity = self._logic.getForFields(properties, unique=True)
   171     keys = self._logic.getKeyFieldNames()
   170     keys = self._logic.getKeyFieldNames()
   172     values = self._logic.getKeyValues(entity)
   171     values = self._logic.getKeyValues(entity)
   173     key_fields = dicts.zip(keys, values)
   172     key_fields = dicts.zip(keys, values)
   176   
   175   
   177   def _editGet(self, request, entity, form):
   176   def _editGet(self, request, entity, form):
   178     """See base.View._editGet().
   177     """See base.View._editGet().
   179     """
   178     """
   180     # fill in the email field with the data from the entity
   179     # fill in the email field with the data from the entity
   181     form.fields['email'].initial = entity.id.email()
   180     form.fields['email'].initial = entity.account.email()
   182     
   181     
   183 
   182 
   184   def _editPost(self, request, entity, fields):
   183   def _editPost(self, request, entity, fields):
   185     """See base.View._editPost().
   184     """See base.View._editPost().
   186     """
   185     """
   187     # fill in the id field with the user created from email
   186     # fill in the account field with the user created from email
   188     fields['id'] = users.User(fields['email'])
   187     fields['account'] = users.User(fields['email'])
   189 
   188 
   190 
   189 
   191 view = View()
   190 view = View()
   192 
   191 
   193 create = view.create
   192 create = view.create