add user model fields
This commit is contained in:
parent
8cabfeb1ba
commit
ec152afe55
|
@ -4,16 +4,31 @@ import time, datetime
|
|||
|
||||
from django.db import models
|
||||
|
||||
from pairent_app.models import Apartament
|
||||
from pairent_app.models import Apartament, User
|
||||
|
||||
factory.Faker.override_default_locale('ru_RU');
|
||||
|
||||
class OpenID_Address(factory.declarations.BaseDeclaration):
|
||||
def evaluate(self, instance, step, extra):
|
||||
return ''.join(random.choices(list('abcdef12345678990'), k=6)) + "@vvsu.ru";
|
||||
|
||||
class PhoneNumber(factory.declarations.BaseDeclaration):
|
||||
def evaluate(self, instance, step, extra):
|
||||
return '+799' + str(random.randint(0, 99999999)).zfill(8);
|
||||
|
||||
class CSV(factory.declarations.BaseDeclaration):
|
||||
def __init__(self, min, max, count_min, count_max):
|
||||
self.min = min; self.max = max;
|
||||
self.count_min = count_min; self.count_max: count_max;
|
||||
|
||||
def evaluate(self, instance, step, extra):
|
||||
len_ = random.randint(self.count_min, self.count_max);
|
||||
out = [];
|
||||
for i in range(len): out.append(random.randint(self.min, self.max));
|
||||
return ','.join(out);
|
||||
|
||||
class Random(factory.declarations.BaseDeclaration):
|
||||
def __init__(self, min, max = None, multiply = 1):
|
||||
def __init__(self, min, max = None, multiply = 1, list = None):
|
||||
if (max == None):
|
||||
self.min = 0;
|
||||
self.max = min;
|
||||
|
@ -21,17 +36,26 @@ class Random(factory.declarations.BaseDeclaration):
|
|||
self.min = min;
|
||||
self.max = max;
|
||||
self.multiply = multiply;
|
||||
super().__init__();
|
||||
self.list = list;
|
||||
super().__init__(self);
|
||||
|
||||
def evaluate(self, instance, step, extra):
|
||||
if (type(self.list) == list):
|
||||
return random.choice(self.list);
|
||||
|
||||
if (self.multiply != None):
|
||||
return random.randint(self.min, self.max) * self.multiply;
|
||||
return random.randint(self.min, self.max);
|
||||
|
||||
class Date(factory.declarations.BaseDeclaration):
|
||||
|
||||
def __init__(self, min_year = 2022, max_year = datetime.date().year):
|
||||
self.min_year = min_year;
|
||||
self.max_year = max_year;
|
||||
super().__init__(self);
|
||||
|
||||
def evaluate(self, instance, step, extra):
|
||||
# year_before = time.time() - (60 * 60 * 24 * 30 * 12);
|
||||
return datetime.datetime(2023, random.randint(1,12), random.randint(1,27)).strftime("%G-%m-%d");
|
||||
return datetime.datetime(random.randint(self.min_year, self.max_year), random.randint(1,12), random.randint(1,27)).strftime("%G-%m-%d");
|
||||
|
||||
class ApartmentFactory(factory.django.DjangoModelFactory):
|
||||
|
||||
|
@ -81,4 +105,25 @@ class ApartmentFactory(factory.django.DjangoModelFactory):
|
|||
|
||||
# views = [] # factory.Faker('random_number')
|
||||
|
||||
dateCreate = Date()
|
||||
dateCreate = Date()
|
||||
|
||||
class UserFactory(factory.django.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = User
|
||||
|
||||
favorites_aparments = CSV(1, 100, 1, 16);
|
||||
comparison_apartments = CSV(1, 100, 1, 5);
|
||||
psych_test_result = Random(20, 90);
|
||||
vvsu_id = OpenID_Address();
|
||||
name = factory.faker.Faker('name');
|
||||
date_of_birth = Date(1980, 2006);
|
||||
about_me = factory.faker.Faker('sentence');
|
||||
gender = Random(0,0,0, ['f', 'm', 'n', '?'])
|
||||
|
||||
phone = PhoneNumber()
|
||||
email = OpenID_Address()
|
||||
telegram = '@uwu'
|
||||
discord = '@uwu' # они поменяли формат
|
||||
|
||||
city = Random(0,0,0, ['Владивосток', 'Хабаровск', 'Урюпинск', 'Мухосранск', 'Нью-Йорк'])
|
||||
role = 's'
|
|
@ -1,8 +1,10 @@
|
|||
# Generated by Django 4.2.1 on 2023-05-12 12:45
|
||||
|
||||
import django.core.validators
|
||||
from django.core.validators import RegexValidator, MaxValueValidator
|
||||
from django.db import migrations, models
|
||||
|
||||
from pairent_app.models import User
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
|
@ -11,17 +13,24 @@ class Migration(migrations.Migration):
|
|||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel('User'),
|
||||
migrations.CreateModel(
|
||||
name='User',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('favorites_apartaments', models.CharField(max_length=100, verbose_name='Избранные квартиры')),
|
||||
('apartaments_for_comparison', models.CharField(max_length=100, verbose_name='Квартиры для сравнения')),
|
||||
('psych_test_result', models.IntegerField(null=True, validators=[django.core.validators.MaxValueValidator(100)], verbose_name='Результат психологического теста')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Пользователь',
|
||||
'verbose_name_plural': 'Пользователи',
|
||||
},
|
||||
),
|
||||
('favorites_apartments', models.CharField(max_length=100, help_text="Избранные квартиры (CSV)")),
|
||||
('comparison_apartments', models.CharField(max_length=100, help_text="Квартиры для сравнения (CSV)")),
|
||||
('psych_test_result', models.IntegerField(validators=[MaxValueValidator(100)], null=True, help_text="Результат психологического теста")),
|
||||
('openid_addr', models.CharField(max_length=1000, null=False, help_text='Адрес Open ID Connect (login@provider.com, для ВВГУ - login@vvsu.ru)')),
|
||||
('name', models.CharField(max_length=256, help_text='ФИО Пользователя')),
|
||||
('date_of_birth', models.DateField(help_text='Дата рождения пользователя')),
|
||||
('about_me', models.CharField(max_length=1000, help_text='Поле "О Себе"')),
|
||||
('gender', models.CharField(max_length=1, help_text='Пол пользователя (f,m,n,?)')),
|
||||
('phone', models.CharField(max_length=30, help_text='Телефон пользователя в международном формате (+00000000)', null=True)),
|
||||
('email', models.CharField(max_length=1000, help_text='Почтовый ящик пользователя в формате user@example.com', null=True)),
|
||||
('telegram', models.CharField(max_length=1000, help_text='Телеграм пользователя', null=True)),
|
||||
('discord', models.CharField(max_length=1000, help_text='Дискорд ник пользователя', null=True)),
|
||||
('city', models.CharField(max_length=1000, help_text='Город пользователя', null=True)),
|
||||
('role', models.CharField(max_length=1, help_text='Роль пользователя (s - student, a - admin, m - moderator)', null=False))
|
||||
]
|
||||
)
|
||||
]
|
||||
|
|
|
@ -81,10 +81,26 @@ class Photo(models.Model):
|
|||
|
||||
# TODO: Add auth
|
||||
class User(models.Model):
|
||||
"""Тестовая модель данных для избранных и сравнения"""
|
||||
favorites_apartaments = models.CharField(max_length=100, verbose_name="Избранные квартиры")
|
||||
apartaments_for_comparison = models.CharField(max_length=100, verbose_name="Квартиры для сравнения")
|
||||
psych_test_result = models.IntegerField(validators=[MaxValueValidator(100)], null=True, verbose_name="Результат психологического теста")
|
||||
"""Модель данных пользователя"""
|
||||
|
||||
favorites_apartments = models.CharField(max_length=100, verbose_name="Избранные квартиры (CSV)")
|
||||
comparison_apartments = models.CharField(max_length=100, verbose_name="Квартиры для сравнения (CSV)")
|
||||
psych_test_result = models.IntegerField(validators=[MaxValueValidator(100)], null=True, verbose_name="Результат психологического теста")
|
||||
openid_addr = models.CharField(max_length=1000, null=False, verbose_name='Адрес Open ID Connect (login@provider.com, для ВВГУ - login@vvsu.ru)')
|
||||
name = models.CharField(max_length=256, verbose_name='ФИО Пользователя')
|
||||
date_of_birth = models.DateField(verbose_name='Дата рождения пользователя')
|
||||
about_me = models.CharField(max_length=1000, verbose_name='Поле "О Себе"')
|
||||
gender = models.CharField(max_length=1, verbose_name='Пол пользователя (f,m,n,?)')
|
||||
|
||||
phone = models.CharField(max_length=30, verbose_name='Телефон пользователя в международном формате (+00000000)', null=True)
|
||||
email = models.CharField(max_length=1000, verbose_name='Почтовый ящик пользователя в формате user@example.com', null=True)
|
||||
telegram = models.CharField(max_length=1000, verbose_name='Телеграм пользователя', null=True)
|
||||
discord = models.CharField(max_length=1000, verbose_name='Дискорд ник пользователя', null=True)
|
||||
|
||||
# as in "City wok"
|
||||
city = models.CharField(max_length=1000, verbose_name='Город пользователя', null=True)
|
||||
|
||||
role = models.CharField(max_length=1, verbose_name='Роль пользователя (s - student, a - admin, m - moderator)', null=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Пользователь"
|
||||
|
|
|
@ -21,4 +21,9 @@ class ApartamentDetailSerializer(serializers.ModelSerializer):
|
|||
class PsychTestAddResultSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ("psych_test_result",)
|
||||
fields = ("psych_test_result",)
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = "__all__"
|
|
@ -9,5 +9,6 @@ urlpatterns = format_suffix_patterns([
|
|||
path("apartaments/comparison/", views.ApartamentGetManyViewSet.as_view({'get': 'retrieve'})), # пример: apartaments/comparison/?user_id=1 user_id - id пользователя
|
||||
path("apartaments/favorite/", views.ApartamentGetManyViewSet.as_view({'get': 'list'})), # пример: apartaments/favorite/?user_id=1 user_id - id пользователя
|
||||
path("apartaments/filters/", views.ApartmentFilter.as_view({'post': 'list'})),
|
||||
path("psych_test/add_result/<int:pk>", views.PsychTestAddResultViewSet.as_view({'patch': 'update'})) # пример: psych_test/add_result/1/?result=50 result - результат псих теста пользователя
|
||||
path("psych_test/add_result/<int:pk>", views.PsychTestAddResultViewSet.as_view({'patch': 'update'})), # пример: psych_test/add_result/1/?result=50 result - результат псих теста пользователя
|
||||
path("users/get_compatible", views.CompatibleUsersView.as_view({'post': 'list'}))
|
||||
])
|
||||
|
|
|
@ -8,7 +8,8 @@ from django.http import HttpResponseBadRequest
|
|||
from .models import Apartament, User
|
||||
from .serializer import (ApartamentListSerializer,
|
||||
ApartamentDetailSerializer,
|
||||
PsychTestAddResultSerializer)
|
||||
PsychTestAddResultSerializer,
|
||||
UserSerializer)
|
||||
|
||||
import json
|
||||
|
||||
|
@ -91,4 +92,9 @@ class PsychTestAddResultViewSet(viewsets.ViewSet):
|
|||
result = request.query_params.get("result", None)
|
||||
user.update(psych_test_result=result)
|
||||
return Response(PsychTestAddResultSerializer(User.objects.get(pk=pk)).data)
|
||||
|
||||
|
||||
class CompatibleUsersView(viewsets.ViewSet):
|
||||
def list(self, req: Request):
|
||||
user_data = dict(req.data);
|
||||
users = User.objects.all();
|
||||
return Response(UserSerializer(users).data);
|
Loading…
Reference in New Issue