Esempio n. 1
0
    def create(self, **kwargs):
        from orders_manager.models import Client

        client = Client()
        client.name = kwargs.get('name')
        client.phone = trim_phone_number(kwargs.get('phone'))
        client.phone_2 = trim_phone_number(kwargs.get('phone_2'))
        client.email = kwargs.get('email')
        client.vk_link = kwargs.get('vk_link')
        client.odnoklassniki_link = kwargs.get('odnoklassniki_link')
        client.instagram_link = kwargs.get('instagram_link')
        client.facebook_link = kwargs.get('facebook_link')
        client.secondby_link = kwargs.get('secondby_link')
        client.comments = kwargs.get('comments')
        client.save()

        return client
Esempio n. 2
0
    def create(self, **kwargs):
        from orders_manager.models import Client

        client = Client()
        client.name = kwargs.get('name')
        client.phone = trim_phone_number(kwargs.get('phone'))
        client.phone_2 = trim_phone_number(kwargs.get('phone_2'))
        client.email = kwargs.get('email')
        client.vk_link = kwargs.get('vk_link')
        client.odnoklassniki_link = kwargs.get('odnoklassniki_link')
        client.instagram_link = kwargs.get('instagram_link')
        client.facebook_link = kwargs.get('facebook_link')
        client.secondby_link = kwargs.get('secondby_link')
        client.comments = kwargs.get('comments')
        client.save()

        return client
Esempio n. 3
0
 def update_or_create(self, defaults=None, **kwargs):
     from orders_manager.utils.data_utils import trim_phone_number
     try:
         if kwargs.get('id'):
             client = self.get(id=kwargs.pop('id'))
         else:
             client = self.get(
                 Q(phone=trim_phone_number(kwargs.get('phone')))
                 & Q(is_active=True))
         for attr, val in kwargs.items():
             if attr == 'phone':
                 exists_cl = self.filter(~Q(id=client.id) & Q(phone=val)
                                         & Q(is_active=True)).all()
                 if exists_cl:
                     raise ValueError(
                         'Client with same phone already exists.')
             setattr(client, attr, val)
         client.save()
     except self.model.DoesNotExist:
         client = self.create(**kwargs)
     return client
Esempio n. 4
0
 def update_or_create(self, defaults=None, **kwargs):
     from orders_manager.utils.data_utils import trim_phone_number
     try:
         if kwargs.get('id'):
             client = self.get(id=kwargs.pop('id'))
         else:
             client = self.get(
                 Q(phone=trim_phone_number(kwargs.get('phone'))) &
                 Q(is_active=True)
             )
         for attr, val in kwargs.items():
             if attr == 'phone':
                 exists_cl = self.filter(
                     ~Q(id=client.id) &
                     Q(phone=val) &
                     Q(is_active=True)
                 ).all()
                 if exists_cl:
                     raise ValueError('Client with same phone already exists.')
             setattr(client, attr, val)
         client.save()
     except self.model.DoesNotExist:
         client = self.create(**kwargs)
     return client