diff --git a/litl/admin.py b/litl/admin.py index d0b6dc3..0dd0cb3 100644 --- a/litl/admin.py +++ b/litl/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin -from .models import Slug +from .models import Slug, Destination admin.site.register(Slug) +admin.site.register(Destination) diff --git a/litl/forms.py b/litl/forms.py index 14a310a..7f426c1 100644 --- a/litl/forms.py +++ b/litl/forms.py @@ -11,9 +11,8 @@ from .models import Slug class SlugAddForm(forms.Form): - destination = forms.CharField(label="Destination", max_length=300,required=True) + destination = forms.CharField(label="Destination(s) ", max_length=300,required=True,widget=forms.Textarea(attrs={"rows":3})) slug = forms.CharField(label="Slug", max_length=20,required=False) - bulk = forms.BooleanField(label="Bulk", required=False) def __init__(self, *args, **kwargs): super(SlugAddForm, self).__init__(*args, **kwargs) diff --git a/litl/models.py b/litl/models.py index d5773e8..28977f1 100644 --- a/litl/models.py +++ b/litl/models.py @@ -16,11 +16,6 @@ class Slug(models.Model): null=False, blank=True, 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, diff --git a/litl/templates/base.html b/litl/templates/base.html index 60aff06..d5315fc 100644 --- a/litl/templates/base.html +++ b/litl/templates/base.html @@ -61,10 +61,10 @@ Code
- Bulk URLs + Surjectiv URLs
- You can bulk multiple destinations under the same shorten URL. Just + You can pack multiple destinations under the same shorten URL. Just for the 0.01% that needed that feature.
diff --git a/litl/templates/multirect.html b/litl/templates/multirect.html new file mode 100644 index 0000000..b752d64 --- /dev/null +++ b/litl/templates/multirect.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} + +{% block content %} + +
+

Redirecting...

+ +If nothing happens, verify that Javascript is enabled in your browser and authorise it to open links and popups. +
+ + + +{% endblock %} diff --git a/litl/views.py b/litl/views.py index 0c94b42..a30eb6f 100644 --- a/litl/views.py +++ b/litl/views.py @@ -31,9 +31,9 @@ def AddSlug(request): # Add slug if needed if form.cleaned_data['slug'] == '': rand_slug = ''.join(random.choice(ensemble) for _ in range(RANDOM_SLUG_LEN)) - while Slug.object.filter(slug = rand_slug).exists(): - rand_string = ''.join(random.choice(ensemble) for _ in range(RANDOM_SLUG_LEN)) - form.cleaned_data['slug'] = rand_string + while Slug.objects.filter(slug = rand_slug).exists(): + rand_slug = ''.join(random.choice(ensemble) for _ in range(RANDOM_SLUG_LEN)) + form.cleaned_data['slug'] = rand_slug else: # If slug added by the user, check uniqueness if Slug.objects.filter(slug=form.cleaned_data['slug']).exists(): @@ -46,13 +46,13 @@ def AddSlug(request): rand_uid = ''.join(random.choice(ensemble) for _ in range(UID_LEN)) slug = Slug(slug = form.cleaned_data['slug'], - uid = rand_uid, - bulk = form.cleaned_data['bulk'],) + uid = rand_uid,) slug.save() - - destination = Destination(slug = slug, - destination = form.cleaned_data['destination'],) - destination.save() + + for dest in form.cleaned_data['destination'].split('\r\n'): + destination = Destination(slug = slug, + destination = dest,) + destination.save() return HttpResponseRedirect('display/{}'.format(slug.slug)) else: @@ -78,5 +78,7 @@ def redirect(request,slug_got): return render(request,'unknown.html',context) else: destinations = Destination.objects.filter(slug=slug.get()).all() - return HttpResponsePermanentRedirect(destinations.first().destination) - + if destinations.count() == 1: + return HttpResponsePermanentRedirect(destinations.get().destination) + elif destinations.count()>1: + return render(request,'multirect.html',{'destinations':destinations})