mirror of https://github.com/openspug/spug
U api update
parent
da58ebab4a
commit
b5d100e977
|
@ -1,7 +1,8 @@
|
|||
from django.db import models
|
||||
from libs import ModelMixin
|
||||
|
||||
|
||||
class Setting(models.Model):
|
||||
class Setting(models.Model, ModelMixin):
|
||||
key = models.CharField(max_length=50, unique=True)
|
||||
value = models.TextField()
|
||||
desc = models.CharField(max_length=255, null=True)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
from django.urls import path
|
||||
|
||||
from .views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('', SettingView.as_view()),
|
||||
]
|
|
@ -3,7 +3,7 @@ from apps.setting.models import Setting
|
|||
|
||||
|
||||
class AppSetting:
|
||||
keys = ('public_key', 'private_key')
|
||||
keys = ('public_key', 'private_key', 'mail_service')
|
||||
|
||||
@classmethod
|
||||
@lru_cache(maxsize=64)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
from django.views.generic import View
|
||||
from libs import JsonParser, Argument, json_response
|
||||
from apps.setting.utils import AppSetting
|
||||
from apps.setting.models import Setting
|
||||
|
||||
|
||||
class SettingView(View):
|
||||
def get(self, request):
|
||||
settings = Setting.objects.exclude(key__in=('public_key', 'private_key'))
|
||||
return json_response(settings)
|
||||
|
||||
def post(self, request):
|
||||
form, error = JsonParser(
|
||||
Argument('data', type=list, help='缺少必要的参数')
|
||||
).parse(request.body)
|
||||
if error is None:
|
||||
for item in form.data:
|
||||
AppSetting.set(**item)
|
||||
return json_response(error=error)
|
|
@ -22,4 +22,5 @@ urlpatterns = [
|
|||
path('schedule/', include('apps.schedule.urls')),
|
||||
path('monitor/', include('apps.monitor.urls')),
|
||||
path('alarm/', include('apps.alarm.urls')),
|
||||
path('setting/', include('apps.setting.urls')),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue