Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
style: lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
adrrf committed Apr 1, 2024
1 parent d4a9d5a commit 5fe5fc6
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 84 deletions.
94 changes: 74 additions & 20 deletions event/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,89 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('user', '0001_initial'),
("user", "0001_initial"),
]

operations = [
migrations.CreateModel(
name='Event',
name="Event",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('place', models.TextField()),
('description', models.TextField()),
('date', models.DateField()),
('hour', models.TimeField()),
('capacity', models.PositiveIntegerField(default=0)),
('category', models.TextField(choices=[('Sports', 'SPORTS'), ('Music', 'MUSIC'), ('Markets', 'MARKETS'), ('Relax activities', 'RELAX_ACTIVITIES'), ('Live concert', 'LIVE_CONCERT')], default='Sports')),
('latitude', models.FloatField()),
('longitude', models.FloatField()),
('image', models.ImageField(blank=True, null=True, upload_to='images/')),
('blurhash', models.TextField(blank=True, null=True)),
('ocialClient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='OcialClient', to='user.ocialclient')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.TextField()),
("place", models.TextField()),
("description", models.TextField()),
("date", models.DateField()),
("hour", models.TimeField()),
("capacity", models.PositiveIntegerField(default=0)),
(
"category",
models.TextField(
choices=[
("Sports", "SPORTS"),
("Music", "MUSIC"),
("Markets", "MARKETS"),
("Relax activities", "RELAX_ACTIVITIES"),
("Live concert", "LIVE_CONCERT"),
],
default="Sports",
),
),
("latitude", models.FloatField()),
("longitude", models.FloatField()),
(
"image",
models.ImageField(blank=True, null=True, upload_to="images/"),
),
("blurhash", models.TextField(blank=True, null=True)),
(
"ocialClient",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="OcialClient",
to="user.ocialclient",
),
),
],
),
migrations.CreateModel(
name='Rating',
name="Rating",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('score', models.PositiveIntegerField(default=0, validators=[django.core.validators.MaxValueValidator(5), django.core.validators.MinValueValidator(0)])),
('comment', models.TextField(blank=True, null=True)),
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='Rating', to='event.event')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"score",
models.PositiveIntegerField(
default=0,
validators=[
django.core.validators.MaxValueValidator(5),
django.core.validators.MinValueValidator(0),
],
),
),
("comment", models.TextField(blank=True, null=True)),
(
"event",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="Rating",
to="event.event",
),
),
],
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
class Migration(migrations.Migration):

dependencies = [
('event', '0001_initial'),
("event", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name='event',
name='blurhash',
model_name="event",
name="blurhash",
),
migrations.RemoveField(
model_name='event',
name='image',
model_name="event",
name="image",
),
]
16 changes: 11 additions & 5 deletions event/migrations/0003_event_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
class Migration(migrations.Migration):

dependencies = [
('images', '0001_initial'),
('event', '0002_remove_event_blurhash_remove_event_image'),
("images", "0001_initial"),
("event", "0002_remove_event_blurhash_remove_event_image"),
]

operations = [
migrations.AddField(
model_name='event',
name='image',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='EventImage', to='images.image'),
model_name="event",
name="image",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="EventImage",
to="images.image",
),
),
]
9 changes: 7 additions & 2 deletions event/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ class Event(models.Model):
ocialClient = models.ForeignKey(
OcialClient, related_name="OcialClient", on_delete=models.CASCADE
)
image = models.ForeignKey(Image, related_name="EventImage", on_delete=models.CASCADE, null=True, blank=True)

image = models.ForeignKey(
Image,
related_name="EventImage",
on_delete=models.CASCADE,
null=True,
blank=True,
)

def __str__(self):
return "{}: {} | {}, {}".format(
Expand Down
2 changes: 2 additions & 0 deletions event/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .models import Event, Rating, OcialClient
from images.serializers import ImageSerializer


class RatingSerializer(serializers.ModelSerializer):
class Meta:
model = Rating
Expand All @@ -25,6 +26,7 @@ class EventSerializer(serializers.ModelSerializer):
ocialClient = OcialClientSerializer()
imageB64 = serializers.CharField(write_only=True, required=False)
image = ImageSerializer(read_only=True)

class Meta:
model = Event
fields = "__all__"
Expand Down
31 changes: 20 additions & 11 deletions event/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from drf_spectacular.openapi import OpenApiResponse
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.parsers import MultiPartParser, FormParser, FileUploadParser
from .serializers import *
from django.db.models.functions import ACos, Cos, Radians, Sin
from django.db.models import F
Expand Down Expand Up @@ -126,18 +125,23 @@ def post(self, request, *args, **kwargs):
if eventform.is_valid():
eventform.save()
if image:
format, imgstr = data.get("image").split(';base64,')
ext = format.split('/')[-1]
valid_ext = ['jpg', 'jpeg', 'png']
format, imgstr = data.get("image").split(";base64,")
ext = format.split("/")[-1]
valid_ext = ["jpg", "jpeg", "png"]
if ext not in valid_ext:
return Response(
{"error": "Formato de imagen no válido"},
status=status.HTTP_422_UNPROCESSABLE_ENTITY,
)
imagefile = ContentFile(base64.b64decode(imgstr), name=f'event-{eventform.instance.id}.{ext}')
imagefile = ContentFile(
base64.b64decode(imgstr),
name=f"event-{eventform.instance.id}.{ext}",
)
image = ImageModel.objects.create(
image=imagefile,
blurhash=blurhash.encode(Image.open(imagefile), x_components=4, y_components=3)
blurhash=blurhash.encode(
Image.open(imagefile), x_components=4, y_components=3
),
)
eventform.instance.image = image
eventform.instance.save()
Expand Down Expand Up @@ -250,18 +254,23 @@ def put(self, request, *args, **kwargs):
eventUpdate.longitude = data.get("longitude")
eventUpdate.save()
if image:
format, imgstr = data.get("image").split(';base64,')
ext = format.split('/')[-1]
valid_ext = ['jpg', 'jpeg', 'png']
format, imgstr = data.get("image").split(";base64,")
ext = format.split("/")[-1]
valid_ext = ["jpg", "jpeg", "png"]
if ext not in valid_ext:
return Response(
{"error": "Formato de imagen no válido"},
status=status.HTTP_422_UNPROCESSABLE_ENTITY,
)
imagefile = ContentFile(base64.b64decode(imgstr), name=f'event-{eventUpdate.instance.id}.{ext}')
imagefile = ContentFile(
base64.b64decode(imgstr),
name=f"event-{eventUpdate.instance.id}.{ext}",
)
image = ImageModel.objects.create(
image=imagefile,
blurhash=blurhash.encode(Image.open(imagefile), x_components=4, y_components=3)
blurhash=blurhash.encode(
Image.open(imagefile), x_components=4, y_components=3
),
)
eventUpdate.instance.image = image
eventUpdate.instance.save()
Expand Down
4 changes: 2 additions & 2 deletions images/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class ImagesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'images'
default_auto_field = "django.db.models.BigAutoField"
name = "images"
11 changes: 5 additions & 6 deletions images/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='Image',
name="Image",
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('image', models.ImageField(upload_to='media/')),
('blurhash', models.TextField()),
("id", models.AutoField(primary_key=True, serialize=False)),
("image", models.ImageField(upload_to="media/")),
("blurhash", models.TextField()),
],
),
]
2 changes: 1 addition & 1 deletion images/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
class ImageSerializer(serializers.ModelSerializer):
class Meta:
model = Image
fields = "__all__"
fields = "__all__"
1 change: 0 additions & 1 deletion images/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.test import TestCase

# Create your tests here.
1 change: 0 additions & 1 deletion images/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.shortcuts import render

# Create your views here.
1 change: 0 additions & 1 deletion ocial/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ class TypeClient(Enum):
class AuthProvider(Enum):
EMAIL = "email"
GOOGLE = "google"

4 changes: 2 additions & 2 deletions ocial/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"chat",
"drf_spectacular",
"rest_framework.authtoken",
"images"
"images",
]

STATIC_URL = "/static/"
Expand Down Expand Up @@ -161,7 +161,7 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_URL = "/static/"

MEDIA_URL = "/media/"

Expand Down
4 changes: 3 additions & 1 deletion ocial/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@
),
]

urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns = urlpatterns + static(
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
)
Loading

0 comments on commit 5fe5fc6

Please sign in to comment.