예제 #1
0
def automatically_create_esteem_for_new_user(sender, **kwargs):
    """docstring for automatically_create_esteem_for_new_user"""
    user_profile = kwargs['instance']
    try:
        esteem = user_profile.esteem
    except Esteem.DoesNotExist:
        esteem = Esteem()
        esteem.save()
        user_profile.esteem = esteem
예제 #2
0
def automatically_create_esteem_for_new_user(sender, **kwargs):
    """Create an esteem value for a user if it does not exist."""
    user_profile = kwargs['instance']
    try:
        esteem = user_profile.esteem
    except Esteem.DoesNotExist:
        esteem = Esteem()
        esteem.save()
        user_profile.esteem = esteem
예제 #3
0
 def modify_esteem(self, data, esteem_id=None):
     """Create or modify an esteem object according to the specified value."""
     parsed_data = self._parse_xml_to_dict(data)
     if esteem_id:
         esteem = Esteem.objects.get(id=esteem_id)
     else:
         esteem = Esteem()
     try:
         user_id = self._get_id_from_atom_link(parsed_data['user'])
         user = User.objects.get(id=user_id)
         esteem.user = user
         esteem.value = parsed_data['value']
         esteem.save()
         return esteem
     except User.DoesNotExist:
         raise InvalidDataException("The user provided does not exist (id: %s)"
                 % (user_id))
     except KeyError, e:
         raise InvalidDataException("The data sent was missing an attribute!")