| 
									
										
										
										
											2016-04-23 19:00:20 +02:00
										 |  |  | from datetime import datetime | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | from django.conf import settings | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  | from django.contrib.auth.hashers import make_password | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  | from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, \ | 
					
						
							|  |  |  |     PermissionsMixin | 
					
						
							| 
									
										
										
										
											2016-04-23 19:00:20 +02:00
										 |  |  | from django.contrib.sites.models import Site | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  | from django.core.urlresolvers import reverse | 
					
						
							|  |  |  | from django.core.validators import RegexValidator | 
					
						
							|  |  |  | from django.db import models | 
					
						
							| 
									
										
										
										
											2017-06-22 13:22:14 +05:30
										 |  |  | from django.utils.crypto import get_random_string | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  | from django.utils.translation import ugettext_lazy as _ | 
					
						
							| 
									
										
										
										
											2016-05-01 14:13:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-11 05:19:56 +05:30
										 |  |  | from utils.mailer import BaseEmail | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  | from utils.mailer import DigitalGlarusRegistrationMailer | 
					
						
							|  |  |  | from utils.stripe_utils import StripeUtils | 
					
						
							| 
									
										
										
										
											2016-03-03 22:55:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  | REGISTRATION_MESSAGE = {'subject': "Validation mail", | 
					
						
							| 
									
										
										
										
											2017-06-29 17:34:40 +03:00
										 |  |  |                         'message': 'Please validate Your account under this link ' | 
					
						
							|  |  |  |                                    'http://localhost:8000/en-us/digitalglarus/login/validate/{}', | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |                         'from': 'test@test.com'} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-03 00:24:16 +03:00
										 |  |  | def get_anonymous_user_instance(CustomUser): | 
					
						
							| 
									
										
										
										
											2016-07-10 22:08:51 -05:00
										 |  |  |     return CustomUser(name='Anonymous', email='anonymous@ungleich.ch', | 
					
						
							|  |  |  |                       validation_slug=make_password(None)) | 
					
						
							| 
									
										
										
										
											2016-06-26 14:50:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  | class MyUserManager(BaseUserManager): | 
					
						
							|  |  |  |     def create_user(self, email, name, password=None): | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2016-03-16 00:26:49 +01:00
										 |  |  |         Creates and saves a User with the given email,name and password. | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |         """
 | 
					
						
							|  |  |  |         if not email: | 
					
						
							|  |  |  |             raise ValueError('Users must have an email address') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         user = self.model( | 
					
						
							|  |  |  |             email=self.normalize_email(email), | 
					
						
							| 
									
										
										
										
											2016-03-16 15:10:48 +01:00
										 |  |  |             name=name, | 
					
						
							|  |  |  |             validation_slug=make_password(None) | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2016-05-02 02:00:38 +02:00
										 |  |  |         user.is_admin = False | 
					
						
							| 
									
										
										
										
											2016-03-19 21:28:58 +01:00
										 |  |  |         user.set_password(password) | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |         user.save(using=self._db) | 
					
						
							|  |  |  |         return user | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def create_superuser(self, email, name, password): | 
					
						
							|  |  |  |         """
 | 
					
						
							| 
									
										
										
										
											2016-03-16 00:26:49 +01:00
										 |  |  |         Creates and saves a superuser with the given email, name and password. | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |         """
 | 
					
						
							|  |  |  |         user = self.create_user(email, | 
					
						
							|  |  |  |                                 password=password, | 
					
						
							| 
									
										
										
										
											2016-03-16 15:10:48 +01:00
										 |  |  |                                 name=name, | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |                                 ) | 
					
						
							|  |  |  |         user.is_admin = True | 
					
						
							| 
									
										
										
										
											2017-07-16 16:51:07 +03:00
										 |  |  |         user.is_active = True | 
					
						
							|  |  |  |         user.is_superuser = True | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |         user.save(using=self._db) | 
					
						
							|  |  |  |         return user | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-27 00:51:10 -05:00
										 |  |  | class CustomUser(AbstractBaseUser, PermissionsMixin): | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |     VALIDATED_CHOICES = ((0, 'Not validated'), (1, 'Validated')) | 
					
						
							| 
									
										
										
										
											2016-04-23 19:00:20 +02:00
										 |  |  |     site = models.ForeignKey(Site, default=1) | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |     name = models.CharField(max_length=50) | 
					
						
							|  |  |  |     email = models.EmailField(unique=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0) | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  |     validation_slug = models.CharField(db_index=True, unique=True, | 
					
						
							|  |  |  |                                        max_length=50) | 
					
						
							| 
									
										
										
										
											2016-05-02 02:00:38 +02:00
										 |  |  |     is_admin = models.BooleanField( | 
					
						
							| 
									
										
										
										
											2016-03-16 15:10:48 +01:00
										 |  |  |         _('staff status'), | 
					
						
							|  |  |  |         default=False, | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  |         help_text=_( | 
					
						
							|  |  |  |             'Designates whether the user can log into this admin site.'), | 
					
						
							| 
									
										
										
										
											2016-03-16 15:10:48 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     objects = MyUserManager() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     USERNAME_FIELD = "email" | 
					
						
							| 
									
										
										
										
											2016-03-07 19:19:25 +01:00
										 |  |  |     REQUIRED_FIELDS = ['name', 'password'] | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  |     def register(cls, name, password, email, app='digital_glarus', | 
					
						
							| 
									
										
										
										
											2017-09-22 12:01:09 +02:00
										 |  |  |                  base_url=None, send_email=True, account_details=None): | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |         user = cls.objects.filter(email=email).first() | 
					
						
							|  |  |  |         if not user: | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  |             user = cls.objects.create_user(name=name, email=email, | 
					
						
							|  |  |  |                                            password=password) | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |             if user: | 
					
						
							| 
									
										
										
										
											2017-06-11 05:19:56 +05:30
										 |  |  |                 if app == 'digital_glarus': | 
					
						
							|  |  |  |                     dg = DigitalGlarusRegistrationMailer(user.validation_slug) | 
					
						
							|  |  |  |                     dg.send_mail(to=user.email) | 
					
						
							|  |  |  |                 elif app == 'dcl': | 
					
						
							| 
									
										
										
										
											2017-06-19 12:30:37 +05:30
										 |  |  |                     dcl_text = settings.DCL_TEXT | 
					
						
							| 
									
										
										
										
											2017-06-11 05:19:56 +05:30
										 |  |  |                     user.is_active = False | 
					
						
							| 
									
										
										
										
											2017-06-22 13:22:14 +05:30
										 |  |  |                     if send_email is True: | 
					
						
							|  |  |  |                         email_data = { | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  |                             'subject': '{dcl_text} {account_activation}'.format( | 
					
						
							|  |  |  |                                 dcl_text=dcl_text, | 
					
						
							|  |  |  |                                 account_activation=_('Account Activation') | 
					
						
							|  |  |  |                             ), | 
					
						
							| 
									
										
										
										
											2017-06-23 04:35:33 +05:30
										 |  |  |                             'from_address': settings.DCL_SUPPORT_FROM_ADDRESS, | 
					
						
							| 
									
										
										
										
											2017-06-22 13:22:14 +05:30
										 |  |  |                             'to': user.email, | 
					
						
							| 
									
										
										
										
											2017-06-29 19:23:25 +03:00
										 |  |  |                             'context': {'base_url': base_url, | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  |                                         'activation_link': reverse( | 
					
						
							|  |  |  |                                             'hosting:validate', | 
					
						
							|  |  |  |                                             kwargs={ | 
					
						
							|  |  |  |                                                 'validate_slug': user.validation_slug}), | 
					
						
							| 
									
										
										
										
											2017-06-29 19:23:25 +03:00
										 |  |  |                                         'dcl_text': dcl_text | 
					
						
							| 
									
										
										
										
											2017-06-23 04:35:33 +05:30
										 |  |  |                                         }, | 
					
						
							| 
									
										
										
										
											2017-06-22 13:22:14 +05:30
										 |  |  |                             'template_name': 'user_activation', | 
					
						
							|  |  |  |                             'template_path': 'datacenterlight/emails/' | 
					
						
							|  |  |  |                         } | 
					
						
							| 
									
										
										
										
											2017-09-22 12:01:09 +02:00
										 |  |  |                         if account_details: | 
					
						
							|  |  |  |                             email_data['context'][ | 
					
						
							|  |  |  |                                 'account_details'] = account_details | 
					
						
							| 
									
										
										
										
											2017-06-22 13:22:14 +05:30
										 |  |  |                         email = BaseEmail(**email_data) | 
					
						
							|  |  |  |                         email.send() | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |                 return user | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 return None | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-01 17:17:46 -05:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def get_all_members(cls): | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  |         return cls.objects.filter( | 
					
						
							|  |  |  |             stripecustomer__membershiporder__isnull=False) | 
					
						
							| 
									
										
										
										
											2016-10-01 17:17:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def validate_url(cls, validation_slug): | 
					
						
							|  |  |  |         user = cls.objects.filter(validation_slug=validation_slug).first() | 
					
						
							|  |  |  |         if user: | 
					
						
							|  |  |  |             user.validated = 1 | 
					
						
							| 
									
										
										
										
											2016-03-16 15:10:48 +01:00
										 |  |  |             user.save() | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |             return True | 
					
						
							|  |  |  |         return False | 
					
						
							| 
									
										
										
										
											2016-03-07 19:19:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-22 13:22:14 +05:30
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def get_random_password(cls): | 
					
						
							|  |  |  |         return get_random_string(24) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-07 18:39:24 +01:00
										 |  |  |     def is_superuser(self): | 
					
						
							| 
									
										
										
										
											2016-03-16 15:10:48 +01:00
										 |  |  |         return False | 
					
						
							| 
									
										
										
										
											2016-03-07 19:19:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  |     def get_full_name(self): | 
					
						
							|  |  |  |         # The user is identified by their email address | 
					
						
							|  |  |  |         return self.email | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def get_short_name(self): | 
					
						
							|  |  |  |         # The user is identified by their email address | 
					
						
							|  |  |  |         return self.email | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __str__(self):  # __unicode__ on Python 2 | 
					
						
							|  |  |  |         return self.email | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-10 22:08:51 -05:00
										 |  |  |     # def has_perm(self, perm, obj=None): | 
					
						
							|  |  |  |     #     "Does the user have a specific permission?" | 
					
						
							|  |  |  |     #     # Simplest possible answer: Yes, always | 
					
						
							|  |  |  |     #     return self.is_admin | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def has_module_perms(self, app_label): | 
					
						
							|  |  |  |         "Does the user have permissions to view the app `app_label`?" | 
					
						
							|  |  |  |         # Simplest possible answer: Yes, always | 
					
						
							| 
									
										
										
										
											2016-05-02 02:00:38 +02:00
										 |  |  |         return self.is_admin | 
					
						
							| 
									
										
										
										
											2016-03-07 17:49:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     def is_staff(self): | 
					
						
							|  |  |  |         "Is the user a member of staff?" | 
					
						
							|  |  |  |         # Simplest possible answer: All admins are staff | 
					
						
							|  |  |  |         return self.is_admin | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 19:42:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 01:16:03 -05:00
										 |  |  | class StripeCustomer(models.Model): | 
					
						
							|  |  |  |     user = models.OneToOneField(CustomUser) | 
					
						
							|  |  |  |     stripe_id = models.CharField(unique=True, max_length=100) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-03 00:07:47 -05:00
										 |  |  |     def __str__(self): | 
					
						
							|  |  |  |         return "%s - %s" % (self.stripe_id, self.user.email) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |     @classmethod | 
					
						
							| 
									
										
										
										
											2017-09-22 12:01:09 +02:00
										 |  |  |     def create_stripe_api_customer(cls, email=None, token=None, | 
					
						
							|  |  |  |                                    customer_name=None): | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |         """
 | 
					
						
							|  |  |  |             This method creates a Stripe API customer with the given | 
					
						
							| 
									
										
										
										
											2017-09-28 14:49:17 +02:00
										 |  |  |             email, token and customer_name. This is different from | 
					
						
							|  |  |  |             get_or_create method below in that it does not create a | 
					
						
							|  |  |  |             CustomUser and associate the customer created in stripe | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |             with it, while get_or_create does that before creating the | 
					
						
							|  |  |  |             stripe user. | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         stripe_utils = StripeUtils() | 
					
						
							|  |  |  |         stripe_data = stripe_utils.create_customer(token, email, customer_name) | 
					
						
							|  |  |  |         if stripe_data.get('response_object'): | 
					
						
							|  |  |  |             stripe_cus_id = stripe_data.get('response_object').get('id') | 
					
						
							|  |  |  |             return stripe_cus_id | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 01:16:03 -05:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def get_or_create(cls, email=None, token=None): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |             Check if there is a registered stripe customer with that email | 
					
						
							|  |  |  |             or create a new one | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         try: | 
					
						
							| 
									
										
										
										
											2016-05-01 14:13:12 +02:00
										 |  |  |             stripe_utils = StripeUtils() | 
					
						
							| 
									
										
										
										
											2016-04-26 01:16:03 -05:00
										 |  |  |             stripe_customer = cls.objects.get(user__email=email) | 
					
						
							| 
									
										
										
										
											2016-05-02 02:00:38 +02:00
										 |  |  |             # check if user is not in stripe but in database | 
					
						
							| 
									
										
										
										
											2016-12-19 09:33:15 -05:00
										 |  |  |             customer = stripe_utils.check_customer(stripe_customer.stripe_id, | 
					
						
							|  |  |  |                                                    stripe_customer.user, token) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if not customer.sources.data: | 
					
						
							|  |  |  |                 stripe_utils.update_customer_token(customer, token) | 
					
						
							| 
									
										
										
										
											2016-04-26 01:16:03 -05:00
										 |  |  |             return stripe_customer | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         except StripeCustomer.DoesNotExist: | 
					
						
							|  |  |  |             user = CustomUser.objects.get(email=email) | 
					
						
							|  |  |  |             stripe_utils = StripeUtils() | 
					
						
							| 
									
										
										
										
											2017-08-15 16:05:52 +05:30
										 |  |  |             stripe_data = stripe_utils.create_customer(token, email, user.name) | 
					
						
							| 
									
										
										
										
											2016-05-21 00:03:17 +02:00
										 |  |  |             if stripe_data.get('response_object'): | 
					
						
							|  |  |  |                 stripe_cus_id = stripe_data.get('response_object').get('id') | 
					
						
							| 
									
										
										
										
											2016-04-26 01:16:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-29 19:23:25 +03:00
										 |  |  |                 stripe_customer = StripeCustomer.objects. \ | 
					
						
							| 
									
										
										
										
											2016-05-21 00:03:17 +02:00
										 |  |  |                     create(user=user, stripe_id=stripe_cus_id) | 
					
						
							| 
									
										
										
										
											2016-04-26 01:16:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-21 00:03:17 +02:00
										 |  |  |                 return stripe_customer | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 return None | 
					
						
							| 
									
										
										
										
											2016-04-26 01:16:03 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 19:42:45 +01:00
										 |  |  | class CreditCards(models.Model): | 
					
						
							|  |  |  |     name = models.CharField(max_length=50) | 
					
						
							|  |  |  |     user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE) | 
					
						
							|  |  |  |     card_number = models.CharField(max_length=50) | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  |     expiry_date = models.CharField(max_length=50, validators=[ | 
					
						
							|  |  |  |         RegexValidator(r'\d{2}\/\d{4}', _( | 
					
						
							|  |  |  |             'Use this pattern(MM/YYYY).'))]) | 
					
						
							|  |  |  |     ccv = models.CharField(max_length=4, validators=[ | 
					
						
							|  |  |  |         RegexValidator(r'\d{3,4}', _('Wrong CCV number.'))]) | 
					
						
							| 
									
										
										
										
											2016-04-23 19:00:20 +02:00
										 |  |  |     payment_type = models.CharField(max_length=5, default='N') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-01 14:13:12 +02:00
										 |  |  |     def save(self, *args, **kwargs): | 
					
						
							|  |  |  |         # override saving to database | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-23 19:00:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class Calendar(models.Model): | 
					
						
							|  |  |  |     datebooked = models.DateField() | 
					
						
							|  |  |  |     user = models.ForeignKey(CustomUser) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, *args, **kwargs): | 
					
						
							|  |  |  |         if kwargs.get('datebooked'): | 
					
						
							|  |  |  |             user = kwargs.get('user') | 
					
						
							| 
									
										
										
										
											2017-09-03 18:17:25 +02:00
										 |  |  |             kwargs['datebooked'] = datetime.strptime( | 
					
						
							|  |  |  |                 kwargs.get('datebooked', ''), '%d,%m,%Y') | 
					
						
							| 
									
										
										
										
											2016-04-23 19:00:20 +02:00
										 |  |  |             self.user_id = user.id | 
					
						
							|  |  |  |         super(Calendar, self).__init__(*args, **kwargs) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							| 
									
										
										
										
											2016-05-01 14:13:12 +02:00
										 |  |  |     def add_dates(cls, dates, user): | 
					
						
							| 
									
										
										
										
											2016-04-23 19:00:20 +02:00
										 |  |  |         old_dates = Calendar.objects.filter(user_id=user.id) | 
					
						
							|  |  |  |         if old_dates: | 
					
						
							|  |  |  |             old_dates.delete() | 
					
						
							|  |  |  |         for date in dates: | 
					
						
							| 
									
										
										
										
											2016-05-01 14:13:12 +02:00
										 |  |  |             Calendar.objects.create(datebooked=date, user=user) |