diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py new file mode 100644 index 0000000..142d7ce --- /dev/null +++ b/tubearchivist/home/forms.py @@ -0,0 +1,62 @@ +"""functionality: +- hold all form classes used in the views +""" + +from django import forms +from django.contrib.auth.forms import AuthenticationForm +from django.forms.widgets import PasswordInput, TextInput + + +class CustomAuthForm(AuthenticationForm): + """better styled login form""" + + username = forms.CharField( + widget=TextInput(attrs={"placeholder": "Username"}), label=False + ) + password = forms.CharField( + widget=PasswordInput(attrs={"placeholder": "Password"}), label=False + ) + + +class UserSettingsForm(forms.Form): + """user configurations values""" + + CHOICES = [ + ("", "-- change color scheme --"), + ("dark", "Dark"), + ("light", "Light"), + ] + + colors = forms.ChoiceField( + widget=forms.Select, choices=CHOICES, required=False + ) + page_size = forms.IntegerField(required=False) + + +class ApplicationSettingsForm(forms.Form): + """handle all application settings""" + + METADATA_CHOICES = [ + ("", "-- change metadata embed --"), + ("0", "don't embed metadata"), + ("1", "embed metadata"), + ] + + THUMBNAIL_CHOICES = [ + ("", "-- change thumbnail embed --"), + ("0", "don't embed thumbnail"), + ("1", "embed thumbnail"), + ] + + subscriptions_channel_size = forms.IntegerField(required=False) + downloads_limit_count = forms.IntegerField(required=False) + downloads_limit_speed = forms.IntegerField(required=False) + downloads_throttledratelimit = forms.IntegerField(required=False) + downloads_sleep_interval = forms.IntegerField(required=False) + downloads_format = forms.CharField(required=False) + downloads_add_metadata = forms.ChoiceField( + widget=forms.Select, choices=METADATA_CHOICES, required=False + ) + downloads_add_thumbnail = forms.ChoiceField( + widget=forms.Select, choices=THUMBNAIL_CHOICES, required=False + ) diff --git a/tubearchivist/home/src/config.py b/tubearchivist/home/src/config.py index 6e304f5..32402fd 100644 --- a/tubearchivist/home/src/config.py +++ b/tubearchivist/home/src/config.py @@ -86,11 +86,23 @@ class AppConfig: elif to_write.isdigit(): to_write = int(to_write) - config_dict, config_value = key.split(".") + config_dict, config_value = key.split("_", maxsplit=1) config[config_dict][config_value] = to_write RedisArchivist().set_message("config", config, expire=False) + @staticmethod + def set_user_config(form_post, user_id): + """set values in redis for user settings""" + for key, value in form_post.items(): + to_write = value[0] + if len(to_write): + if to_write.isdigit(): + to_write = int(to_write) + message = {"status": to_write} + redis_key = f"{user_id}:{key}" + RedisArchivist().set_message(redis_key, message, expire=False) + def load_new_defaults(self): """check config.json for missing defaults""" default_config = self.get_config_file() diff --git a/tubearchivist/home/src/searching.py b/tubearchivist/home/src/searching.py index 2d8dee4..14e8c5a 100644 --- a/tubearchivist/home/src/searching.py +++ b/tubearchivist/home/src/searching.py @@ -12,6 +12,7 @@ from datetime import datetime import requests from home.src.config import AppConfig +from home.src.helper import RedisArchivist from home.src.thumbnails import ThumbManager @@ -181,13 +182,23 @@ class Pagination: figure out the pagination based on page size and total_hits """ - def __init__(self, page_get, search_get=False): - config = AppConfig().config - self.page_size = config["archive"]["page_size"] + def __init__(self, page_get, user_id, search_get=False): + self.user_id = user_id + self.page_size = self.get_page_size() self.page_get = page_get self.search_get = search_get self.pagination = self.first_guess() + def get_page_size(self): + """get default or user modified page_size""" + key = f"{self.user_id}:page_size" + page_size = RedisArchivist().get_message(key)["status"] + if not page_size: + config = AppConfig().config + page_size = config["archive"]["page_size"] + + return page_size + def first_guess(self): """build first guess before api call""" page_get = self.page_get diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index 9dab509..306424b 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -1,20 +1,16 @@ {% extends "home/base.html" %} {% block content %}
- + +