44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from django.db import models
|
|
from django.conf import settings
|
|
from django.utils.safestring import mark_safe
|
|
from django.utils.translation import gettext
|
|
|
|
|
|
class Service(models.Model):
|
|
class SourcesType(models.TextChoices):
|
|
closed = "CLOSED", gettext("Sources closes")
|
|
open = "OPEN", gettext("Sources ouvertes")
|
|
unknown = "UNK", gettext("Inconnu")
|
|
|
|
class HostedType(models.TextChoices):
|
|
federated = "FED", gettext("Fédéré")
|
|
centralized = "CENT", gettext("Centralisé")
|
|
unknown = "UNK", gettext("Inconnu")
|
|
|
|
id = models.AutoField(primary_key=True)
|
|
name = models.CharField(max_length=150)
|
|
description = models.TextField()
|
|
description_en = models.TextField(null=True)
|
|
photo = models.ImageField(upload_to="services")
|
|
|
|
sources = models.CharField(
|
|
max_length=10, choices=SourcesType.choices, default=SourcesType.unknown,
|
|
)
|
|
hosted = models.CharField(
|
|
max_length=10, choices=HostedType.choices, default=HostedType.unknown,
|
|
)
|
|
|
|
domain = models.CharField(max_length=150)
|
|
hidden = models.BooleanField(default=False)
|
|
|
|
def domain_tag(self):
|
|
return mark_safe(
|
|
f'<a href="http://{self.domain}" target="_blank">{self.domain}</a>'
|
|
)
|
|
|
|
def image_tag(self):
|
|
return mark_safe(
|
|
f"<img src="
|
|
f'"{settings.MEDIA_URL + self.photo.name}"'
|
|
f' width="50" height="50">'
|
|
)
|