使用 SysOptions

This commit is contained in:
virusdefender
2017-10-02 03:54:34 +08:00
parent d650252a1a
commit 9990cf647a
19 changed files with 297 additions and 172 deletions

View File

@@ -1,2 +1,2 @@
from .api import * # NOQA
from ._serializers import * # NOQA
from .api import * # NOQA

View File

@@ -3,7 +3,6 @@ from django.test.testcases import TestCase
from rest_framework.test import APIClient
from account.models import AdminType, ProblemPermission, User, UserProfile
from conf.models import WebsiteConfig
class APITestCase(TestCase):
@@ -28,9 +27,6 @@ class APITestCase(TestCase):
return self.create_user(username=username, password=password, admin_type=AdminType.SUPER_ADMIN,
problem_permission=ProblemPermission.ALL, login=login)
def create_website_config(self):
return WebsiteConfig.objects.create()
def reverse(self, url_name):
return reverse(url_name)

View File

@@ -2,3 +2,4 @@ class CacheKey:
waiting_queue = "waiting_queue"
contest_rank_cache = "contest_rank_cache_"
website_config = "website_config"
option = "option"

View File

@@ -1,35 +1,9 @@
import logging
import random
import datetime
from io import BytesIO
import random
from base64 import b64encode
from io import BytesIO
from django.utils.crypto import get_random_string
from envelopes import Envelope
from conf.models import SMTPConfig
logger = logging.getLogger(__name__)
def send_email(from_name, to_email, to_name, subject, content):
smtp = SMTPConfig.objects.first()
if not smtp:
return
envlope = Envelope(from_addr=(smtp.email, from_name),
to_addr=(to_email, to_name),
subject=subject,
html_body=content)
try:
envlope.send(smtp.server,
login=smtp.email,
password=smtp.password,
port=smtp.port,
tls=smtp.tls)
return True
except Exception as e:
logger.exception(e)
return False
def rand_str(length=32, type="lower_hex"):