from django.db import models import binascii import site_tps.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, name="URL du FTP", ) ftp_id = models.CharField( max_length=255, name="Identifiant sur le FTP", ) ftp_pass = AESEncryptedField( max_length=255, name="Mot de passe" ) class SiteSettings(models.Model): allow_upload = models.BooleanField( help_text="Autoriser l'upload de vidéos." ) site_name = models.CharField( max_length=255, help_text="Nom du site", )