Commit 70f16263 authored by David Haynes's avatar David Haynes 🙆

Add emoji support for short

- support for the entire range as well as multiple
character emojis

- right now, urls.py only accepts emoji. I need to
go in and modify the regex to support the old way and
the new

Closes #149
parent 7b84fb10
Pipeline #2460 failed with stages
in 1 minute and 11 seconds
......@@ -10,7 +10,6 @@ venv
/go/settings/secret.py
/go/static/admin
/go/media
/go/go/migrations
.coverage
htmlcov/
.idea
......
......@@ -3,6 +3,7 @@ version: "3"
services:
db:
image: mysql:5.7
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
ports:
- "3306:3306"
environment:
......
......@@ -147,7 +147,14 @@ class URL(models.Model):
help_text=""
)
short = models.SlugField(
# TODO Validator for Slug + Emoji
"""
# http://stackoverflow.com/a/13752628/6762004
RE_EMOJI = re.compile('[\U00010000-\U0010ffff]', flags=re.UNICODE)
slug_unicode_re = _lazy_re_compile(r'^[-\w]+\Z')
slug_re = _lazy_re_compile(r'^[-a-zA-Z0-9_]+\Z')
"""
short = models.CharField(
max_length=20,
unique=True,
help_text=""
......@@ -160,7 +167,7 @@ class URL(models.Model):
def __str__(self):
return '<Owner: %s - Target URL: %s>' % (
self.owner.user, self.target
self.owner.user, self.destination
)
class Meta:
......
......@@ -486,10 +486,10 @@ def redirection(request, short):
# Get the URL short link
doesExist = URL.objects.get(short__iexact=short)
# Checks to see if the link exists, if not we 404 the user.
if doesExist.target is None:
if doesExist.destination is None:
return redirect('go/404.html')
# If the user is trying to make a Go link to itself, we 404 them
if url.target == domain + short:
if url.destination == domain + short:
return redirect('404.html')
# If the user is coming from a QR request then increment qrclicks
......@@ -502,7 +502,7 @@ def redirection(request, short):
# Save our data and redirect the user towards their destination
url.save()
return redirect(url.target)
return redirect(url.destination)
def staff_member_required(view_func, redirect_field_name=REDIRECT_FIELD_NAME, login_url='/'):
......
......@@ -80,6 +80,7 @@ DATABASES = {
'PASSWORD': os.environ['GO_DB_PASSWORD'],
'HOST': os.environ['GO_DB_HOST'],
'PORT': os.environ['GO_DB_PORT'],
'OPTIONS': {'charset': 'utf8mb4'}
}
}
......
......@@ -5,7 +5,7 @@ The URLs of the project and their associated view that requests are routed to.
"""
# Django Imports
import django.contrib.auth.views
from django.urls import path
from django.urls import path, re_path
from django.contrib import admin
from django.views.decorators.cache import cache_page
from django.views.generic import TemplateView
......@@ -26,7 +26,8 @@ urlpatterns = [
path('view/<slug:short>', cache_page(60 * 15)(go.views.view), name='view'),
# /about - About page. Cached for 15 minutes
path('about',cache_page(60 * 15)(TemplateView.as_view(template_name='core/about.html')), name='about'),
path('about', cache_page(60 * 15)
(TemplateView.as_view(template_name='core/about.html')), name='about'),
# /signup - Signup page for access. Cached for 15 minutes
path('signup', cache_page(60 * 15)(go.views.signup), name='signup'),
......@@ -44,7 +45,8 @@ urlpatterns = [
path('delete/<slug:short>', go.views.delete, name='delete'),
# /registered - registration complete page. Cached for 15 minutes
path('registered', cache_page(60 * 15)(TemplateView.as_view(template_name='registered.html')), name='registered'),
path('registered', cache_page(60 * 15)
(TemplateView.as_view(template_name='registered.html')), name='registered'),
# /admin - Administrator interface.
path('admin', admin.site.urls, name='go_admin'),
......@@ -54,8 +56,10 @@ urlpatterns = [
# Authentication URLs
path('login', django.contrib.auth.views.login, name='go_login'),
path('logout', django.contrib.auth.views.logout, {'next_page': '/'}, name='go_logout'),
path('logout', django.contrib.auth.views.logout,
{'next_page': '/'}, name='go_logout'),
# Redirection regex.
path('<slug:short>', go.views.redirection, name='redirection'),
re_path(r'^(?P<short>([\U00010000-\U0010ffff][\U0000200D]?)+)$',
go.views.redirection, name='redirection'),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment