Example #1
0
    def setUpData(self):
        self.client = APIClient()
        post_user = User(username='******', password='******', email='*****@*****.**')
        post_user.save()

        Post.objects.create(title='First post', text='Text for first post', user=post_user)
        Post.objects.create(title='Second post', text='Text for second post', user=post_user)
        Post.objects.create(title='Third post', text='Text for third post', user=post_user)

        self.user_registration('user_2')
        self.user_login('user_2')
Example #2
0
def load_data():
    file_path = '/home/quattro/Descargas/MOCK_DATA.json'
    with open(file_path, 'r') as f:
        f_data = f.read()
        datas = json.loads(f_data)
        for data in datas:
            user = User()
            user.first_name = data.get('first_name', '')
            user.last_name = data.get('last_name', '')
            user.email = data.get('email', '')
            user.password = lorem.paragraph()
            user.birthdate = data.get('birthdate', '')
            user.save()
            print(user.pk)
Example #3
0
def register(request):  #회원가입 페이지를 보여주기 위한 함수
    if request.method == "GET":
        return render(request, 'register.html')

    elif request.method == "POST":
        username = request.POST.get('username', None)
        password = request.POST.get('password', None)
        re_password = request.POST.get('re_password', None)
        res_data = {}
        if not (username and password and re_password):
            res_data['error'] = "모든 값을 입력해야 합니다."
        if password != re_password:
            return HttpResponse('비밀번호가 다릅니다.')
            res_data['error'] = '비밀번호가 다릅니다.'
        else:
            user = User(username=username, password=make_password(password))
            user.save()
        return render(request, 'index.html', res_data)
Example #4
0
 def create(self, validated_data):
     username = validated_data['username']
     password = validated_data['password']
     email = validated_data['email']
     user_obj = User(username=username, email=email)
     user_obj.set_password(password)
     user_obj.save()
     return validated_data
Example #5
0
def register():
    """View for register a new user.
    """

    if current_user.is_authenticated:
        return redirect(url_for('habr_app.posts'))

    title = 'Регистрация'
    popular_tags = get_popular_tags()
    register_form = RegisterForm()

    if register_form.validate_on_submit():
        user = User.query.filter_by(
            username=register_form.username.data).first()
        if user:
            flash('Такой пользователь уже есть')
            return redirect(url_for('register'))

        user = User(username=register_form.username.data)
        user.set_password(register_form.password.data)

        db.session.add(user)
        db.session.commit()

        flash('Вы успешно зарегистрировались')
        return redirect(url_for('login'))

    if request.method == 'POST':
        flash('Проверьте требования полей в форме.')

    return render_template(
        'register.html',
        title=title,
        tags=popular_tags,
        form=register_form,
        current_user=current_user,
    )
Example #6
0
 def test_user_object_creation_with_email(self):
     self.user['email'] = '*****@*****.**'
     user = User(**self.user)
     user.save()
     created_user = User.objects.first()
     self.assertEqual(created_user.email, self.user['email'])
Example #7
0
 def test_user_object_creation(self):
     user = User(**self.user)
     user.save()
     created_user = User.objects.first()
     username = f'{created_user.username}'
     self.assertEqual(username, self.user['username'])
Example #8
0
    'last_name': 'Vega',
    'password': '******'
}, {
    'email': '*****@*****.**',
    'first_name': 'Yésica',
    'last_name': 'Cortés',
    'password': '******',
    'birthdate': date(1990, 12, 19)
}, {
    'email':
    '*****@*****.**',
    'first_name':
    'Arturo',
    'last_name':
    'Martínez',
    'password':
    '******',
    'is_admin':
    True,
    'birthdate':
    date(1981, 11, 6),
    'bio':
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
}]

from posts.models import User

for user in users:
    obj = User(**user)
    obj.save()
    print(obj.pk, ':', obj.email)
Example #9
0
    {
        'email': '*****@*****.**',
        'first_name': 'jojo',
        'last_name': 'jeje',
        'password': '******'
    },
    {
        'email': '*****@*****.**',
        'first_name': 'jojo',
        'last_name': 'jeje',
        'password': '******',
        'birthdate': date(1990, 12, 19)
    },
    {
        'email': '*****@*****.**',
        'first_name': 'jojo',
        'last_name': 'jeje',
        'password': '******',
        'birthdate': date(1990, 12, 19),
        'bio': 'Muchas cosas woooo',
        'is_admin': True
    },
]

from posts.models import User

for user in users:
    person = User(**user)
    obj.save()
    # person = User.objects.create(**user)
    print(obj.pk)
def parse_users():
    json_data = get_json(USERS_URL)

    for item in json_data:
        address = Address()
        address.city = item['address']['city']
        address.street = item['address']['street']
        address.suite = item['address']['suite']
        address.zipcode = item['address']['zipcode']
        address.lat = item['address']['geo']['lat']
        address.lng = item['address']['geo']['lng']

        try:
            address.save()
        except IntegrityError:
            address = Address.objects.filter(
                city=item['address']['city'],
                street=item['address']['street'],
                suite=item['address']['suite'],
            ).first()

        company = Company()
        company.name = item['company']['name']
        company.catchphrase = item['company']['catchPhrase']
        company.bs = item['company']['bs']

        try:
            company.save()
        except IntegrityError:
            company = Company.objects.filter(name=item['name']).first()

        try:
            user = User()
            user.name = item['name']
            user.username = item['username']
            user.email = item['email']
            user.phone = item['phone']
            user.website = item['website']
            user.address = address
            user.company = company
            user.save()
        except IntegrityError:
            pass
Example #11
0
from getpass import getpass
import sys

from posts.app import app
from posts.models import User
from posts.models.database import db

with app.app_context():
    username = input('Введите имя пользователя: ')

    if db.session.query(User).filter_by(username=username).count():
        sys.exit('Такой пользователь уже есть')

    password = getpass('Введите пароль: ')
    password2 = getpass('Повторите пароль: ')
    if not password == password2:
        sys.exit('Пароли должны совпадать')

    new_user = User(username=username, is_admin=True)
    new_user.set_password(password)

    db.session.add(new_user)
    db.session.commit()
    print(f'{ new_user } added')
Example #12
0
	},
	{
	'email' :'*****@*****.**',
	'password':'******',
	'first_name':'Fabrizio',
	'last_name':'Vásquez',	
	'bio':'Luis Vásquez señor de 50 años de edad , actualmente vive en Lima La Victoria.',
	'birthday':date(1967,10,2),
	'country':'Huancayo',
	'is_admin':True
	}
	]	


from posts.models import User

for data in personas:
	obj = User(**data)
	obj.save()
	print(obj.first_name,':',obj.email,':',obj.country,":",obj.birthday)


--------------------------------------------------------------------------------------------------------------------->


def __str__(self):
	return self.first_name

for u in user:
	print(u.first_name,':',u.email,':',u.birthday,':',u.country,':',u.password)
    'last_name': 'Vega',
    'password': '******'
}, {
    'email': '*****@*****.**',
    'first_name': 'Yésica',
    'last_name': 'Cortés',
    'password': '******',
    'birthdate': date(1990, 12, 19)
}, {
    'email':
    '*****@*****.**',
    'first_name':
    'Arturo',
    'last_name':
    'Martínez',
    'password':
    '******',
    'is_admin':
    True,
    'birthdate':
    date(1981, 11, 6),
    'bio':
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
}]

from posts.models import User

for user in users:
    new = User(**user)
    new.save()
    print(new.pk, ':', new.email)
Example #14
0
 def create(self, validated_data):
     password = validated_data.pop('password')
     user = User(**validated_data)
     user.set_password(password)
     user.save()
     return user