diff --git a/requirements.txt b/requirements.txt index 12dafde..318bcfa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django +Django>=4.2 djangorestframework django-cors-headers django-filter diff --git a/task/migrations/0011_alter_task_shared_id_alter_task_shared_link_and_more.py b/task/migrations/0011_alter_task_shared_id_alter_task_shared_link_and_more.py new file mode 100644 index 0000000..55b4e46 --- /dev/null +++ b/task/migrations/0011_alter_task_shared_id_alter_task_shared_link_and_more.py @@ -0,0 +1,36 @@ +# Generated by Django 4.1.7 on 2023-07-23 17:27 +from django.db import migrations +from django.db import models + + +class Migration(migrations.Migration): + + dependencies = [ + ("task", "0010_alter_task_full_download_now"), + ] + + operations = [ + migrations.AlterField( + model_name="task", + name="shared_id", + field=models.CharField(blank=True, default="", max_length=50), + ), + migrations.AlterField( + model_name="task", + name="shared_link", + field=models.CharField( + help_text="Link, with or without password", + max_length=100, + ), + ), + migrations.AlterField( + model_name="task", + name="shared_password", + field=models.CharField( + blank=True, + help_text="Password, if not included in the shared link", + max_length=4, + null=True, + ), + ), + ] diff --git a/task/models.py b/task/models.py index f8cf340..c8a4383 100644 --- a/task/models.py +++ b/task/models.py @@ -19,9 +19,17 @@ class Status(models.TextChoices): SAMPLING_DOWNLOADED = "SampleDLed" FINISHED = "Finished" - shared_id = models.CharField(max_length=50, default="", editable=False) - shared_link = models.CharField(max_length=100) - shared_password = models.CharField(max_length=4, blank=True, null=True) + shared_id = models.CharField(max_length=50, default="", blank=True) + shared_link = models.CharField( + max_length=100, + help_text="Link, with or without password", + ) + shared_password = models.CharField( + max_length=4, + blank=True, + null=True, + help_text="Password, if not included in the shared link", + ) status = models.CharField( max_length=12, editable=False, diff --git a/task/utils.py b/task/utils.py index bba64df..1a3d49b 100644 --- a/task/utils.py +++ b/task/utils.py @@ -55,7 +55,7 @@ def parse_shared_link(url: str) -> str: >>> parse_shared_link('https://test.com/xyb') Traceback (most recent call last): ... - ValueError: The shared url is not a valid url. https://test.com/xyb + ValueError: The shared url is invalid: https://test.com/xyb """ pwd = get_url_query(url, "pwd") or "" @@ -72,7 +72,7 @@ def parse_shared_link(url: str) -> str: if m: return dict(id="1" + m.group(1), password=pwd) - raise ValueError(f"The shared url is not a valid url. {url}") + raise ValueError(f"The shared url is invalid: {url}") def unify_shared_link(url): diff --git a/ui/forms.py b/ui/forms.py index fa27183..3ee712d 100644 --- a/ui/forms.py +++ b/ui/forms.py @@ -1,14 +1,33 @@ from django import forms from task.models import Task +from task.utils import parse_shared_link -class TaskForm(forms.ModelForm): +class NewTaskForm(forms.ModelForm): class Meta: model = Task - fields = ["shared_link", "shared_password", "full_download_now"] + fields = ["shared_link", "shared_id", "shared_password", "full_download_now"] widgets = { - "shared_link": forms.TextInput(attrs={"class": "form-control"}), - "shared_password": forms.TextInput(attrs={"class": "form-control"}), + "shared_link": forms.TextInput( + attrs={"class": "input input-bordered w-full max-w-xxs"}, + ), + "shared_password": forms.TextInput( + attrs={"class": "input input-bordered w-full max-w-xxs"}, + ), "full_download_now": forms.TextInput(attrs={"class": "form-control"}), } + + def clean(self): + cleaned_data = super().clean() + shared_link = cleaned_data.get("shared_link") + if not shared_link: + return cleaned_data + try: + link = parse_shared_link(shared_link) + except ValueError as e: + self.add_error("shared_link", str(e)) + return cleaned_data + cleaned_data["shared_id"] = link["id"] + if not cleaned_data["shared_password"] and link["password"]: + cleaned_data["shared_password"] = link["password"] diff --git a/ui/templates/ui/base.html b/ui/templates/ui/base.html index a76d06b..b8733dc 100644 --- a/ui/templates/ui/base.html +++ b/ui/templates/ui/base.html @@ -7,14 +7,19 @@ {% load static %} - - + {% comment %} + + + {% endcomment %} + + + -
-