2019-11-24 16:29:52 +00:00
|
|
|
from crispy_forms.helper import FormHelper
|
|
|
|
from crispy_forms.layout import Layout, Fieldset
|
2019-11-24 16:22:30 +00:00
|
|
|
from django import forms
|
2019-11-12 17:13:56 +00:00
|
|
|
from django.forms import ModelForm
|
2019-11-24 16:22:30 +00:00
|
|
|
from djconfig.forms import ConfigForm
|
2019-11-12 17:13:56 +00:00
|
|
|
|
|
|
|
from bots.models import TelegramBot
|
|
|
|
|
|
|
|
|
|
|
|
class BotForm(ModelForm):
|
|
|
|
prefix = 'bot'
|
|
|
|
|
|
|
|
def __init__(self, *args, module, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
if not hasattr(module, 'rpc_dispatcher'):
|
|
|
|
self.fields.pop('rpc_name')
|
|
|
|
if not hasattr(module, 'periodic_task'):
|
|
|
|
self.fields.pop('periodic_interval')
|
|
|
|
self.fields.pop('periodic_last_run')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = TelegramBot
|
|
|
|
exclude = 'owner', 'config_type', 'config_id',
|
2019-11-24 16:22:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BotsAppConfigForm(ConfigForm):
|
|
|
|
slug = 'bots'
|
|
|
|
title = 'Bots'
|
|
|
|
|
|
|
|
tmp_uploads_chat_id = forms.CharField(required=True)
|
2021-03-15 18:59:34 +00:00
|
|
|
aws_access_key_id = forms.CharField(required=True)
|
|
|
|
aws_secret_access_key = forms.CharField(required=True)
|
|
|
|
s3_bucket = forms.CharField(required=True)
|
2019-11-24 16:29:52 +00:00
|
|
|
|
|
|
|
helper = FormHelper()
|
|
|
|
helper.form_class = 'form-horizontal'
|
|
|
|
helper.label_class = 'col-sm-2'
|
|
|
|
helper.field_class = 'col-sm-10'
|
|
|
|
helper.form_tag = False
|
|
|
|
helper.layout = Layout(
|
|
|
|
Fieldset('Global', 'tmp_uploads_chat_id'),
|
2021-03-15 18:59:34 +00:00
|
|
|
Fieldset('Amazon S3', 'aws_access_key_id', 'aws_secret_access_key', 's3_bucket'),
|
2019-11-24 16:29:52 +00:00
|
|
|
)
|