Add random profiles

This commit is contained in:
Andros Fenollosa 2021-11-11 22:46:49 +01:00
parent b57103eabd
commit fe3caee6f9
8 changed files with 135 additions and 16 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
media/
static/

View File

@ -25,4 +25,3 @@ RUN pip3 install -r requirements.txt
# launcher # launcher
COPY django-launcher.sh /django-launcher.sh COPY django-launcher.sh /django-launcher.sh
RUN chmod +x /django-launcher.sh RUN chmod +x /django-launcher.sh

29
Makefile Normal file
View File

@ -0,0 +1,29 @@
.DEFAULT_GOAL := help
help:
@perl -nle'print $& if m{^[a-zA-Z_-|.]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
run.format: ## Format style with black
docker-compose -f docker-compose.dev.yaml exec -T django bash -c "black --exclude='/(postgres|venv|migrations|node_modules|\.git)/' ."
docker.bash: ## Enter bash terminal
docker exec -it formacion-htmx_django_1 bash
docker.recreate.django: ## Recreate Django image
docker-compose down
docker-compose build --no-cache django
run.loaddata: ## Minimal load data
# Remove database
docker-compose -f docker-compose.dev.yaml exec -T django bash -c "python3 manage.py flush --noinput"
# Remove media
sudo rm -rf media
# Migrate
docker-compose -f docker-compose.dev.yaml exec -T django bash -c "python3 manage.py migrate"
# Add provinces, towns and categories
docker-compose -f docker-compose.dev.yaml exec -T db bash -c "psql -h localhost -d kualitte -U postgres -p 5432 -a -q -f /usr/src/app/scripts/provincias.sql"
run.server: # Run server
docker-compose -f docker-compose.dev.yaml up

View File

@ -0,0 +1,60 @@
# Generated by Django 3.2.7 on 2021-11-11 20:29
from django.db import migrations, models
import django.db.models.deletion
import tinymce.models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, verbose_name='Nombre')),
],
options={
'verbose_name': 'Categoria',
'verbose_name_plural': 'Categorias',
'ordering': ('name',),
},
),
migrations.CreateModel(
name='Profile',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('email', models.EmailField(max_length=254, unique=True, verbose_name='Email')),
('full_name', models.CharField(default='', max_length=100, verbose_name='Full name')),
('avatar', models.ImageField(upload_to='uploads/avatars/', verbose_name='Avatar')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Talk',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100, verbose_name='Título')),
('image', models.ImageField(upload_to='uploads/talks/', verbose_name='Imagen')),
('is_draft', models.BooleanField(default=True, verbose_name='¿Es un borrador?')),
('content', tinymce.models.HTMLField(verbose_name='Contenido')),
('created_at', models.DateTimeField(auto_now=True, verbose_name='Creado')),
('author', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='author', to='website.profile', verbose_name='Autor')),
('category', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='Categoría', to='website.category', verbose_name='Categoría')),
],
options={
'verbose_name': 'Charla',
'verbose_name_plural': 'Charlas',
'ordering': ('-created_at',),
},
),
]

View File

@ -1,4 +1,6 @@
from django.db import models from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from tinymce import models as tinymce_models
class Profile(AbstractBaseUser): class Profile(AbstractBaseUser):
@ -7,7 +9,7 @@ class Profile(AbstractBaseUser):
email = models.EmailField("Email", unique=True) email = models.EmailField("Email", unique=True)
full_name = models.CharField( full_name = models.CharField(
max_length=100, verbose_name="Nombre y apellidos", default="Sapps" max_length=100, verbose_name="Full name", default=""
) )
avatar = models.ImageField(verbose_name="Avatar", upload_to="uploads/avatars/") avatar = models.ImageField(verbose_name="Avatar", upload_to="uploads/avatars/")
@ -51,7 +53,7 @@ class Talk(models.Model):
related_name="author", related_name="author",
verbose_name="Autor", verbose_name="Autor",
) )
image = models.ImageField(verbose_name="Imagen", upload_to="uploads/articles/") image = models.ImageField(verbose_name="Imagen", upload_to="uploads/talks/")
is_draft = models.BooleanField(default=True, verbose_name="¿Es un borrador?") is_draft = models.BooleanField(default=True, verbose_name="¿Es un borrador?")
content = tinymce_models.HTMLField(verbose_name="Contenido") content = tinymce_models.HTMLField(verbose_name="Contenido")
created_at = models.DateTimeField(auto_now=True, verbose_name="Creado") created_at = models.DateTimeField(auto_now=True, verbose_name="Creado")

View File

@ -1,9 +1,8 @@
version: '3.1'
services: services:
postgresql: db:
image: postgres image: postgres:14-alpine
restart: "no" restart: "no"
environment: environment:
POSTGRES_USER: postgres POSTGRES_USER: postgres
@ -22,13 +21,13 @@ services:
- .:/usr/src/app/ - .:/usr/src/app/
environment: environment:
DEBUG: "True" DEBUG: "True"
ALLOWED_HOSTS: "event.localhost" ALLOWED_HOSTS: "event.localhost,localhost"
SECRET_KEY: "my-secret" SECRET_KEY: "my-secret"
DB_ENGINE: "django.db.backends.postgresql" DB_ENGINE: "django.db.backends.postgresql"
DB_NAME: "event" DB_NAME: "event"
DB_USER: "postgres" DB_USER: "postgres"
DB_PASSWORD: "postgres" DB_PASSWORD: "postgres"
DB_HOST: "postgresql" DB_HOST: db
DB_PORT: "5432" DB_PORT: "5432"
DOMAIN: "event.localhost" DOMAIN: "event.localhost"
DOMAIN_URL: "http://event.localhost" DOMAIN_URL: "http://event.localhost"
@ -42,12 +41,12 @@ services:
EMAIL_PORT: "1025" EMAIL_PORT: "1025"
EMAIL_USER: "" EMAIL_USER: ""
EMAIL_PASSWORD: "" EMAIL_PASSWORD: ""
expose: ports:
- 8000 - 8000:8000
depends_on: depends_on:
- postgresql - db
caddy: web:
image: caddy:alpine image: caddy:alpine
restart: unless-stopped restart: unless-stopped
ports: ports:

View File

@ -1,5 +1,5 @@
# Django # Django
django===3.2.10 django===3.2.9
django-extensions===3.1.3 django-extensions===3.1.3
# PostgreSQL driver # PostgreSQL driver
psycopg2===2.9.1 psycopg2===2.9.1
@ -15,15 +15,16 @@ channels_redis===3.2.0
djangorestframework djangorestframework
markdown markdown
django-filter django-filter
# HTTP client
Requests===2.26.0
# Template # Template
## Componentes - https://mitchel.me/slippers/ ## Componentes - https://mitchel.me/slippers/
slippers slippers
# WYSIWYG editor Python Django admin # WYSIWYG editor Python Django admin
django-tinymce===3.3.0 django-tinymce===3.3.0
# Testing
pytest-django
pytest
# Pillow # Pillow
Pillow===8.2.0 Pillow===8.2.0
# Linter # Linter
black black
# Fake data
Faker===8.13.2

View File

@ -0,0 +1,27 @@
from app.website.models import Profile
from faker import Faker
# Get random imagen from url
from django.core.files import File
import requests
import time
from tempfile import NamedTemporaryFile
from random import randint
def run():
fake = Faker()
# 30 Profiles random
for email in [fake.unique.email() for i in range(30)]:
my_profile = Profile()
my_profile.email = email
my_profile.full_name = f"{fake.first_name()} {fake.last_name()}"
my_profile.set_password("password")
my_profile.save()
# Add a profile picture
url_random_imagen = f"https://cdn.jsdelivr.net/gh/tanrax/place-image-random/images/{randint(1, 1000)}.jpg"
r = requests.get(url_random_imagen)
img_temp = NamedTemporaryFile(delete=True)
img_temp.write(r.content)
img_temp.flush()
my_profile.avatar.save(f"random_{int(time.time() * 1000)}.jpg", File(img_temp))