You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
# coding: utf-8
|
|
# Author: Grizzly
|
|
#
|
|
# Views for litl.
|
|
|
|
from django.shortcuts import render
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from .settings import TEMPLATES
|
|
from .models import Slug
|
|
from .forms import SlugAddForm
|
|
|
|
import random, string
|
|
ensemble = string.ascii_letters + string.digits
|
|
|
|
def index(request):
|
|
"""Display the home page of the site.
|
|
TODO: Search and display the urls shortened by the user in the past.
|
|
"""
|
|
context = {}
|
|
return render(request,'base.html',context)
|
|
|
|
def AddSlug(request):
|
|
"""Display the form for creating a new slug.
|
|
"""
|
|
if request.method == 'POST':
|
|
form = SlugAddForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
slug = form.save(commit=False)
|
|
if slug.slug == '':
|
|
slug.slug = ''.join(random.choice(ensemble) for _ in range(5))
|
|
|
|
slug.uid = ''.join(random.choice(ensemble) for _ in range(20))
|
|
|
|
slug.save()
|
|
|
|
return HttpResponseRedirect('')
|
|
else:
|
|
form = SlugAddForm()
|
|
|
|
return render(request,'add_slug.html',{'form':form})
|
|
|