Commit 1d9a6303 authored by David Haynes's avatar David Haynes 🙆
Browse files

Merge branch 'urloverhall' into 'master'

Clean up link detail page plus some other minor things

- see commit notes for specifics

- 'edit' is not functional as of right now, just a placeholder

See merge request !16
parents 69f41c37 f0fe9c1a
from django import forms from django import forms
from go.models import URL, RegisteredUser from go.models import URL, RegisteredUser
from django.core.validators import RegexValidator # MinLengthValidator, MinValueValidator
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from captcha.fields import CaptchaField from captcha.fields import CaptchaField
class URLForm(forms.ModelForm): class URLForm(forms.ModelForm):
# Custom target URL field
target = forms.URLField(
required=True,
label='Long URL',
max_length=1000,
widget=forms.URLInput(attrs={
'placeholder': 'https://'
})
)
# Check to make sure the short url has not been used
def unique_short(value):
try:
URL.objects.get(short__iexact=value)
except URL.DoesNotExist:
return
raise ValidationError('Short url already exists.')
# Custom short-url field with validators.
short = forms.SlugField(
required=False,
label='Short URL (Optional)',
widget=forms.TextInput(),
validators=[unique_short],
max_length=20,
min_length=3,
)
DAY = '1 Day' DAY = '1 Day'
WEEK = '1 Week' WEEK = '1 Week'
MONTH = '1 Month' MONTH = '1 Month'
...@@ -28,36 +55,10 @@ class URLForm(forms.ModelForm): ...@@ -28,36 +55,10 @@ class URLForm(forms.ModelForm):
widget=forms.RadioSelect(), widget=forms.RadioSelect(),
) )
def unique_short(value):
try:
URL.objects.get(short__iexact=value)
except URL.DoesNotExist:
return
raise ValidationError('Short url already exists.')
# Custom short-url field with validators.
short = forms.SlugField(
required=False,
label='Short URL (Optional)',
widget=forms.TextInput(attrs={}),
validators=[unique_short],
max_length=20,
min_length=3,
)
class Meta: class Meta:
model = URL model = URL
fields = ('target',) fields = ('target',)
exclude = ('owner', 'short', 'date_created', 'clicks', 'expires') exclude = ('owner', 'short', 'date_created', 'clicks', 'expires')
labels = {
'target': 'Long URL',
}
widgets = {
'target': forms.URLInput(attrs={
'placeholder': 'http://',
}),
}
class SignupForm(forms.ModelForm): class SignupForm(forms.ModelForm):
......
...@@ -43,7 +43,7 @@ class URL(models.Model): ...@@ -43,7 +43,7 @@ class URL(models.Model):
tries = 1 tries = 1
while tries < 100: while tries < 100:
try: try:
# urls = URL.objects.get(short__iexact=short) urls = URL.objects.get(short__iexact=short)
tries += 1 tries += 1
hashids_counter += 1 hashids_counter += 1
except URL.DoesNotExist: except URL.DoesNotExist:
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
{% block title %} {% block title %}
Go - A URL Shortener Go - A University Branded URL Shortener
{% endblock %} {% endblock %}
......
...@@ -9,36 +9,50 @@ ...@@ -9,36 +9,50 @@
legend { legend {
font-size: inherit; font-size: inherit;
} }
pre {
font-family: inherit;
}
</style> </style>
<div class="container"> <div class="container">
<div class="col-md-8"> <div class="col-md-8">
<strong>Long:</strong> <a href="{{url.target}}">{{url.target}}</a> <h3>Go Address:</h3>
<br /> <a href="{{url.short}}">go.gmu.edu/{{url.short}}</a>
<br></br>
<strong>Short:</strong> <a href="/{{url.short}}">{{url.short}}</a> <h3>Address Details:</h3>
<br /> <strong>Target URL:</strong>
<br />
<a href="{{url.target}}">{{url.target}}</a>
<br />
{% if url.owner = request.user and request.user|is_registered %} {% if url.owner = request.user and request.user|is_registered %}
<strong>Clicks:</strong> {{url.clicks}} <strong>Clicks:</strong>
<br /> {{url.clicks}}
<br />
<strong>QR Code Uses:</strong> {{url.qrclicks}} <strong>QR Code Uses:</strong> {{url.qrclicks}}
<br /> <br />
<strong>Social Clicks:</strong> {{url.socialclicks}} <strong>Social Clicks:</strong> {{url.socialclicks}}
<br /> <br />
<strong>Expires:</strong> {{url.expires|default_if_none:"Never"}} <strong>Expires:</strong> {{url.expires|default_if_none:"Never"}}
<br /> <br></br>
<strong> <strong>
<a href="{%url 'delete' url.short%}" <a href="https://www.google.com">
onclick="return confirm('Are you sure you want to delete this link?');"> Edit
Delete </a>
</a> </strong>
</strong> <br />
{% endif %}
<br></br> <strong>
<a href="{%url 'delete' url.short%}" onclick="return confirm('Are you sure you want to delete this link?');">
Delete
</a>
</strong>
{% endif %}
<br></br>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
...@@ -64,6 +78,15 @@ ...@@ -64,6 +78,15 @@
<i class="fa fa-linkedin-square fa-3x"></i> <i class="fa fa-linkedin-square fa-3x"></i>
</a> </a>
{% endwith %} {% endwith %}
{% with the_url|add:"?qr" as qr_url %}
<pre><strong>QR Downloads:</strong>
<a href="http://chart.googleapis.com/chart?cht=qr&chs=120x120&chl={{ qr_url }}">Small (120x120)</a>
<a href="http://chart.googleapis.com/chart?cht=qr&chs=230x230&chl={{ qr_url }}">Medium (230x230)</a>
<a href="http://chart.googleapis.com/chart?cht=qr&chs=350x350&chl={{ qr_url }}">Large (350x350)</a>
</pre>
{% endwith %}
{% endwith %} {% endwith %}
</div> </div>
</div> </div>
...@@ -117,7 +117,7 @@ def index(request): ...@@ -117,7 +117,7 @@ def index(request):
random_short = URL.generate_valid_short() random_short = URL.generate_valid_short()
if random_short is None: if random_short is None:
return HttpResponseServerError( return HttpResponseServerError(
render(request, 'core/500.html', {}) render(request, '500.html', {})
) )
else: else:
url.short = random_short url.short = random_short
...@@ -213,13 +213,13 @@ def signup(request): ...@@ -213,13 +213,13 @@ def signup(request):
""" """
# Do not display signup page to registered or approved users (Staff can still see these pages) # Do not display signup page to registered or approved users (Staff can still see these pages)
if is_registered(request.user) and not request.user.is_staff: if is_registered(request.user) and not request.user.is_staff:
return render(request, 'signup.html', { return render(request, 'core/signup.html', {
'registered': True, 'registered': True,
'approved': False, 'approved': False,
}, },
) )
elif is_approved(request.user) and not request.user.is_staff: elif is_approved(request.user) and not request.user.is_staff:
return render(request, 'signup.html', { return render(request, 'core/signup.html', {
'registered': True, 'registered': True,
'approved': True, 'approved': True,
}, },
...@@ -258,7 +258,7 @@ def signup(request): ...@@ -258,7 +258,7 @@ def signup(request):
return redirect('registered') return redirect('registered')
return render(request, 'signup.html', { return render(request, 'core/signup.html', {
'form': signup_form, 'form': signup_form,
'registered': False, 'registered': False,
}, },
......
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