site_tps/settings/models.py

48 lines
1.2 KiB
Python
Raw Normal View History

2018-01-14 12:19:11 +00:00
from django.db import models
import binascii
2018-01-20 22:08:46 +00:00
from site_tps import qaes
from django.conf import settings
2018-01-14 12:19:11 +00:00
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,
2018-01-20 22:08:46 +00:00
verbose_name="URL du FTP",
default="",
)
ftp_id = models.CharField(
max_length=255,
2018-01-20 22:08:46 +00:00
verbose_name="Identifiant sur le FTP",
default=""
)
ftp_pass = AESEncryptedField(
max_length=255,
2018-01-20 22:08:46 +00:00
verbose_name="Mot de passe",
default=""
)
class SiteSettings(models.Model):
allow_upload = models.BooleanField(
2018-01-20 22:08:46 +00:00
verbose_name="Autoriser l'upload de vidéos.",
default=False,
)
2018-01-20 22:08:46 +00:00
home_message = models.TextField(
verbose_name="Message de la page d'accueil",
default=""
)
2018-01-20 22:08:46 +00:00
@classmethod
def get_settings(cls):
return cls.objects.get_or_create()[0]