site_tps/settings/models.py

40 lines
1,013 B
Python
Raw Normal View History

2018-01-14 12:19:11 +00:00
from django.db import models
import binascii
import site_tps.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,
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",
)