class Account(AbstractBaseUser): id_user = models.IntegerField(primary_key=True, unique=True) user_name = models.CharField(max_length=25, blank=False, null=False, unique=True) user_first_name = models.CharField(max_length=25, blank=False, null=False) user_last_name = models.CharField(max_length=25, blank=False, null=False) user_role = models.IntegerField() user_image = models.ImageField(upload_to='images/', height_field=None, width_field=None, max_length=None) email = models.EmailField(max_length=254, blank=False, null=False, unique=True) birthday = models.DateTimeField(auto_now=False, auto_now_add=False) address = models.CharField(max_length=50, blank=False, null=False) phone = PhoneNumber(txt=None) cellphone = PhoneNumber(txt=None) project = models.CharField(max_length=50, blank=True, null=True) team = models.CharField(max_length=50, blank=True, null=True) hours_worked = models.IntegerField(blank=True, null=True) salary_per_hour = models.IntegerField(blank=True, null=True) is_admin = models.BooleanField(default=False) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) objects = HelpDesk_AccountManager() USERNAME_FIELD = 'user_name' REQUIRED_FIELDS = [ 'user_first_name', 'user_last_name', 'email', 'birthday', 'address', 'user_role' ] def __str__(self): return "User name: " + self.user_name + "; Name: " + self.user_first_name + " " + self.user_last_name + " " + str( self.user_image) def has_perm(self, perm, obj=None): return self.is_admin def has_module_perms(self, app_label): return self.is_admin # class User(models.Model): # user_first_name = models.CharField(max_length=25, blank=False, null=False) # user_last_name = models.CharField(max_length=25, blank=False, null=False) # birth_day = models.DateTimeField(auto_now=False, auto_now_add=False) # address = models.CharField(max_length=50, blank=False, null=False) # phone = models.CharField(max_length=13, blank=False, null=False) # cellphone =models.CharField(max_length=13, blank=True, null=True) # project = models.CharField(max_length=50, blank=True,null=True) # team = models.CharField(max_length=50, blank=True,null=True) # task = models.CharField(max_length=100) # hours_worked = models.IntegerField(blank=False, null=False) # salary_per_hour = models.IntegerField(blank=False, null=False)
def test_form_rendering(self): f = TestFormOptional( initial={'phone': PhoneNumber('415.123.4567 x 12')}) self.assertEqual( str(f), _rendered_field_html(phone_number='(415) 123-4567', extension='12', required=False))
def test_raw_filter_native(self): t = Template(r'{% load phone %}{{ ph|raw_phone }}') out = t.render(Context({'ph': PhoneNumber('415-123-4567')})) self.assertEqual(out, '+14151234567')
def test_native(self): t = Template(r'{{ ph }}') out = t.render(Context({'ph': PhoneNumber('4151234567')})) self.assertEqual(out, '(415) 123-4567')
def test_parsing(self): for input_str, label, attrs in PARSING_TESTS: ph = PhoneNumber(input_str) for key, val in attrs.items(): self.assertEqual(getattr(ph, key), val, msg=label)
def test_form_rendering(self): f = TestFormOptional(initial={'phone': PhoneNumber('415.123.4567 x 12')}) expected = '<tr><th><label for="id_phone_0">Phone:</label></th><td><input type="text" name="phone_0" ' \ 'value="(415) 123-4567" size="13" id="id_phone_0" />\n\n ext. ' \ '<input type="text" name="phone_1" value="12" size="4" id="id_phone_1" /></td></tr>' self.assertEqual(str(f), expected)