Unverified Commit 99da0008 authored by David Haynes's avatar David Haynes
Browse files

Merge branch '2.2-dev' into 43-unittests

parents 5562582f 98bed2aa
Pipeline #849 passed with stage
in 1 minute and 11 seconds
......@@ -11,7 +11,7 @@ variables:
before_script:
- apt-get update -qy
- apt-get install -y libldap2-dev libsasl2-dev mysql-client libmysqlclient-dev python-mysqldb
- pip install -r requirements.txt
- pip install -r requirements/ci.txt
- cd go/
- cp settings/settings.py.template settings/settings.py
- cp settings/secret.py.template settings/secret.py
......@@ -49,6 +49,5 @@ Go-py3.6:
image: library/python:3.6
type: test
script:
- pip install coverage
- coverage run --source=go --omit=*migrations/*,*admin.py,*manage.py,*wsgi.py,*settings.py,*secret.py,*__init__.py,*.pyc,*templates/*,*static/* manage.py test
- coverage html -i && grep pc_cov htmlcov/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
......@@ -8,6 +8,6 @@ RUN apt-get install netcat -y
RUN mkdir /go
WORKDIR /go
ADD requirements.txt /go/
RUN pip install -r requirements.txt
ADD /requirements/ /go/
RUN pip install -r base.txt
ADD . /go/
<!-- include the base html template -->
{% extends 'layouts/base.html' %}
<!-- define the page title block -->
{% block title %}
403 Error &bull; Forbidden
{% endblock %}
<!-- define the content block for the page -->
{% block content %}
<!-- Tell Django to load static files -->
{% load staticfiles %}
<!-- div that contains the 404 page content -->
<div class="row">
<div class="col-md-10 col-md-offset-1 text-center">
<h1>403 Error - Forbidden</h1>
<h3>You are not permitted to access this page, or you have exceeded the maximum limit of submitted links.</h3>
<h3>
Click <a href="{% url 'index' %}">here</a> to return to the home page.
</h3>
<img id="squirrels" src="{% static "img/acorn.png" %}">
<a href="/"><img src="{% static "img/acorn.png" %}" style="width:10vw;"></a>
</div>
</div>
{% endblock %}
......@@ -12,6 +12,7 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import User
from django.contrib.auth.decorators import user_passes_test, login_required
from django.shortcuts import render, get_object_or_404, redirect
from ratelimit.decorators import ratelimit
# App Imports
from go.models import URL, RegisteredUser
......@@ -46,67 +47,73 @@ def index(request):
# If a POST request is received, then the user has submitted a form and it's
# time to parse the form and create a new URL object
if request.method == 'POST':
# Now we initialize the form again but this time we have the POST
# request
url_form = URLForm(request.POST, host = request.META.get('HTTP_HOST'))
return redirect('view', post(request).short)
# Django will check the form to make sure it's valid
if url_form.is_valid():
# Render index.html passing the form to the template
return render(request, 'core/index.html', {
'form': url_form,
},
)
# We don't commit the url object yet because we need to add its
# owner, and parse its date field.
url = url_form.save(commit = False)
url.owner = request.user.registereduser
#rate limits are completely arbitrary
@ratelimit(key='user', rate='3/m', method='POST', block=True)
@ratelimit(key='user', rate='25/d', method='POST', block=True)
def post(request):
# If the user entered a short url, it's already been validated,
# so accept it. If they did not, however, then generate a
# random one and use that instead.
short = url_form.cleaned_data.get('short').strip()
# Now we initialize the form again but this time we have the POST
# request
url_form = URLForm(request.POST, host = request.META.get('HTTP_HOST'))
# Check if a short URL was entered
if len(short) > 0:
url.short = short
else:
# If the user didn't enter a short url, generate a random
# one. However, if a random one can't be generated, return
# a 500 server error.
random_short = URL.generate_valid_short()
if random_short is None:
return HttpResponseServerError(
render(request, 'admin/500.html', {})
)
else:
url.short = random_short
# Grab the expiration field value. It's currently an unsable
# string value, so we need to parse it into a datetime object
# relative to right now.
expires = url_form.cleaned_data.get('expires')
# Determine what the expiration date is
if expires == URLForm.DAY:
url.expires = timezone.now() + timedelta(days = 1)
elif expires == URLForm.WEEK:
url.expires = timezone.now() + timedelta(weeks = 1)
elif expires == URLForm.MONTH:
url.expires = timezone.now() + timedelta(weeks = 3)
elif expires == URLForm.CUSTOM:
url.expires = url_form.cleaned_data.get('expires_custom')
else:
pass # leave the field NULL
# Django will check the form to make sure it's valid
if url_form.is_valid():
# Make sure that our new URL object is clean, then save it and
# let's redirect to view this baby.
url.full_clean()
url.save()
# We don't commit the url object yet because we need to add its
# owner, and parse its date field.
url = url_form.save(commit = False)
url.owner = request.user.registereduser
return redirect('view', url.short)
# If the user entered a short url, it's already been validated,
# so accept it. If they did not, however, then generate a
# random one and use that instead.
short = url_form.cleaned_data.get('short').strip()
# Render index.html passing the form to the template
return render(request, 'core/index.html', {
'form': url_form,
},
)
# Check if a short URL was entered
if len(short) > 0:
url.short = short
else:
# If the user didn't enter a short url, generate a random
# one. However, if a random one can't be generated, return
# a 500 server error.
random_short = URL.generate_valid_short()
if random_short is None:
return HttpResponseServerError(
render(request, 'admin/500.html', {})
)
else:
url.short = random_short
# Grab the expiration field value. It's currently an unsable
# string value, so we need to parse it into a datetime object
# relative to right now.
expires = url_form.cleaned_data.get('expires')
# Determine what the expiration date is
if expires == URLForm.DAY:
url.expires = timezone.now() + timedelta(days = 1)
elif expires == URLForm.WEEK:
url.expires = timezone.now() + timedelta(weeks = 1)
elif expires == URLForm.MONTH:
url.expires = timezone.now() + timedelta(weeks = 3)
elif expires == URLForm.CUSTOM:
url.expires = url_form.cleaned_data.get('expires_custom')
else:
pass # leave the field NULL
# Make sure that our new URL object is clean, then save it and
# let's redirect to view this baby.
url.full_clean()
url.save()
return url
"""
This view allows the user to view details about a URL. Note that they
......
Django==1.10
django-auth-ldap==1.2.8
django-crispy-forms==1.6.0
git+https://github.com/bruno207/django-qrcode.git
flake8==3.0.4
git+https://github.com/kstateome/django-cas.git
git+https://github.com/bruno207/django-bootstrap3-datetimepicker.git
gunicorn==19.6.0
hashids==1.1.0
mccabe==0.5.2
mysqlclient
pep8==1.7.0
Pillow==3.3.0
pyflakes==1.2.3
pyldap
requests==2.11.0
simplejson==3.8.2
wheel==0.29.0
# This file is here because many platforms as a service look for
# requirements.txt in the root directory of a project.
-r requirements/base.txt
Django==1.10
django-auth-ldap==1.2.8
django-crispy-forms==1.6.0
django-ratelimit==1.0.1
git+https://github.com/bruno207/django-qrcode.git
git+https://github.com/kstateome/django-cas.git
git+https://github.com/bruno207/django-bootstrap3-datetimepicker.git
hashids==1.1.0
mysqlclient
pyldap
requests==2.11.0
simplejson==3.8.2
-r base.txt
flake8==3.0.4
pep8==1.7.0
pyflakes==1.2.3
coverage
-r base.txt
flake8==3.0.4
pep8==1.7.0
pyflakes==1.2.3
# Pro-tip: Try not to put anything here. There should be no dependency in
# production that isn't in development.
-r base.txt
gunicorn==19.6.0
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