Skip to content

Commit

Permalink
models_user.py cleaned and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
DEKHTIARJonathan committed Aug 2, 2018
1 parent 491a381 commit d052390
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions feedcrunch/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class UserFactory(factory.DjangoModelFactory):
class Meta:
model = FeedUser
django_get_or_create = ('username',)

username="testuser1"
email="marco.flint31@gmail.com"
Expand Down
20 changes: 10 additions & 10 deletions feedcrunch/model_files/models_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
######### https://github.com/django/django/blob/master/django/contrib/auth/models.py

import os, re, uuid, datetime, unicodedata, getenv, random, urllib, string
import re, uuid, datetime, unicodedata, random, urllib, string
from xml.sax.saxutils import escape as escape_xml

from django.conf import settings
from django.contrib.auth.models import User, UserManager, PermissionsMixin, AbstractUser
from django.contrib.auth.models import UserManager, PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
from django.db import models
from django.utils import six, timezone
from django.utils.encoding import force_text
Expand All @@ -18,16 +19,16 @@
from pyisemail import is_email
from encrypted_model_fields .fields import EncryptedCharField

from feedcrunch.models import Continent, Country, Estimator, Interest
from feedcrunch.models import Country, Estimator, Interest

from oauth.twitterAPI import TwitterAPI
from oauth.facebookAPI import FacebookAPI
from oauth.linkedinAPI import LinkedInAPI
from oauth.slackAPI import SlackAPI

from validators import ASCIIUsernameValidator, UnicodeUsernameValidator
from functions.validators import ASCIIUsernameValidator, UnicodeUsernameValidator

from datetime import timedelta, date, datetime
from datetime import timedelta, datetime

def generateDummyDesc():
return "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam dui nisl, aliquam nec quam nec, laoreet porta odio. Morbi ultrices sagittis ligula ut consectetur. Aenean quis facilisis augue. Vestibulum maximus aliquam augue, ut lobortis turpis euismod vel. Sed in mollis tellus, eget eleifend turpis. Vivamus aliquam ornare felis at dignissim. Integer vitae cursus eros, non dignissim dui. Suspendisse porttitor justo nec lacus dictum commodo. Sed in fringilla tortor, at pharetra tortor."
Expand Down Expand Up @@ -59,12 +60,12 @@ def _validate_username(self, username):
if not re.match("^[A-Za-z0-9]*$", username):
raise ValueError("The given username is not a valid string, it should only contains letters (A-Z and a-z) and numbers (0-9)")

if FeedUser.objects.filter(username = username).exists():
raise ValueError("The given username ( "+ username +" ) is already taken")
if FeedUser.objects.filter(username=username).exists():
raise ValueError("The given username `%s` is already taken" % username)

def _validate_email(self, email):
if not is_email(email, check_dns=True):
raise ValueError("The given email is not valid or not doesn''t exist.")
raise ValueError("The given email `%s` is not valid or not does not exist." % email)

def _validate_password(self, password):
if re.match("(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{8,}", password) == None:
Expand Down Expand Up @@ -184,7 +185,6 @@ def create_user(self, username, email, password, **extra_fields):

return self._create_user(username, email, password, **extra_fields)


def create_superuser(self, username, email, password, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
Expand Down

0 comments on commit d052390

Please sign in to comment.