Commit 21633793 authored by David Haynes's avatar David Haynes 🙆
Browse files

Merge branch 'customDateTime'

- yass :mrodgers:
parents e4a87b0e 25aed936
......@@ -2,6 +2,7 @@
from django import forms
from django.core.exceptions import ValidationError
from django.utils.safestring import mark_safe
from django.utils import timezone
# App Imports
from go.models import URL, RegisteredUser
......@@ -10,6 +11,9 @@ from go.models import URL, RegisteredUser
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, Submit, HTML, Div, Field
from crispy_forms.bootstrap import StrictButton, PrependedText, Accordion, AccordionGroup
from bootstrap3_datetime.widgets import DateTimePicker
import datetime
from datetime import date
class URLForm(forms.ModelForm):
......@@ -52,6 +56,7 @@ class URLForm(forms.ModelForm):
DAY = '1 Day'
WEEK = '1 Week'
MONTH = '1 Month'
CUSTOM = 'Custom Date'
NEVER = 'Never'
EXPIRATION_CHOICES = (
......@@ -59,9 +64,10 @@ class URLForm(forms.ModelForm):
(WEEK, WEEK),
(MONTH, MONTH),
(NEVER, NEVER),
(CUSTOM, CUSTOM),
)
# Add a custom expiration choice field.
# Add preset expiration choices.
expires = forms.ChoiceField(
required=True,
label='Expiration (Required)',
......@@ -70,6 +76,29 @@ class URLForm(forms.ModelForm):
widget=forms.RadioSelect(),
)
def valid_date(value):
if value > timezone.now():
return
else:
raise ValidationError('Date must be after today.')
# Add a custom expiration choice.
expires_custom = forms.DateTimeField(
required = False,
label='Custom Date',
input_formats=['%m-%d-%Y'],
validators=[valid_date],
widget=DateTimePicker(
options={
"format": "MM-DD-YYYY",
"pickTime": False,
"defaultDate": (datetime.date.today() + datetime.timedelta(hours=24)).strftime("%m-%d-%Y"),
},
icon_attrs={
"class": "fa fa-calendar",
})
)
def __init__(self, *args, **kwargs):
# Grab that host info
......@@ -107,7 +136,7 @@ class URLForm(forms.ModelForm):
<h4>Create a custom Go address:</h4>
<br />"""),
PrependedText(
'short', 'https://go.gmu.edu/'),
'short', 'https://go.gmu.edu/', template='crispy/customPrepended.html'),
style="background: rgb(#F6F6F6);"),
active=True,
template='crispy/accordian-group.html',),
......@@ -119,6 +148,7 @@ class URLForm(forms.ModelForm):
<h4>Set when you would like your Go address to expire:</h4>
<br />"""),
'expires',
Field('expires_custom', template="crispy/customDateField.html"),
style="background: rgb(#F6F6F6);"),
active=True,
template='crispy/accordian-group.html'),
......
......@@ -5,8 +5,24 @@
Go - A University Branded URL Shortener
{% endblock %}
{% block content %}
<script type="text/javascript">
$(function() {
$("div_id_expires_custom").hide();
if ($("#id_expires_5").is(":checked")) {
$("#div_id_expires_custom").slideDown();
} else {
$("#div_id_expires_custom").slideUp();
}
$("#div_id_expires").click(function() {
if ($("#id_expires_5").is(":checked")) {
$("#div_id_expires_custom").slideDown();
} else {
$("#div_id_expires_custom").slideUp();
}
})
})
</script>
<div class="page-header" id="banner">
<div class="row">
......
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{% else %}
{% if field|is_checkbox %}
<div class="form-group">
{% if label_class %}
<div class="controls col-{{ bootstrap_device_type }}-offset-{{ label_size }} {{ field_class }}">
{% endif %}
{% endif %}
<{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" {% if not field|is_checkbox %}class="form-group{% else %}class="checkbox{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if form_show_errors%}{% if field.errors %} has-error{% endif %}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label and not field|is_checkbox and form_show_labels %}
<label for="{{ field.id_for_label }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
{% if field|is_checkboxselectmultiple %}
{% include 'bootstrap3/layout/checkboxselectmultiple.html' %}
{% endif %}
{% if field|is_radioselect %}
{% include 'bootstrap3/layout/radioselect.html' %}
{% endif %}
{% if not field|is_checkboxselectmultiple and not field|is_radioselect %}
{% if field|is_checkbox and form_show_labels %}
<label for="{{ field.id_for_label }}" class="{% if field.field.required %} requiredField{% endif %}">
{% crispy_field field %}
{{ field.label|safe }}
{% include 'bootstrap3/layout/help_text_and_errors.html' %}
</label>
{% else %}
<div class="controls col-md-2">
{% crispy_field field %}
{% include 'bootstrap3/layout/help_text_and_errors.html' %}
</div>
{% endif %}
{% endif %}
</{% if tag %}{{ tag }}{% else %}div{% endif %}>
{% if field|is_checkbox %}
{% if label_class %}
</div>
{% endif %}
</div>
{% endif %}
{% endif %}
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{% else %}
<div id="div_{{ field.auto_id }}" class="form-group{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if form_show_errors and field.errors %} has-error{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label and form_show_labels %}
<label for="{{ field.id_for_label }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
<div class="controls col-md-4">
{% if field|is_select %}
{% if crispy_prepended_text %}<span class="input-group{% if active %} active{% endif %}{% if input_size %} {{ input_size }}{% endif %}">{{ crispy_prepended_text|safe }}</span>{% endif %}
{% crispy_field field %}
{% if crispy_appended_text %}<span class="input-group{% if active %} active{% endif %}{% if input_size %} {{ input_size }}{% endif %}">{{ crispy_appended_text|safe }}</span>{% endif %}
{% else %}
<div class="input-group">
{% if crispy_prepended_text %}<span class="input-group-addon{% if active %} active{% endif %}{% if input_size %} {{ input_size }}{% endif %}">{{ crispy_prepended_text|safe }}</span>{% endif %}
{% crispy_field field %}
{% if crispy_appended_text %}<span class="input-group-addon{% if active %} active{% endif %}{% if input_size %} {{ input_size }}{% endif %}">{{ crispy_appended_text|safe }}</span>{% endif %}
</div>
{% endif %}
{% include 'bootstrap3/layout/help_text_and_errors.html' %}
</div>
</div>
{% endif %}
......@@ -110,6 +110,8 @@ def index(request):
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
......
......@@ -100,6 +100,7 @@ INSTALLED_APPS = (
'django.contrib.admin',
'qrcode',
'crispy_forms',
'bootstrap3_datetime',
)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
......
......@@ -100,6 +100,7 @@ INSTALLED_APPS = (
'django.contrib.admin',
'qrcode',
'crispy_forms',
'bootstrap3_datetime',
)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
......
......@@ -5,6 +5,7 @@ django-piwik==0.1
django-qrcode==0.3
flake8==2.5.1
git+https://github.com/kstateome/django-cas.git
git+https://github.com/bruno207/django-bootstrap3-datetimepicker.git
gunicorn==19.4.5
hashids==1.1.0
mccabe==0.3.1
......
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