diff --git a/go/go/forms.py b/go/go/forms.py
index 9ec4b1b3e07a99ff2723e954e67226b6ec6853c6..001a817ac794b99ab5cceec8b6a77f3bfe7a837b 100644
--- a/go/go/forms.py
+++ b/go/go/forms.py
@@ -30,8 +30,8 @@ class URLForm(ModelForm):
Define custom fields and then render them onto the template.
"""
- # target ------------------------------------------------------------------
- target = URLField(
+ # destination ------------------------------------------------------------------
+ destination = URLField(
required=True,
label='Long URL (Required)',
max_length=1000,
@@ -55,7 +55,7 @@ class URLForm(ModelForm):
# then raise a ValidationError
raise ValidationError('Short url already exists.')
- short = SlugField(
+ short = CharField(
required=False,
label='Short URL (Optional)',
widget=TextInput(),
@@ -134,7 +134,7 @@ class URLForm(ModelForm):
HTML("""
Paste the URL you would like to shorten:
"""),
- 'target',
+ 'destination',
style="background: rgb(#F6F6F6);"),
active=True,
template='crispy/accordian-group.html'),
@@ -177,7 +177,7 @@ class URLForm(ModelForm):
# what model this form is for
model = URL
# what attributes are included
- fields = ['target']
+ fields = ['destination']
class EditForm(URLForm):
@@ -215,7 +215,7 @@ class EditForm(URLForm):
HTML("""
Modify the URL you would like to shorten:
"""),
- 'target',
+ 'destination',
style="background: rgb(#F6F6F6);"),
active=True,
template='crispy/accordian-group.html'),
diff --git a/go/go/models.py b/go/go/models.py
index c11e4cd05705bf835ad3bfd6e761119280c7d335..e66ac2d1863d0bc5a49bd56700db5f43d5e643ae 100644
--- a/go/go/models.py
+++ b/go/go/models.py
@@ -166,7 +166,7 @@ class URL(models.Model):
socialclicks = models.IntegerField(default=0, help_text="")
def __str__(self):
- return '' % (
+ return '' % (
self.owner.user, self.destination
)
diff --git a/go/go/test_forms.py b/go/go/test_forms.py
index 7b99d7b8f4296000e5ebefa467e0bd2045645b0a..c96b6c8de64d95832edbd900e7b92a2f4d841ae9 100644
--- a/go/go/test_forms.py
+++ b/go/go/test_forms.py
@@ -34,7 +34,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data.
"""
form_data = {
- 'target': 'https://srct.gmu.edu',
+ 'destination': 'https://srct.gmu.edu',
'short': 'pls',
'expires': '1 Day',
'expires_custom': ''
@@ -49,7 +49,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data.
"""
form_data = {
- 'target': 'https://srct.gmu.edu',
+ 'destination': 'https://srct.gmu.edu',
'short': 'pls',
'expires': 'Custom Date',
'expires_custom': datetime.now() + timedelta(days=1)
@@ -59,12 +59,12 @@ class URLFormTest(TestCase):
print(form.errors)
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.
"""
form_data = {
- 'target': '.gmu.edu',
+ 'destination': '.gmu.edu',
'short': 'pls',
'expires': '1 Day',
'expires_custom': ''
@@ -79,7 +79,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data.
"""
form_data = {
- 'target': 'https://srct.gmu.edu',
+ 'destination': 'https://srct.gmu.edu',
'short': 'test',
'expires': '1 Day',
'expires_custom': ''
@@ -94,7 +94,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data.
"""
form_data = {
- 'target': 'https://srct.gmu.edu',
+ 'destination': 'https://srct.gmu.edu',
'short': 'pls',
'expires': 'None',
'expires_custom': ''
@@ -109,7 +109,7 @@ class URLFormTest(TestCase):
Test that form fields are validated correctly given valid data.
"""
form_data = {
- 'target': 'https://srct.gmu.edu',
+ 'destination': 'https://srct.gmu.edu',
'short': 'pls',
'expires': 'Custom Date',
'expires_custom': datetime.now() - timedelta(days=1)
diff --git a/go/go/test_models.py b/go/go/test_models.py
index 4a2c059099ff0fc75dde86bc9f9e0d420935eb6e..348a7ab31b9cfc2a17872fa347779ad752ce7064 100644
--- a/go/go/test_models.py
+++ b/go/go/test_models.py
@@ -243,10 +243,10 @@ class URLTest(TestCase):
self.assertEqual(current_url.date_created, now)
- # target ------------------------------------------------------------------
- def test_target(self):
+ # destination ------------------------------------------------------------------
+ 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
test_url = "https://dhaynes.xyz"
@@ -257,12 +257,12 @@ class URLTest(TestCase):
current_url = URL.objects.get(owner=get_registered_user)
# Apply the URL
- current_url.target = test_url
+ current_url.destination = test_url
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
"""
@@ -275,7 +275,7 @@ class URLTest(TestCase):
current_url = URL.objects.get(owner=get_registered_user)
# Apply the URL
- current_url.target = test_url
+ current_url.destination = test_url
try:
current_url.save()
@@ -420,9 +420,9 @@ class URLTest(TestCase):
# get_registered_user = RegisteredUser.objects.get(user=get_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()
- # expected = ''
+ # expected = ''
# actual = str(current_url)
# self.assertEqual(expected, actual) TODO
diff --git a/go/go/test_views.py b/go/go/test_views.py
index 78313ad66ddc04d86d1dc5c619443a189019f2ec..48b1e0235fa101edae3c6ebc3b70919f257addb9 100644
--- a/go/go/test_views.py
+++ b/go/go/test_views.py
@@ -135,7 +135,7 @@ class RedirectionTest(TestCase):
User.objects.create(username='dhaynes', password='password')
get_user = User.objects.get(username='dhaynes')
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):
# """
diff --git a/go/go/views.py b/go/go/views.py
index 764696fdb245699193fe17907ae5ab308e2a8d04..6e10edc67de663a0e15c3ecdb40f482cddd94559 100644
--- a/go/go/views.py
+++ b/go/go/views.py
@@ -275,9 +275,9 @@ def edit(request, short):
# The short was not edited and thus, we can directly edit the url
else:
- if url_form.cleaned_data.get('target').strip() != copy.target:
- copy.target = url_form.cleaned_data.get(
- 'target').strip()
+ if url_form.cleaned_data.get('destination').strip() != copy.destination:
+ copy.destination = url_form.cleaned_data.get(
+ 'destination').strip()
copy.save()
# Grab the expiration field value. It's currently an unsable
@@ -316,7 +316,7 @@ def edit(request, short):
if url.expires != None:
# Initialize a URL form with an expire date
url_form = EditForm(host=request.META.get('HTTP_HOST'), initial={
- 'target': url.target,
+ 'destination': url.destination,
'short': url.short,
'expires': 'Custom Date',
'expires_custom': url.expires
@@ -324,7 +324,7 @@ def edit(request, short):
else:
# Initialize a URL form without an expire date
url_form = EditForm(host=request.META.get('HTTP_HOST'), initial={
- 'target': url.target,
+ 'destination': url.destination,
'short': url.short,
'expires': 'Never',
}) # unbound form
diff --git a/go/settings/urls.py b/go/settings/urls.py
index 1b7058e40bee1d375720320dab8d4c55bf826809..c14f315b08775465ffc48a477305cf1961ac25b4 100644
--- a/go/settings/urls.py
+++ b/go/settings/urls.py
@@ -23,7 +23,10 @@ urlpatterns = [
path('', cache_page(1)(go.views.index), name='index'),
# /view/ - View URL data. Cached for 15 minutes
- path('view/', cache_page(60 * 15)(go.views.view), name='view'),
+ re_path(r'^view/(?P([\U00010000-\U0010ffff][\U0000200D]?)+)$',
+ cache_page(60 * 15)(go.views.view), name='view'),
+ re_path(r'^view/(?P[-\w]+)$',
+ cache_page(60 * 15)(go.views.view), name='view'),
# /about - About page. Cached for 15 minutes
path('about', cache_page(60 * 15)
@@ -62,4 +65,6 @@ urlpatterns = [
# Redirection regex.
re_path(r'^(?P([\U00010000-\U0010ffff][\U0000200D]?)+)$',
go.views.redirection, name='redirection'),
+ re_path(r'^(?P[-\w]+)$',
+ go.views.redirection, name='redirection'),
]