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 ...@@ -10,7 +10,6 @@ venv
/go/settings/secret.py /go/settings/secret.py
/go/static/admin /go/static/admin
/go/media /go/media
/go/go/migrations
.coverage .coverage
htmlcov/ htmlcov/
.idea .idea
......
...@@ -3,6 +3,7 @@ version: "3" ...@@ -3,6 +3,7 @@ version: "3"
services: services:
db: db:
image: mysql:5.7 image: mysql:5.7
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
ports: ports:
- "3306:3306" - "3306:3306"
environment: environment:
......
...@@ -147,7 +147,14 @@ class URL(models.Model): ...@@ -147,7 +147,14 @@ class URL(models.Model):
help_text="" 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, max_length=20,
unique=True, unique=True,
help_text="" help_text=""
...@@ -160,7 +167,7 @@ class URL(models.Model): ...@@ -160,7 +167,7 @@ class URL(models.Model):
def __str__(self): def __str__(self):
return '<Owner: %s - Target URL: %s>' % ( return '<Owner: %s - Target URL: %s>' % (
self.owner.user, self.target self.owner.user, self.destination
) )
class Meta: class Meta:
......
...@@ -486,10 +486,10 @@ def redirection(request, short): ...@@ -486,10 +486,10 @@ def redirection(request, short):
# Get the URL short link # Get the URL short link
doesExist = URL.objects.get(short__iexact=short) doesExist = URL.objects.get(short__iexact=short)
# Checks to see if the link exists, if not we 404 the user. # 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') return redirect('go/404.html')
# If the user is trying to make a Go link to itself, we 404 them # 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') return redirect('404.html')
# If the user is coming from a QR request then increment qrclicks # If the user is coming from a QR request then increment qrclicks
...@@ -502,7 +502,7 @@ def redirection(request, short): ...@@ -502,7 +502,7 @@ def redirection(request, short):
# Save our data and redirect the user towards their destination # Save our data and redirect the user towards their destination
url.save() url.save()
return redirect(url.target) return redirect(url.destination)
def staff_member_required(view_func, redirect_field_name=REDIRECT_FIELD_NAME, login_url='/'): def staff_member_required(view_func, redirect_field_name=REDIRECT_FIELD_NAME, login_url='/'):
......
...@@ -80,6 +80,7 @@ DATABASES = { ...@@ -80,6 +80,7 @@ DATABASES = {
'PASSWORD': os.environ['GO_DB_PASSWORD'], 'PASSWORD': os.environ['GO_DB_PASSWORD'],
'HOST': os.environ['GO_DB_HOST'], 'HOST': os.environ['GO_DB_HOST'],
'PORT': os.environ['GO_DB_PORT'], '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. ...@@ -5,7 +5,7 @@ The URLs of the project and their associated view that requests are routed to.
""" """
# Django Imports # Django Imports
import django.contrib.auth.views import django.contrib.auth.views
from django.urls import path from django.urls import path, re_path
from django.contrib import admin from django.contrib import admin
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_page
from django.views.generic import TemplateView from django.views.generic import TemplateView
...@@ -26,7 +26,8 @@ urlpatterns = [ ...@@ -26,7 +26,8 @@ urlpatterns = [
path('view/<slug:short>', cache_page(60 * 15)(go.views.view), name='view'), path('view/<slug:short>', cache_page(60 * 15)(go.views.view), name='view'),
# /about - About page. Cached for 15 minutes # /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 # /signup - Signup page for access. Cached for 15 minutes
path('signup', cache_page(60 * 15)(go.views.signup), name='signup'), path('signup', cache_page(60 * 15)(go.views.signup), name='signup'),
...@@ -44,7 +45,8 @@ urlpatterns = [ ...@@ -44,7 +45,8 @@ urlpatterns = [
path('delete/<slug:short>', go.views.delete, name='delete'), path('delete/<slug:short>', go.views.delete, name='delete'),
# /registered - registration complete page. Cached for 15 minutes # /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. # /admin - Administrator interface.
path('admin', admin.site.urls, name='go_admin'), path('admin', admin.site.urls, name='go_admin'),
...@@ -54,8 +56,10 @@ urlpatterns = [ ...@@ -54,8 +56,10 @@ urlpatterns = [
# Authentication URLs # Authentication URLs
path('login', django.contrib.auth.views.login, name='go_login'), 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. # 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