diff --git a/README.md b/README.md index f9ebdec..1504a63 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # litl -The world: Here is a free open source full-featured self-hosted URL shortener. - -Grizzly: *choke on PHP* I can do better! +The World: Here is a free open source full-featured self-hosted URL shortener. +Grizzly: I can do better! ## Description @@ -18,4 +17,4 @@ Litl est un racourcisseur d'URL qui vise à être simple d'utilisation, simple Idée de fonctionalité non essentielles: - * Permetre la création de *bulk URL*. On enregistre plusieurs url dans une seule url racourcie. Utiliser cette url racourcie réouvre toutes les urls dans différents onglets. \ No newline at end of file + * Permetre la création de *bulk URL*. On enregistre plusieurs url dans une seule url racourcie. Utiliser cette url racourcie réouvre toutes les urls dans différents onglets. diff --git a/litl/forms.py b/litl/forms.py index d4a9749..14a310a 100644 --- a/litl/forms.py +++ b/litl/forms.py @@ -9,13 +9,14 @@ from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit from .models import Slug -class SlugAddForm(forms.ModelForm): - class Meta: - model = Slug - fields = ('destination','slug') +class SlugAddForm(forms.Form): + + destination = forms.CharField(label="Destination", max_length=300,required=True) + slug = forms.CharField(label="Slug", max_length=20,required=False) + bulk = forms.BooleanField(label="Bulk", required=False) - def __init__(self,*args,**kwargs): - super().__init__(*args,**kwargs) + def __init__(self, *args, **kwargs): + super(SlugAddForm, self).__init__(*args, **kwargs) self.helper = FormHelper() - self.helper.form_method = 'post' - self.helper.add_input(Submit('submit','Shorten')) + self.helper.add_input(Submit('submit', 'Shorten', css_class='btn-primary')) + self.helper.form_method = 'POST' diff --git a/litl/migrations/0004_auto_20210101_2227.py b/litl/migrations/0004_auto_20210101_2227.py new file mode 100644 index 0000000..fdc8665 --- /dev/null +++ b/litl/migrations/0004_auto_20210101_2227.py @@ -0,0 +1,31 @@ +# Generated by Django 3.1.4 on 2021-01-01 22:27 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('litl', '0003_auto_20210101_1203'), + ] + + operations = [ + migrations.RemoveField( + model_name='slug', + name='destination', + ), + migrations.AddField( + model_name='slug', + name='bulk', + field=models.BooleanField(default=False, help_text='Generate a short URL leading to multiple destinations'), + ), + migrations.CreateModel( + name='Destination', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('destination', models.CharField(help_text='The destination URL, limited to 300 characters.', max_length=300)), + ('slug', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='litl.slug')), + ], + ), + ] diff --git a/litl/models.py b/litl/models.py index 83f1bea..d5773e8 100644 --- a/litl/models.py +++ b/litl/models.py @@ -7,17 +7,21 @@ from django.db import models class Slug(models.Model): + """Model of a slug. The slug represent the URL that leads to litl.*.*/slug + A slug has one user and can have from one to many destination. + """ slug = models.SlugField( max_length=20, null=False, blank=True, - help_text="Slug of the new URL. Up to 20 caracters including letters, number, underscores and hyphens.",) - destination = models.CharField( - max_length=300, - null=False, - blank=False, - help_text="The destination URL, limited to 300 characters.",) + help_text="Slug of the new URL. Up to 20 caracters including letters, number, underscores and hyphens.", ) + + bulk = models.BooleanField( + default=False, + help_text="Generate a short URL leading to multiple destinations", + ) + uid = models.CharField( max_length=100, null=True,) @@ -25,6 +29,17 @@ class Slug(models.Model): auto_now=True,) def __str__(self): - return '{} -> {:.15}...'.format(self.slug,self.destination) + return '{} -> ?'.format(self.slug) +class Destination(models.Model): + """Model of a destination. A destination is the end URL wanted by the user. + One Slug can have multiple destinations. + """ + slug = models.ForeignKey(Slug, on_delete=models.CASCADE) + + destination = models.CharField( + max_length=300, + null=False, + blank=False, + help_text="The destination URL, limited to 300 characters.",) diff --git a/litl/templates/add_slug.html b/litl/templates/add_slug.html index 830674b..7b25b72 100644 --- a/litl/templates/add_slug.html +++ b/litl/templates/add_slug.html @@ -3,5 +3,19 @@ {% load crispy_forms_tags %} {% block content %} + {% if form.errors %} + {% for field in form %} + {% for error in field.errors %} +