소스 검색

favicon, channel_setting fundamentals

Double-Vee 3 년 전
부모
커밋
fcd02c09f4

+ 17 - 9
webgui/config/forms.py

@@ -1,14 +1,14 @@
-from django.forms import ModelForm, CharField, SlugField
+from django import forms
 from .models import ChannelSettings
 
-class ChannelSettingsForm(ModelForm):
+class ChannelSettingsForm(forms.ModelForm):
     class Meta:
-        model=ChannelSettings
+        model = ChannelSettings
         fields = ['interact']
         #fields='__all__'
         #exclude = ['id'] #Does not need "fields = '__all__'".
-        # labels={
-        #     'name': '<i class="sitemap icon"></i>Name',
+        # labels = {
+        #     'interact': 'Interact',
         #     'slug': '<i class="linkify icon"></i>Slug',
         #     'nickname': '<i class="id badge icon"></i>Nickname',
         #     'username': '<i class="id card icon"></i>Username',
@@ -20,10 +20,18 @@ class ChannelSettingsForm(ModelForm):
         #     'services': '<i class="lightbulb outline icon"></i>Network services',
         #     'enabled': '<i class="power off icon"></i>Enabled',
         #     # 'mute': '<i class="comment slash icon"></i>Mute',
-        # }
-        # widgets={
-        #     'enabled': forms.CheckboxInput(attrs={'_style': 'inverted toggle',}),
-        # }
+        #}
+        
+        widgets={
+            'interact': forms.CheckboxInput(attrs={
+                '_style': 'inverted toggle',
+                '_icon': 'comment dots',
+                '_align': 'left',
+                #'_no_label': True,
+                '_help': True,
+                #'_inline': False,
+            }),
+        }
 
 # class HostForm(ModelForm):
 #     class Meta:

+ 1 - 1
webgui/config/models.py

@@ -4,7 +4,6 @@ from django.db import models
 
 class ChannelSettings(models.Model):
 	id = models.AutoField(
-		#max_length = 11,   # 'max_length' is ignored when used with AutoField.
 		primary_key = True,
 	)
 	channel = models.ForeignKey(
@@ -15,6 +14,7 @@ class ChannelSettings(models.Model):
 	)
 	interact = models.BooleanField(
 		default = False,
+		help_text = "Allow the robot to speak and interact with users."
 	)
 	
 	class Meta:

+ 8 - 18
webgui/config/templates/config/channel_settings.html

@@ -1,25 +1,15 @@
 {% extends "base.html" %}
 {% load static %}
 {% load semanticui %}
-{% block head %}
-    <meta name="nonfiction" content="true">
-    <script type="text/javascript" src="{% static 'javascript/loader.js' %}"></script>
-{% endblock %}
-{% block title %}{{ title }}{% endblock %}
-{% block description %}{{ descriptiopn }}{% endblock %}
-{% block keywords %}{{ keywords }}{% endblock %}
-{% block keywords-not %}{% endblock %}
 {% block content %}
-    {% render_form form %}
+    <form class= "ui form" method="post">
+        {% csrf_token %}
+        {% render_form form %}
+
+        {{ channel_settings.interact }}
+        <button class="ui right floated inverted positive button" type="submit" value="Submit"><i class="save icon"></i>Save</button>
+    </form>
     
-    <article class="ui container">
-        <header class="ui six statistics">
-            Header
-        </header>
-        <section class="ui basic text segment container">
-            {{ channel_settings.interact }}
-        </section>
-    </article>
 {% endblock %}
 {% block breadcrumbs %}
     <i class="sitemap icon"></i>
@@ -28,5 +18,5 @@
     Bar
     <div class="divider"> / </div>
     <i class="hashtag icon"></i>
-    <div class="active section">Channels</div>
+    <div class="active section">Channel settings</div>
 {% endblock %}

+ 7 - 7
webgui/config/views.py

@@ -7,15 +7,15 @@ from .models import ChannelSettings
 from .forms import ChannelSettingsForm
 
 def channel_settings(request, channel_id):
-	print(ChannelSettings.objects.get(channel=channel_id))
-	print(ChannelSettings.objects.get(channel=channel_id).interact)
+	initial_data = {
+		"interact": ChannelSettings.objects.get(channel=channel_id).interact
+	}
+	
 	context = {
-		'title': 'Channel settings for ',
+		'title': 'Channel settings',
 		'icon': 'screwdriver',
-		'description': 'modify channel settings for ' + APPLICATION_NAME,
+		'description': 'Modify channel settings for ' + APPLICATION_NAME,
 		'keywords': 'settigns, channel',
-
-		'channel_settings': ChannelSettings.objects.get(channel=channel_id),
-		'form': ChannelSettingsForm,
+		'form': ChannelSettingsForm(initial=initial_data),
 	}
 	return render(request, 'config/channel_settings.html', context)

BIN
webgui/static/favicon-16x16.png


BIN
webgui/static/favicon-32x32.png


BIN
webgui/static/favicon.ico


+ 4 - 3
webgui/templates/base.html

@@ -12,7 +12,7 @@
     <meta name="description" content="{{ description }}">
     <meta name="keywords" content="{{ keywords }}">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <link rel="icon" href="{% static "favicon.png" %}">
+    <link rel="icon" href="{% static "favicon-32x32.png" %}">
     <link rel="stylesheet" type="text/css" href="{% static "semantic.min.css" %}">
     <style>
       .main.container {
@@ -27,12 +27,13 @@
     </style>
     <script src="{% static "jquery@3.3.1/dist/jquery.min.js" %}"></script>
     <script src="{% static "semantic.min.js" %}"></script>
-    <script src="{% static "Chart.min.js" %}"></script>
+    <!--script src="{% static "Chart.min.js" %}"></script-->
   </head>
   <body>
     <nav class="ui pointing top fixed inverted menu">
       <a class="item" href="% url 'index' %">
-        <!--img src="{% static "logo.png" %}" alt="{{ settings.APPLICATION_NAME }} logo"-->
+        <!--img src="{% static "favicon-32x32.png" %}" alt="{{ settings.APPLICATION_NAME }} logo"-->
+        <i class="robot icon"></i>
         {{ settings.APPLICATION_NAME }}
       </a>
       {% if title %}

+ 14 - 19
webgui/webgui/routers.py

@@ -3,43 +3,38 @@ class BotRouter:
     A router to control all database operations on models in the
     auth application.
     """
+    route_app_labels = {'config', 'stats'}
+
     def db_for_read(self, model, **hints):
         """
-        Attempts to read auth models go to auth_db.
+        Attempts to read auth models go to bot_db.
         """
-        if model._meta.app_label == 'config':
-            return 'bot_db'
-        elif model._meta.app_label == 'stats':
+        if model._meta.app_label in self.route_app_labels:
             return 'bot_db'
         return None
         
     def db_for_write(self, model, **hints):
         """
-        Attempts to write auth models go to auth_db.
+        Attempts to write auth models go to bot_db.
         """
-        if model._meta.app_label == 'config':
-            return 'bot_db'
-        elif model._meta.app_label == 'stats':
+        if model._meta.app_label in self.route_app_labels:
             return 'bot_db'
         return None
 
     def allow_relation(self, obj1, obj2, **hints):
         """
-        Allow relations if a model in the auth app is involved.
+        Allow relations if a model in the auth or contenttypes apps is
+        involved.
         """
-        if obj1._meta.app_label == 'config' or obj2._meta.app_label == 'config':
-            return False
-        elif obj1._meta.app_label == 'stats' or obj2._meta.app_label == 'stats':
-            return False
+        if (obj1._meta.app_label in self.route_app_labels or obj2._meta.app_label in self.route_app_labels):
+           return True
         return None
 
     def allow_migrate(self, db, app_label, model_name=None, **hints):
         """
-        Make sure the auth app only appears in the 'auth_db'
-        database.
+        Make sure the "route_app_labels" apps only appear in the
+        'bot_db' database.
         """
-        if app_label == 'config':
-            return False
-        elif app_label == 'stats':
-            return False
+        if app_label in self.route_app_labels:
+            return db == 'bot_db'
         return None