diff options
author | clarkzjw <[email protected]> | 2023-02-21 16:46:11 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-21 16:46:11 -0800 |
commit | 22fb6a357f1b6b91f04a180604e2f992280ee661 (patch) | |
tree | 0ed80d12ac41475138077891ffea0bb78fe392cb | |
parent | 0ce8037dcb01745edc9930b09e72bf7ea4dfcf4e (diff) | |
download | swarm2fediverse-22fb6a357f1b6b91f04a180604e2f992280ee661.tar.gz |
add django app templatefeature/django
-rw-r--r-- | bot.py (renamed from bot/bot.py) | 14 | ||||
-rw-r--r-- | bot/__init__.py | 13 | ||||
-rw-r--r-- | bot/admin.py | 5 | ||||
-rw-r--r-- | bot/apps.py | 6 | ||||
-rw-r--r-- | bot/migrations/0001_initial.py | 44 | ||||
-rw-r--r-- | bot/migrations/__init__.py | 0 | ||||
-rw-r--r-- | bot/models.py | 9 | ||||
-rw-r--r-- | bot/tests.py | 3 | ||||
-rw-r--r-- | bot/urls.py | 7 | ||||
-rw-r--r-- | bot/views.py | 5 | ||||
-rw-r--r-- | checkin/settings.py | 2 | ||||
-rw-r--r-- | checkin/urls.py | 3 |
12 files changed, 97 insertions, 14 deletions
@@ -5,6 +5,20 @@ | |||
5 | import logging | 5 | import logging |
6 | import io | 6 | import io |
7 | import telegram.constants | 7 | import telegram.constants |
8 | from telegram import __version__ as TG_VER | ||
9 | |||
10 | try: | ||
11 | from telegram import __version_info__ | ||
12 | except ImportError: | ||
13 | __version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment] | ||
14 | |||
15 | if __version_info__ < (20, 0, 0, "alpha", 1): | ||
16 | raise RuntimeError( | ||
17 | f"This example is not compatible with your current PTB version {TG_VER}. To view the " | ||
18 | f"{TG_VER} version of this example, " | ||
19 | f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html" | ||
20 | ) | ||
21 | |||
8 | from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, ReplyKeyboardMarkup, KeyboardButton | 22 | from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, ReplyKeyboardMarkup, KeyboardButton |
9 | from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters, ConversationHandler, CallbackContext | 23 | from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters, ConversationHandler, CallbackContext |
10 | from ..config import BOT_TOKEN | 24 | from ..config import BOT_TOKEN |
diff --git a/bot/__init__.py b/bot/__init__.py index 5e3c341..e69de29 100644 --- a/bot/__init__.py +++ b/bot/__init__.py | |||
@@ -1,13 +0,0 @@ | |||
1 | from telegram import __version__ as TG_VER | ||
2 | |||
3 | try: | ||
4 | from telegram import __version_info__ | ||
5 | except ImportError: | ||
6 | __version_info__ = (0, 0, 0, 0, 0) # type: ignore[assignment] | ||
7 | |||
8 | if __version_info__ < (20, 0, 0, "alpha", 1): | ||
9 | raise RuntimeError( | ||
10 | f"This example is not compatible with your current PTB version {TG_VER}. To view the " | ||
11 | f"{TG_VER} version of this example, " | ||
12 | f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html" | ||
13 | ) | ||
diff --git a/bot/admin.py b/bot/admin.py new file mode 100644 index 0000000..f91be8f --- /dev/null +++ b/bot/admin.py | |||
@@ -0,0 +1,5 @@ | |||
1 | from django.contrib import admin | ||
2 | from django.contrib.auth.admin import UserAdmin | ||
3 | from .models import User | ||
4 | |||
5 | admin.site.register(User, UserAdmin) | ||
diff --git a/bot/apps.py b/bot/apps.py new file mode 100644 index 0000000..1cd7ff2 --- /dev/null +++ b/bot/apps.py | |||
@@ -0,0 +1,6 @@ | |||
1 | from django.apps import AppConfig | ||
2 | |||
3 | |||
4 | class BotConfig(AppConfig): | ||
5 | default_auto_field = 'django.db.models.BigAutoField' | ||
6 | name = 'bot' | ||
diff --git a/bot/migrations/0001_initial.py b/bot/migrations/0001_initial.py new file mode 100644 index 0000000..6b4f210 --- /dev/null +++ b/bot/migrations/0001_initial.py | |||
@@ -0,0 +1,44 @@ | |||
1 | # Generated by Django 4.1.7 on 2023-02-22 00:44 | ||
2 | |||
3 | import django.contrib.auth.models | ||
4 | from django.db import migrations, models | ||
5 | import django.utils.timezone | ||
6 | |||
7 | |||
8 | class Migration(migrations.Migration): | ||
9 | |||
10 | initial = True | ||
11 | |||
12 | dependencies = [ | ||
13 | ('auth', '0012_alter_user_first_name_max_length'), | ||
14 | ] | ||
15 | |||
16 | operations = [ | ||
17 | migrations.CreateModel( | ||
18 | name='User', | ||
19 | fields=[ | ||
20 | ('password', models.CharField(max_length=128, verbose_name='password')), | ||
21 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), | ||
22 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), | ||
23 | ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), | ||
24 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), | ||
25 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), | ||
26 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), | ||
27 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), | ||
28 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), | ||
29 | ('name', models.CharField(blank=True, max_length=50)), | ||
30 | ('telegram_id', models.PositiveBigIntegerField(primary_key=True, serialize=False, unique=True)), | ||
31 | ('username', models.CharField(max_length=32)), | ||
32 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), | ||
33 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), | ||
34 | ], | ||
35 | options={ | ||
36 | 'verbose_name': 'user', | ||
37 | 'verbose_name_plural': 'users', | ||
38 | 'abstract': False, | ||
39 | }, | ||
40 | managers=[ | ||
41 | ('objects', django.contrib.auth.models.UserManager()), | ||
42 | ], | ||
43 | ), | ||
44 | ] | ||
diff --git a/bot/migrations/__init__.py b/bot/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/bot/migrations/__init__.py | |||
diff --git a/bot/models.py b/bot/models.py new file mode 100644 index 0000000..c6df3e7 --- /dev/null +++ b/bot/models.py | |||
@@ -0,0 +1,9 @@ | |||
1 | from django.contrib.auth.models import AbstractUser | ||
2 | from django.db import models | ||
3 | |||
4 | |||
5 | class User(AbstractUser): | ||
6 | name = models.CharField(max_length=50, blank=True) | ||
7 | telegram_id = models.PositiveBigIntegerField(unique=True, primary_key=True) | ||
8 | username = models.CharField(max_length=32, blank=False) | ||
9 | USERNAME_FIELD = 'telegram_id' | ||
diff --git a/bot/tests.py b/bot/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/bot/tests.py | |||
@@ -0,0 +1,3 @@ | |||
1 | from django.test import TestCase | ||
2 | |||
3 | # Create your tests here. | ||
diff --git a/bot/urls.py b/bot/urls.py new file mode 100644 index 0000000..88a9cac --- /dev/null +++ b/bot/urls.py | |||
@@ -0,0 +1,7 @@ | |||
1 | from django.urls import path | ||
2 | |||
3 | from . import views | ||
4 | |||
5 | urlpatterns = [ | ||
6 | path('', views.index, name='index'), | ||
7 | ] | ||
diff --git a/bot/views.py b/bot/views.py new file mode 100644 index 0000000..963b6f7 --- /dev/null +++ b/bot/views.py | |||
@@ -0,0 +1,5 @@ | |||
1 | from django.http import HttpResponse | ||
2 | |||
3 | |||
4 | def index(request): | ||
5 | return HttpResponse("Hello, world. You're at the polls index.") | ||
diff --git a/checkin/settings.py b/checkin/settings.py index 6fa12a2..8d74770 100644 --- a/checkin/settings.py +++ b/checkin/settings.py | |||
@@ -31,6 +31,7 @@ ALLOWED_HOSTS = [] | |||
31 | # Application definition | 31 | # Application definition |
32 | 32 | ||
33 | INSTALLED_APPS = [ | 33 | INSTALLED_APPS = [ |
34 | 'bot.apps.BotConfig', | ||
34 | 'django.contrib.admin', | 35 | 'django.contrib.admin', |
35 | 'django.contrib.auth', | 36 | 'django.contrib.auth', |
36 | 'django.contrib.contenttypes', | 37 | 'django.contrib.contenttypes', |
@@ -99,6 +100,7 @@ AUTH_PASSWORD_VALIDATORS = [ | |||
99 | }, | 100 | }, |
100 | ] | 101 | ] |
101 | 102 | ||
103 | AUTH_USER_MODEL = 'bot.User' | ||
102 | 104 | ||
103 | # Internationalization | 105 | # Internationalization |
104 | # https://docs.djangoproject.com/en/4.1/topics/i18n/ | 106 | # https://docs.djangoproject.com/en/4.1/topics/i18n/ |
diff --git a/checkin/urls.py b/checkin/urls.py index a173748..4f9cbe8 100644 --- a/checkin/urls.py +++ b/checkin/urls.py | |||
@@ -14,8 +14,9 @@ Including another URLconf | |||
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) |
15 | """ | 15 | """ |
16 | from django.contrib import admin | 16 | from django.contrib import admin |
17 | from django.urls import path | 17 | from django.urls import path, include |
18 | 18 | ||
19 | urlpatterns = [ | 19 | urlpatterns = [ |
20 | path('bot/', include('bot.urls')), | ||
20 | path('admin/', admin.site.urls), | 21 | path('admin/', admin.site.urls), |
21 | ] | 22 | ] |