Commit 2edec6ef authored by David Haynes's avatar David Haynes 🙆

Merge branch '149-emoji' into 'go-three'

Resolve "Support Unicode Shortlinks"

See merge request !119
parents 0e510eb0 c63b32fc
Pipeline #2495 passed with stage
in 1 minute and 27 seconds
...@@ -30,8 +30,8 @@ class URLForm(ModelForm): ...@@ -30,8 +30,8 @@ class URLForm(ModelForm):
Define custom fields and then render them onto the template. Define custom fields and then render them onto the template.
""" """
# target ------------------------------------------------------------------ # destination ------------------------------------------------------------------
target = URLField( destination = URLField(
required=True, required=True,
label='Long URL (Required)', label='Long URL (Required)',
max_length=1000, max_length=1000,
...@@ -55,7 +55,7 @@ class URLForm(ModelForm): ...@@ -55,7 +55,7 @@ class URLForm(ModelForm):
# then raise a ValidationError # then raise a ValidationError
raise ValidationError('Short url already exists.') raise ValidationError('Short url already exists.')
short = SlugField( short = CharField(
required=False, required=False,
label='Short URL (Optional)', label='Short URL (Optional)',
widget=TextInput(), widget=TextInput(),
...@@ -134,7 +134,7 @@ class URLForm(ModelForm): ...@@ -134,7 +134,7 @@ class URLForm(ModelForm):
HTML(""" HTML("""
<h4>Paste the URL you would like to shorten:</h4> <h4>Paste the URL you would like to shorten:</h4>
<br />"""), <br />"""),
'target', 'destination',
style="background: rgb(#F6F6F6);"), style="background: rgb(#F6F6F6);"),
active=True, active=True,
template='crispy/accordian-group.html'), template='crispy/accordian-group.html'),
...@@ -177,7 +177,7 @@ class URLForm(ModelForm): ...@@ -177,7 +177,7 @@ class URLForm(ModelForm):
# what model this form is for # what model this form is for
model = URL model = URL
# what attributes are included # what attributes are included
fields = ['target'] fields = ['destination']
class EditForm(URLForm): class EditForm(URLForm):
...@@ -215,7 +215,7 @@ class EditForm(URLForm): ...@@ -215,7 +215,7 @@ class EditForm(URLForm):
HTML(""" HTML("""
<h4>Modify the URL you would like to shorten:</h4> <h4>Modify the URL you would like to shorten:</h4>
<br />"""), <br />"""),
'target', 'destination',
style="background: rgb(#F6F6F6);"), style="background: rgb(#F6F6F6);"),
active=True, active=True,
template='crispy/accordian-group.html'), template='crispy/accordian-group.html'),
......
...@@ -166,7 +166,7 @@ class URL(models.Model): ...@@ -166,7 +166,7 @@ class URL(models.Model):
socialclicks = models.IntegerField(default=0, help_text="") socialclicks = models.IntegerField(default=0, help_text="")
def __str__(self): def __str__(self):
return '<Owner: %s - Target URL: %s>' % ( return '<Owner: %s - destination URL: %s>' % (
self.owner.user, self.destination self.owner.user, self.destination
) )
......
...@@ -34,7 +34,7 @@ class URLFormTest(TestCase): ...@@ -34,7 +34,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data. Test that form fields are validated correctly given valid data.
""" """
form_data = { form_data = {
'target': 'https://srct.gmu.edu', 'destination': 'https://srct.gmu.edu',
'short': 'pls', 'short': 'pls',
'expires': '1 Day', 'expires': '1 Day',
'expires_custom': '' 'expires_custom': ''
...@@ -49,7 +49,7 @@ class URLFormTest(TestCase): ...@@ -49,7 +49,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data. Test that form fields are validated correctly given valid data.
""" """
form_data = { form_data = {
'target': 'https://srct.gmu.edu', 'destination': 'https://srct.gmu.edu',
'short': 'pls', 'short': 'pls',
'expires': 'Custom Date', 'expires': 'Custom Date',
'expires_custom': datetime.now() + timedelta(days=1) 'expires_custom': datetime.now() + timedelta(days=1)
...@@ -59,12 +59,12 @@ class URLFormTest(TestCase): ...@@ -59,12 +59,12 @@ class URLFormTest(TestCase):
print(form.errors) print(form.errors)
self.assertTrue(form.is_valid()) self.assertTrue(form.is_valid())
def test_invalid_target(self): def test_invalid_destination(self):
""" """
Test that form fields are validated correctly given valid data. Test that form fields are validated correctly given valid data.
""" """
form_data = { form_data = {
'target': '.gmu.edu', 'destination': '.gmu.edu',
'short': 'pls', 'short': 'pls',
'expires': '1 Day', 'expires': '1 Day',
'expires_custom': '' 'expires_custom': ''
...@@ -79,7 +79,7 @@ class URLFormTest(TestCase): ...@@ -79,7 +79,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data. Test that form fields are validated correctly given valid data.
""" """
form_data = { form_data = {
'target': 'https://srct.gmu.edu', 'destination': 'https://srct.gmu.edu',
'short': 'test', 'short': 'test',
'expires': '1 Day', 'expires': '1 Day',
'expires_custom': '' 'expires_custom': ''
...@@ -94,7 +94,7 @@ class URLFormTest(TestCase): ...@@ -94,7 +94,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data. Test that form fields are validated correctly given valid data.
""" """
form_data = { form_data = {
'target': 'https://srct.gmu.edu', 'destination': 'https://srct.gmu.edu',
'short': 'pls', 'short': 'pls',
'expires': 'None', 'expires': 'None',
'expires_custom': '' 'expires_custom': ''
...@@ -109,7 +109,7 @@ class URLFormTest(TestCase): ...@@ -109,7 +109,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data. Test that form fields are validated correctly given valid data.
""" """
form_data = { form_data = {
'target': 'https://srct.gmu.edu', 'destination': 'https://srct.gmu.edu',
'short': 'pls', 'short': 'pls',
'expires': 'Custom Date', 'expires': 'Custom Date',
'expires_custom': datetime.now() - timedelta(days=1) 'expires_custom': datetime.now() - timedelta(days=1)
......
...@@ -243,10 +243,10 @@ class URLTest(TestCase): ...@@ -243,10 +243,10 @@ class URLTest(TestCase):
self.assertEqual(current_url.date_created, now) self.assertEqual(current_url.date_created, now)
# target ------------------------------------------------------------------ # destination ------------------------------------------------------------------
def test_target(self): def test_destination(self):
""" """
Test that the target field properly accepts a URL Test that the destination field properly accepts a URL
""" """
# Get a URL # Get a URL
test_url = "https://dhaynes.xyz" test_url = "https://dhaynes.xyz"
...@@ -257,12 +257,12 @@ class URLTest(TestCase): ...@@ -257,12 +257,12 @@ class URLTest(TestCase):
current_url = URL.objects.get(owner=get_registered_user) current_url = URL.objects.get(owner=get_registered_user)
# Apply the URL # Apply the URL
current_url.target = test_url current_url.destination = test_url
current_url.save() current_url.save()
self.assertEqual(current_url.target, test_url) self.assertEqual(current_url.destination, test_url)
def test_target_length(self): def test_destination_length(self):
""" """
Test that we can't input a URL longer than 1000 chars Test that we can't input a URL longer than 1000 chars
""" """
...@@ -275,7 +275,7 @@ class URLTest(TestCase): ...@@ -275,7 +275,7 @@ class URLTest(TestCase):
current_url = URL.objects.get(owner=get_registered_user) current_url = URL.objects.get(owner=get_registered_user)
# Apply the URL # Apply the URL
current_url.target = test_url current_url.destination = test_url
try: try:
current_url.save() current_url.save()
...@@ -420,9 +420,9 @@ class URLTest(TestCase): ...@@ -420,9 +420,9 @@ class URLTest(TestCase):
# get_registered_user = RegisteredUser.objects.get(user=get_user) # get_registered_user = RegisteredUser.objects.get(user=get_user)
# current_url = URL.objects.get(owner=get_registered_user) # current_url = URL.objects.get(owner=get_registered_user)
# current_url.target = "https://dhaynes.xyz" # current_url.destination = "https://dhaynes.xyz"
# current_url.save() # current_url.save()
# expected = '<Owner: dhaynes - Target URL: https://dhaynes.xyz>' # expected = '<Owner: dhaynes - destination URL: https://dhaynes.xyz>'
# actual = str(current_url) # actual = str(current_url)
# self.assertEqual(expected, actual) TODO # self.assertEqual(expected, actual) TODO
...@@ -135,7 +135,7 @@ class RedirectionTest(TestCase): ...@@ -135,7 +135,7 @@ class RedirectionTest(TestCase):
User.objects.create(username='dhaynes', password='password') User.objects.create(username='dhaynes', password='password')
get_user = User.objects.get(username='dhaynes') get_user = User.objects.get(username='dhaynes')
get_registered_user = RegisteredUser.objects.get(user=get_user) get_registered_user = RegisteredUser.objects.get(user=get_user)
URL.objects.create(owner=get_registered_user, short='test', target='https://srct.gmu.edu') URL.objects.create(owner=get_registered_user, short='test', destination='https://srct.gmu.edu')
# def test_redirect_get_anon(self): # def test_redirect_get_anon(self):
# """ # """
......
...@@ -275,9 +275,9 @@ def edit(request, short): ...@@ -275,9 +275,9 @@ def edit(request, short):
# The short was not edited and thus, we can directly edit the url # The short was not edited and thus, we can directly edit the url
else: else:
if url_form.cleaned_data.get('target').strip() != copy.target: if url_form.cleaned_data.get('destination').strip() != copy.destination:
copy.target = url_form.cleaned_data.get( copy.destination = url_form.cleaned_data.get(
'target').strip() 'destination').strip()
copy.save() copy.save()
# Grab the expiration field value. It's currently an unsable # Grab the expiration field value. It's currently an unsable
...@@ -316,7 +316,7 @@ def edit(request, short): ...@@ -316,7 +316,7 @@ def edit(request, short):
if url.expires != None: if url.expires != None:
# Initialize a URL form with an expire date # Initialize a URL form with an expire date
url_form = EditForm(host=request.META.get('HTTP_HOST'), initial={ url_form = EditForm(host=request.META.get('HTTP_HOST'), initial={
'target': url.target, 'destination': url.destination,
'short': url.short, 'short': url.short,
'expires': 'Custom Date', 'expires': 'Custom Date',
'expires_custom': url.expires 'expires_custom': url.expires
...@@ -324,7 +324,7 @@ def edit(request, short): ...@@ -324,7 +324,7 @@ def edit(request, short):
else: else:
# Initialize a URL form without an expire date # Initialize a URL form without an expire date
url_form = EditForm(host=request.META.get('HTTP_HOST'), initial={ url_form = EditForm(host=request.META.get('HTTP_HOST'), initial={
'target': url.target, 'destination': url.destination,
'short': url.short, 'short': url.short,
'expires': 'Never', 'expires': 'Never',
}) # unbound form }) # unbound form
......
...@@ -23,7 +23,10 @@ urlpatterns = [ ...@@ -23,7 +23,10 @@ urlpatterns = [
path('', cache_page(1)(go.views.index), name='index'), path('', cache_page(1)(go.views.index), name='index'),
# /view/<short> - View URL data. Cached for 15 minutes # /view/<short> - View URL data. Cached for 15 minutes
path('view/<slug:short>', cache_page(60 * 15)(go.views.view), name='view'), re_path(r'^view/(?P<short>([\U00010000-\U0010ffff][\U0000200D]?)+)$',
cache_page(60 * 15)(go.views.view), name='view'),
re_path(r'^view/(?P<short>[-\w]+)$',
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) path('about', cache_page(60 * 15)
...@@ -62,4 +65,6 @@ urlpatterns = [ ...@@ -62,4 +65,6 @@ urlpatterns = [
# Redirection regex. # Redirection regex.
re_path(r'^(?P<short>([\U00010000-\U0010ffff][\U0000200D]?)+)$', re_path(r'^(?P<short>([\U00010000-\U0010ffff][\U0000200D]?)+)$',
go.views.redirection, name='redirection'), go.views.redirection, name='redirection'),
re_path(r'^(?P<short>[-\w]+)$',
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