Parcourir la source

semanticuiforms intergration, seperated databases routing

Double-Vee il y a 3 ans
Parent
commit
1a4ce35b4c

+ 100 - 0
webgui/config/forms.py

@@ -0,0 +1,100 @@
+from django.forms import ModelForm, CharField, SlugField
+from .models import ChannelSettings
+
+class ChannelSettingsForm(ModelForm):
+    class Meta:
+        model=ChannelSettings
+        fields = ['interact']
+        #fields='__all__'
+        #exclude = ['id'] #Does not need "fields = '__all__'".
+        # labels={
+        #     'name': '<i class="sitemap icon"></i>Name',
+        #     'slug': '<i class="linkify icon"></i>Slug',
+        #     'nickname': '<i class="id badge icon"></i>Nickname',
+        #     'username': '<i class="id card icon"></i>Username',
+        #     'password': '<i class="privacy icon"></i>Password',
+        #     'mail': '<i class="envelope icon"></i>NickServ registration E-mail',
+        #     'home_channel': '<i class="hashtag icon"></i>Home channel',
+        #     'command_character': '<i class="terminal icon"></i>Command character',
+        #     'help_character': '<i class="help icon"></i>Help character',
+        #     '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',}),
+        # }
+
+# class HostForm(ModelForm):
+#     class Meta:
+#         model=Host
+#         exclude=['network', 'connection_attempts', 'connection_succeeds']
+#         labels={
+#             'address': '<i class="server icon"></i>Address',
+#             'port': '<i class="dungeon icon"></i>Port',
+#             'ssl': '<i class="lock icon"></i>Use SSL',
+#         }
+#         widgets={
+#             'ssl': forms.CheckboxInput(attrs={'_style': 'inverted toggle',}),
+#         }
+#         layout = [
+#             ('Four Fields',
+#                 ('Field', 'address'),
+#                 ('Field', 'port'),
+#                 ('Field', 'ssl'),
+#                 ('Field', 'DELETE'),
+#             )
+#         ]
+
+# class OwnerForm(ModelForm):
+#     class Meta:
+#         model=Owner
+#         exclude=['network',]
+#         labels={
+#             'hostmask': '<i class="fingerprint icon"></i>Owner hostmask',
+#         }
+#         layout = [
+#             ('Two Fields',
+#                 ('Field', 'hostmask'),
+#                 ('Field', 'DELETE'),
+#             )
+#         ]
+
+# class ChannelForm(ModelForm):
+#     class Meta:
+#         model=Channel
+#         fields=['autojoin', 'statistic_commands', 'games', 'chat']
+#         labels={
+#             'autojoin': '<i class="power icon"></i>Auto join',
+#             'statistic_commands': '<i class="chart pie icon"></i>Statistic commands',
+#             'chat': '<i class="comment dots icon"></i>Chat',
+#             'games': '<i class="gamepad icon"></i>Games',
+#         }
+#         widgets={
+#             'autojoin': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
+#             'statistic_commands': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
+#             'chat': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
+#             'games': forms.CheckboxInput(attrs={'_style': 'inverted toggle'}),
+#         }
+
+# class CurseWordForm(ModelForm):
+#     class Meta:
+#         model=CurseWord
+#         fields={'content'}
+#         labels={
+#             'content': '<i class="book dead icon"></i>Curse word'
+#         }
+#         widgets={
+#             'content': forms.TextInput(attrs={'_no_required': 'True'}),
+#         }
+
+# class AdjectiveForm(ModelForm):
+#     class Meta:
+#         model=Adjective
+#         fields={'content'}
+#         labels={
+#             'content': '<i class="book dead icon"></i>Adjective'
+#         }
+#         widgets={
+#             'content': forms.TextInput(attrs={'_no_required': 'True'}),
+#         }

+ 3 - 1
webgui/config/models.py

@@ -8,8 +8,10 @@ class ChannelSettings(models.Model):
 		primary_key = True,
 	)
 	channel = models.ForeignKey(
-		'stats.Guild',
+		"stats.Channel",
 		on_delete = models.CASCADE,
+		to_field = "channel_id",
+		db_column = "channel",
 	)
 	interact = models.BooleanField(
 		default = False,

+ 32 - 0
webgui/config/templates/config/channel_settings.html

@@ -0,0 +1,32 @@
+{% 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 %}
+    
+    <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>
+    Foo
+    <div class="divider"> / </div>
+    Bar
+    <div class="divider"> / </div>
+    <i class="hashtag icon"></i>
+    <div class="active section">Channels</div>
+{% endblock %}

+ 9 - 0
webgui/config/urls.py

@@ -0,0 +1,9 @@
+from django.urls import path
+
+
+from . import views
+
+app_name = 'config'
+urlpatterns = [
+    path('channel-settings/<int:channel_id>/', views.channel_settings, name='channel-settings'),
+]

+ 18 - 0
webgui/config/views.py

@@ -1,3 +1,21 @@
 from django.shortcuts import render
 
 # Create your views here.
+from webgui.settings import APPLICATION_NAME
+
+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)
+	context = {
+		'title': 'Channel settings for ',
+		'icon': 'screwdriver',
+		'description': 'modify channel settings for ' + APPLICATION_NAME,
+		'keywords': 'settigns, channel',
+
+		'channel_settings': ChannelSettings.objects.get(channel=channel_id),
+		'form': ChannelSettingsForm,
+	}
+	return render(request, 'config/channel_settings.html', context)

+ 2 - 0
webgui/stats/models.py

@@ -27,6 +27,8 @@ class Channel(models.Model):
 	guild = models.ForeignKey(
 		'Guild',
 		on_delete = models.CASCADE,
+		to_field = "guild_id",
+		db_column = "guild",
 	)
 
 	class Meta:

+ 7 - 2
webgui/templates/base.html

@@ -31,8 +31,8 @@
   </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">
+      <a class="item" href="% url 'index' %">
+        <!--img src="{% static "logo.png" %}" alt="{{ settings.APPLICATION_NAME }} logo"-->
         {{ settings.APPLICATION_NAME }}
       </a>
       {% if title %}
@@ -60,5 +60,10 @@
     <div class="ui main container">
       {% block content %}{% endblock content %}
     </div>
+    <footer class="ui bottom fixed borderless menu">
+      <nav class="ui breadcrumb item">
+        {% block breadcrumbs %}{% endblock %}
+      </nav>
+    </footer>
   </body>
 </html>

+ 1 - 1
webgui/webgui/routers.py

@@ -1,4 +1,4 @@
-class GameRouter:
+class BotRouter:
     """
     A router to control all database operations on models in the
     auth application.

+ 5 - 0
webgui/webgui/settings.py

@@ -78,6 +78,11 @@ TEMPLATES = [
 WSGI_APPLICATION = 'webgui.wsgi.application'
 
 
+# Database
+# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
+DATABASE_ROUTERS = ['webgui.routers.BotRouter']
+
+
 # Password validation
 # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
 

+ 2 - 1
webgui/webgui/urls.py

@@ -14,8 +14,9 @@ Including another URLconf
     2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
 """
 from django.contrib import admin
-from django.urls import path
+from django.urls import path, include
 
 urlpatterns = [
+    path('config/', include('config.urls')),
     path('admin/', admin.site.urls),
 ]