from django.db import models import binascii from site_tps import qaes from django.conf import settings class AESEncryptedField(models.CharField): def save_form_data(self, instance, data): setattr(instance, self.name, binascii.b2a_base64(qaes.encrypt(settings.AES_KEY, data))) def value_from_object(self, obj): return qaes.decrypt(settings.AES_KEY, binascii.a2b_base64(getattr(obj, self.attname))) class ContentSettings(models.Model): ftp_url = models.URLField( max_length=255, verbose_name="URL du FTP", default="", ) ftp_id = models.CharField( max_length=255, verbose_name="Identifiant sur le FTP", default="" ) ftp_pass = AESEncryptedField( max_length=255, verbose_name="Mot de passe", default="" ) class SiteSettings(models.Model): allow_upload = models.BooleanField( verbose_name="Autoriser l'upload de vidéos.", default=False, ) home_message = models.TextField( verbose_name="Message de la page d'accueil", default="" ) @classmethod def get_settings(cls): return cls.objects.get_or_create()[0]