from django.db import models
from django.db.models.signals import post_delete, pre_save
from django.utils.translation import gettext_lazy as _
from firm_info.managers import SingletonManager
from smart_media.modelfields import SmartMediaField
from smart_media.signals import auto_purge_files_on_change, auto_purge_files_on_delete
post_delete.connect(
auto_purge_files_on_delete(["logo", "logo_invert", "favicon"]),
dispatch_uid="firm_info_firm_contact_medias_on_delete",
sender=FirmContact,
weak=False,
)
pre_save.connect(
auto_purge_files_on_change(["logo", "logo_invert", "favicon"]),
dispatch_uid="firm_info_firm_contact_medias_on_change",
sender=FirmContact,
weak=False,
)
[docs]
class Link(models.Model):
"""
Represents a social network link.
Attributes:
SOCIAL_NETWORK_NAMES (tuple): Choices for the name field representing
various social network names.
name (CharField): The name of the social network.
url (URLField): The URL of the social network link.
client_contact (ForeignKey): The foreign key to the FirmContact model
representing the client contact.
"""
SOCIAL_NETWORK_NAMES = (
("linkedin", "linkedin"),
("facebook", "facebook"),
("twitter", "twitter"),
("youtube", "youtube"),
("instagram", "instagram"),
("glassdoor", "glassdoor"),
("bitbucket", "bitbucket"),
("github", "github"),
("gitlab", "gitlab"),
("tiktok", "tiktok"),
("twitch", "twitch"),
("discord", "discord"),
("vk", "vk"),
("slack", "slack"),
("whatsapp", "whatsapp"),
("weechat", "weechat"),
)
name = models.CharField(max_length=255, choices=SOCIAL_NETWORK_NAMES)
url = models.URLField(max_length=255)
client_contact = models.ForeignKey(FirmContact, on_delete=models.CASCADE)
def __str__(self):
return f"{self.name} - {self.url}"
class Meta:
verbose_name = _("Social network link")
verbose_name_plural = _("Social networks links")
[docs]
class SocialSharing(models.Model):
"""
Represents social media sharing information.
Attributes:
og_image (SmartMediaField): The OG image for social media sharing.
og_description (TextField): The OG description for social media sharing.
og_twitter_site (CharField): The OG Twitter site for social media sharing.
objects (SingletonManager): The manager for the FirmContact model.
"""
og_image = SmartMediaField(
_("OG Image"),
null=True,
blank=True,
upload_to="firm/social_sharing/%y/%m",
)
og_description = models.TextField(
max_length=180,
null=False,
blank=True,
default="",
verbose_name=_("OG Description"),
)
og_twitter_site = models.CharField(
max_length=100,
null=False,
blank=True,
default="",
verbose_name=_("OG Twitter Site"),
)
objects = SingletonManager()
class Meta:
verbose_name = _("Social media share")
verbose_name_plural = _("Social media shares")
post_delete.connect(
auto_purge_files_on_delete(["og_image"]),
dispatch_uid="socialsharing_medias_on_delete",
sender=SocialSharing,
weak=False,
)
pre_save.connect(
auto_purge_files_on_change(["og_image"]),
dispatch_uid="socialsharing_medias_on_change",
sender=SocialSharing,
weak=False,
)
[docs]
class Tracking(models.Model):
"""
Represents tracking information.
Attributes:
tag_analytic (CharField): The tag analytic for tracking.
objects (SingletonManager): The manager for the FirmContact model.
"""
tag_analytic = models.CharField(
max_length=100,
null=False,
blank=True,
default="",
verbose_name=_("Tag Analytic"),
)
objects = SingletonManager()
class Meta:
verbose_name = _("Tracking")
verbose_name_plural = _("Tracks")
[docs]
class AppsBanner(models.Model):
"""
Represents an app banner in the Django firm_info models.
Attributes:
APPS_CHOICES (list): A list of tuples representing the available choices for
the application type.
application_type (models.CharField): The type of the application.
image (SmartMediaField): The image associated with the app banner.
title (models.CharField): The title of the app banner.
description (models.TextField): The description of the app banner.
"""
APPS_CHOICES = [
("application_sent", _("Application sent")),
("free_apply", _("Free apply")),
("job_offers", _("Job offers")),
("news", _("News")),
("trombinoscope", _("Trombinoscope")),
]
application_type = models.CharField(
max_length=16, choices=APPS_CHOICES, unique=True
)
image = SmartMediaField(
_("Image"),
null=True,
blank=True,
upload_to="firm/apps_banner/%y/%m",
)
title = models.CharField(_("Title"), max_length=150, blank=True, null=True)
description = models.TextField(
verbose_name=_("Description"),
blank=True,
null=True
)
def __str__(self):
return self.get_application_type_display()
class Meta:
verbose_name = _("App banner")
verbose_name_plural = _("App banners")
post_delete.connect(
auto_purge_files_on_delete(["image"]),
dispatch_uid="apps_banner_medias_on_delete",
sender=AppsBanner,
weak=False,
)
pre_save.connect(
auto_purge_files_on_change(["image"]),
dispatch_uid="apps_banner_medias_on_change",
sender=AppsBanner,
weak=False,
)