Skip to content

Commit

Permalink
Merge pull request #12 from Ilhasoft/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dyohan9 authored Jan 14, 2021
2 parents 7d3eccc + 3e28fbc commit 32dc63e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
14 changes: 10 additions & 4 deletions weni/api/v1/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ def upload_photo(self, request, **kwargs): # pragma: no cover
)

return Response({"photo": self.request.user.photo.url})
raise UnsupportedMediaType(
filetype.get_type(f.content_type).extension,
detail=_("Unauthorized file type, upload an image file"),
)
try:
raise UnsupportedMediaType(
filetype.get_type(f.content_type).extension,
detail=_("We accept images only in the formats: .png, .jpeg, .gif"),
)
except Exception:
raise UnsupportedMediaType(
None,
detail=_("We accept images only in the formats: .png, .jpeg, .gif"),
)

@action(
detail=True,
Expand Down
27 changes: 27 additions & 0 deletions weni/common/migrations/0004_auto_20210114_1405.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 2.2.17 on 2021-01-14 14:05

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("common", "0003_auto_20210106_1826"),
]

operations = [
migrations.AlterField(
model_name="servicestatus",
name="service",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="common.Service"
),
),
migrations.AlterUniqueTogether(
name="servicestatus",
unique_together={("service", "user")},
),
]
10 changes: 9 additions & 1 deletion weni/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class ServiceStatus(models.Model):
class Meta:
verbose_name = _("service status")
ordering = ["created_at"]
unique_together = ["service", "user"]

service = models.OneToOneField(Service, models.CASCADE)
service = models.ForeignKey(Service, models.CASCADE)
user = models.ForeignKey(User, models.CASCADE, related_name="service_status")
created_at = models.DateTimeField(_("created at"), auto_now_add=True)

Expand All @@ -42,3 +43,10 @@ def create_service_status(sender, instance, created, **kwargs):
if created:
for service in Service.objects.filter(default=True):
instance.service_status.create(service=service)


@receiver(post_save, sender=Service)
def create_service_default_in_all_user(sender, instance, created, **kwargs):
if created and instance.default:
for user in User.objects.all():
user.service_status.create(service=instance)

0 comments on commit 32dc63e

Please sign in to comment.