Unverified Commit 9dd954de authored by David Haynes's avatar David Haynes
Browse files

Form displays and some initial data set

- Also remove old css file
- Better imports for forms.py
parent 80209b83
Pipeline #1172 passed with stage
in 1 minute and 4 seconds
......@@ -11,8 +11,10 @@ from datetime import datetime, timedelta
from six.moves import urllib
# Django Imports
from django import forms
from django.core.exceptions import ValidationError
from django.forms import (BooleanField, CharField, ChoiceField, DateTimeField,
ModelForm, RadioSelect, SlugField, Textarea,
TextInput, URLField, URLInput)
from django.utils import timezone
from django.utils.safestring import mark_safe
......@@ -27,7 +29,7 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Div, Field, Fieldset, Layout, Submit
class URLForm(forms.ModelForm):
class URLForm(ModelForm):
"""
The form that is used in URL creation.
"""
......@@ -66,11 +68,11 @@ class URLForm(forms.ModelForm):
return target
# Custom target URL field
target = forms.URLField(
target = URLField(
required=True,
label='Long URL (Required)',
max_length=1000,
widget=forms.URLInput(attrs={
widget=URLInput(attrs={
'placeholder': 'https://yoursite.com/'
})
)
......@@ -92,10 +94,10 @@ class URLForm(forms.ModelForm):
raise ValidationError('Short url already exists.')
# Custom short-url field with validators.
short = forms.SlugField(
short = SlugField(
required=False,
label='Short URL (Optional)',
widget=forms.TextInput(),
widget=TextInput(),
validators=[unique_short],
max_length=20,
min_length=3,
......@@ -120,12 +122,12 @@ class URLForm(forms.ModelForm):
)
# Add preset expiration choices.
expires = forms.ChoiceField(
expires = ChoiceField(
required=True,
label='Expiration (Required)',
choices=EXPIRATION_CHOICES,
initial=NEVER,
widget=forms.RadioSelect(),
widget=RadioSelect(),
)
def valid_date(value):
......@@ -142,7 +144,7 @@ class URLForm(forms.ModelForm):
# Add a custom expiration choice.
expires_custom = forms.DateTimeField(
expires_custom = DateTimeField(
required=False,
label='Custom Date',
input_formats=['%m-%d-%Y'],
......@@ -233,37 +235,37 @@ class URLForm(forms.ModelForm):
# what attributes are included
fields = ['target']
class SignupForm(forms.ModelForm):
class SignupForm(ModelForm):
"""
The form that is used when a user is signing up to be a RegisteredUser
"""
# The full name of the RegisteredUser
full_name = forms.CharField(
full_name = CharField(
required=True,
label='Full Name (Required)',
max_length=100,
widget=forms.TextInput(),
widget=TextInput(),
)
# The RegisteredUser's chosen organization
organization = forms.CharField(
organization = CharField(
required=True,
label='Organization (Required)',
max_length=100,
widget=forms.TextInput(),
widget=TextInput(),
)
# The RegisteredUser's reason for signing up to us Go
description = forms.CharField(
description = CharField(
required=False,
label='Description (Optional)',
max_length=200,
widget=forms.Textarea(),
widget=Textarea(),
)
# A user becomes registered when they agree to the TOS
registered = forms.BooleanField(
registered = BooleanField(
required=True,
# ***Need to replace lower url with production URL***
# ie. go.gmu.edu/about#terms
......
......@@ -30,6 +30,8 @@ SRCT Go • Edit Link
</div>
</div>
<!-- call django crispy forms to render the go link creation form here -->
{% crispy form %}
<!-- load some JS to hide/show the custom date field -->
<script src="{% static "js/new_link.js" %}"></script>
......
......@@ -35,8 +35,6 @@
rel="stylesheet">
<link rel="stylesheet" href="{% static "css/bootswatch.min.css" %}" />
<link rel="stylesheet" href="{% static "css/styles.css" %}" />
<link rel="stylesheet" href="{% static "css/style-link-box.css" %}" />
<link rel="stylesheet" href="{% static "css/style-link-box.css" %}" />
<!-- Load in global js -->
<script src="{% static "js/jquery.min.js" %}"></script>
......
......@@ -210,12 +210,38 @@ def edit(request, short):
# If the RegisteredUser is the owner of the URL
if url.owner == request.user.registereduser:
# render the edit URL form
# Render index.html passing the form to the template
return render(request, 'core/edit_link.html', {
})
# Initialize a URL form
url_form = URLForm(host=request.META.get('HTTP_HOST'), initial={
'target': url.target,
'short': url.short
# figure out how to set expires (lambda?)
}) # unbound form
# Initial data set here
# If a POST request is received, then the user has submitted a form and it's
# time to parse the form and edit that 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'))
# Django will check the form to make sure it's valid
if url_form.is_valid():
return redirect('view', None)
# Else, there is an error, redisplay the form with the validation errors
else:
# Render index.html passing the form to the template
return render(request, 'core/edit_link.html', {
'form': url_form
})
else:
# Render index.html passing the form to the template
return render(request, 'core/edit_link.html', {
'form': url_form
})
# redirect to my_links
# return redirect('my_links')
......
a.share:link {color:#000000;}
a.share:visited {color:#000000;}
a.share:hover {color:#000000;}
a.share {text-decoration:none;}
a.button:link {color:#FFF;}
a.button:visited {color:#FFF;}
a.button:hover {color:#FFF;}
legend {
font-size: inherit;
}
#button-container {
padding-bottom: 4px;
padding-left: 6px;
padding-right: 6px;
padding-top: 4px;
}
#copy-button {
border: none;
background-color: #eeeeee;
padding-bottom: 3px;
}
#copy-button:focus {
outline: none;
}
#clipboard-icon {
font-size: 14px;
}
#link:visited {
color: #006633;
}
#link-container {
width: 400px;
}
.tooltip-inner {
white-space: nowrap;
max-width: none;
}
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