Merge pull request #13 from vincentmdealmeida/ReCaptchaUpdate
Made a number of small enhancements. The django-recaptcha fields have…
This commit is contained in:
commit
14e475cf3b
7 changed files with 26 additions and 85 deletions
|
@ -1,10 +1,7 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.validators import MinLengthValidator
|
|
||||||
|
|
||||||
from .models import DemoUser
|
from .models import DemoUser
|
||||||
|
|
||||||
from captcha.fields import ReCaptchaField
|
|
||||||
|
|
||||||
|
|
||||||
class DemoUserEditForm(forms.ModelForm):
|
class DemoUserEditForm(forms.ModelForm):
|
||||||
"""Form for viewing and editing name fields in a DemoUser object.
|
"""Form for viewing and editing name fields in a DemoUser object.
|
||||||
|
@ -40,7 +37,6 @@ class NameForm(forms.Form):
|
||||||
|
|
||||||
|
|
||||||
class RegistrationForm(forms.Form):
|
class RegistrationForm(forms.Form):
|
||||||
captcha = ReCaptchaField()
|
|
||||||
|
|
||||||
def signup(self, request, user):
|
def signup(self, request, user):
|
||||||
user.save()
|
user.save()
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
from functools import partial
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.validators import MinLengthValidator
|
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.template import Context
|
from django.template import Context
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import EmailValidator
|
from django.core.validators import EmailValidator
|
||||||
from django.core.mail import send_mail
|
|
||||||
from crispy_forms.helper import FormHelper
|
from crispy_forms.helper import FormHelper
|
||||||
from crispy_forms.layout import LayoutObject, Layout, TEMPLATE_PACK, Fieldset, ButtonHolder, Submit, Div, Field, HTML
|
from crispy_forms.layout import LayoutObject, Layout, TEMPLATE_PACK, Div, Field, HTML
|
||||||
from crispy_forms.bootstrap import StrictButton, TabHolder, Tab, FormActions, PrependedText, PrependedAppendedText, Accordion, AccordionGroup
|
from crispy_forms.bootstrap import PrependedText, PrependedAppendedText, Accordion, AccordionGroup
|
||||||
from captcha.fields import ReCaptchaField
|
|
||||||
from allauthdemo.auth.models import DemoUser
|
from allauthdemo.auth.models import DemoUser
|
||||||
from .models import Event, Poll, PollOption
|
from .models import Event, Poll, PollOption
|
||||||
|
|
||||||
|
@ -21,12 +17,12 @@ def is_valid_email(email):
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# This form has been deprecated
|
||||||
class EventForm(forms.ModelForm):
|
class EventForm(forms.ModelForm):
|
||||||
#trustees = forms.CharField(label="Trustee list", widget=forms.Textarea(attrs={'width':"100%", 'cols' : "80", 'rows': "20", }))
|
|
||||||
voters = forms.CharField(label="Voters", required=False, widget=forms.Textarea(attrs={'width':"100%", 'cols' : "80", 'rows': "20", }))
|
voters = forms.CharField(label="Voters", required=False, widget=forms.Textarea(attrs={'width':"100%", 'cols' : "80", 'rows': "20", }))
|
||||||
#self.voters.widget=forms.Textarea(attrs={'width':"100%", 'cols' : "80", 'rows': "20", })
|
|
||||||
votersTextFile = forms.FileField(required=False)
|
votersTextFile = forms.FileField(required=False)
|
||||||
captcha = ReCaptchaField()
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.helper = FormHelper()
|
self.helper = FormHelper()
|
||||||
self.helper.form_tag = False
|
self.helper.form_tag = False
|
||||||
|
@ -42,8 +38,7 @@ class EventForm(forms.ModelForm):
|
||||||
Div(
|
Div(
|
||||||
PrependedAppendedText('end_time', 'Ends', '<span class="glyphicon glyphicon-calendar"></span>', placeholder="dd/mm/yyyy hh:mm"),
|
PrependedAppendedText('end_time', 'Ends', '<span class="glyphicon glyphicon-calendar"></span>', placeholder="dd/mm/yyyy hh:mm"),
|
||||||
css_class="input-group date col-sm-6"
|
css_class="input-group date col-sm-6"
|
||||||
),
|
)
|
||||||
Field('captcha')
|
|
||||||
),
|
),
|
||||||
AccordionGroup("Organisers",
|
AccordionGroup("Organisers",
|
||||||
HTML("<p>Event creators are automatically made an Organiser. Click and drag the tabs to reorder. Blank fields will be ignored.</p>"),
|
HTML("<p>Event creators are automatically made an Organiser. Click and drag the tabs to reorder. Blank fields will be ignored.</p>"),
|
||||||
|
@ -70,17 +65,16 @@ class EventForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Event
|
model = Event
|
||||||
fields = ('title', 'start_time', 'end_time', 'captcha') # TWEAK!!!
|
fields = ('title', 'start_time', 'end_time')
|
||||||
widgets = {
|
widgets = {
|
||||||
'voters': forms.Textarea(attrs={'cols': 80, 'rows': 20})
|
'voters': forms.Textarea(attrs={'cols': 80, 'rows': 20})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# This form has been deprecated
|
||||||
class EventEditForm(forms.ModelForm):
|
class EventEditForm(forms.ModelForm):
|
||||||
#trustees = forms.CharField(label="Trustee list", widget=forms.Textarea(attrs={'width':"100%", 'cols' : "80", 'rows': "20", }))
|
|
||||||
voters = forms.CharField(label="Voters", required=False, widget=forms.Textarea(attrs={'width':"100%", 'cols' : "80", 'rows': "20", }))
|
voters = forms.CharField(label="Voters", required=False, widget=forms.Textarea(attrs={'width':"100%", 'cols' : "80", 'rows': "20", }))
|
||||||
#self.voters.widget=forms.Textarea(attrs={'width':"100%", 'cols' : "80", 'rows': "20", })
|
|
||||||
votersTextFile = forms.FileField(required=False)
|
votersTextFile = forms.FileField(required=False)
|
||||||
captcha = ReCaptchaField()
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.helper = FormHelper()
|
self.helper = FormHelper()
|
||||||
self.helper.form_tag = False
|
self.helper.form_tag = False
|
||||||
|
@ -96,8 +90,7 @@ class EventEditForm(forms.ModelForm):
|
||||||
Div(
|
Div(
|
||||||
PrependedAppendedText('end_time', 'Ends', '<span class="glyphicon glyphicon-calendar"></span>', placeholder="dd/mm/yyyy hh:mm"),
|
PrependedAppendedText('end_time', 'Ends', '<span class="glyphicon glyphicon-calendar"></span>', placeholder="dd/mm/yyyy hh:mm"),
|
||||||
css_class="input-group date col-sm-6"
|
css_class="input-group date col-sm-6"
|
||||||
),
|
)
|
||||||
Field('captcha')
|
|
||||||
),
|
),
|
||||||
AccordionGroup('Voters',
|
AccordionGroup('Voters',
|
||||||
'voters',
|
'voters',
|
||||||
|
@ -110,7 +103,7 @@ class EventEditForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Event
|
model = Event
|
||||||
fields = ('title', 'start_time', 'end_time', 'captcha') # TWEAK!!!
|
fields = ('title', 'start_time', 'end_time')
|
||||||
widgets = {
|
widgets = {
|
||||||
'voters': forms.Textarea(attrs={'cols': 80, 'rows': 20})
|
'voters': forms.Textarea(attrs={'cols': 80, 'rows': 20})
|
||||||
}
|
}
|
||||||
|
@ -338,46 +331,3 @@ DecryptionFormset = forms.formset_factory(form=DecryptionForm, extra=0, min_num=
|
||||||
|
|
||||||
OptionFormset = forms.inlineformset_factory(Poll, PollOption, form=OptionForm, min_num=2, max_num=20, validate_min=True, extra=0, fields=('choice_text',), can_delete=True)
|
OptionFormset = forms.inlineformset_factory(Poll, PollOption, form=OptionForm, min_num=2, max_num=20, validate_min=True, extra=0, fields=('choice_text',), can_delete=True)
|
||||||
QuestionFormset = forms.inlineformset_factory(Event, Poll, form=PollForm, extra=0, min_num=2, validate_min=True, max_num=20, can_delete=True)
|
QuestionFormset = forms.inlineformset_factory(Event, Poll, form=PollForm, extra=0, min_num=2, validate_min=True, max_num=20, can_delete=True)
|
||||||
|
|
||||||
"""
|
|
||||||
PartialQuestionFormSet = partial(forms.formset_factory, PollQuestionForm, extra=2,
|
|
||||||
validate_min=True, validate_max=True, min_num=1, max_num=10)
|
|
||||||
|
|
||||||
|
|
||||||
OptionFormset = forms.inlineformset_factory(PollQuestion, QuestionChoice, extra=3, fields=('choice_text',))
|
|
||||||
|
|
||||||
QuestionFormset = forms.inlineformset_factory(Poll, PollQuestion,
|
|
||||||
formset=BasePollQuestionFormset, extra=2, fields=('question_text',))
|
|
||||||
|
|
||||||
|
|
||||||
TenantFormset = forms.inlineformset_factory(Building, Tenant, extra=1, fields=('name',))
|
|
||||||
BuildingFormset = forms.inlineformset_factory(Block, Building,
|
|
||||||
formset=BaseBuildingFormset, extra=1, fields=('address',))
|
|
||||||
AccordionGroup('Poll Questions',
|
|
||||||
Formset("question_formset",
|
|
||||||
"polls/create_question.html"
|
|
||||||
)
|
|
||||||
),
|
|
||||||
"""
|
|
||||||
"""
|
|
||||||
|
|
||||||
class PollQuestionForm(forms.ModelForm):
|
|
||||||
question_text = forms.CharField(
|
|
||||||
label = "Poll Title",
|
|
||||||
max_length = 80,
|
|
||||||
required = True,
|
|
||||||
)
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.helper = FormHelper()
|
|
||||||
self.helper.form_tag = False
|
|
||||||
self.helper.layout = Layout(
|
|
||||||
TabHolder(
|
|
||||||
Tab('question_text')
|
|
||||||
),
|
|
||||||
)
|
|
||||||
super(PollQuestionForm, self).__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = PollQuestion
|
|
||||||
fields = ('question_text',)
|
|
||||||
"""
|
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-collapse collapse">
|
<div class="navbar-collapse collapse">
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li><a href="{% url 'landing_index' %}">Welcome</a></li>
|
<li><a href="{% url 'landing_index' %}">Home</a></li>
|
||||||
<li><a href="{% url 'landing_about' %}">About</a></li>
|
{% comment %}<li><a href="{% url 'landing_about' %}">About</a></li>{% endcomment %} <!-- Currently this is not a production-ready page -->
|
||||||
<li><a href="{% url 'polls:index' %}">Events</a></li>
|
<li><a href="{% url 'polls:index' %}">Events</a></li>
|
||||||
<li><a href="{% url 'account_signup' %}"><strong>Join</strong></a></li>
|
<li><a href="{% url 'account_signup' %}"><strong>Join</strong></a></li>
|
||||||
<li><a href="{% url 'account_login' %}"><strong>Log In</strong></a></li>
|
<li><a href="{% url 'account_login' %}"><strong>Log In</strong></a></li>
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-collapse collapse">
|
<div class="navbar-collapse collapse">
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li><a href="{% url 'landing_index' %}">Welcome</a></li>
|
<li><a href="{% url 'landing_index' %}">Home</a></li>
|
||||||
<li><a href="{% url 'landing_about' %}">About</a></li>
|
{% comment %}<li><a href="{% url 'landing_about' %}">About</a></li>{% endcomment %} <!-- Currently this is not a production-ready page -->
|
||||||
<li><a href="{% url 'polls:index' %}">Events</a></li>
|
<li><a href="{% url 'polls:index' %}">Events</a></li>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
const OPTION_COUNT = {{ object.options.count }};
|
const OPTION_COUNT = {{ object.options.count }};
|
||||||
const MIN_SELECTIONS = {{ min_selection }};
|
const MIN_SELECTIONS = {{ min_selection }};
|
||||||
const MAX_SELECTIONS = {{ max_selection }};
|
const MAX_SELECTIONS = {{ max_selection }};
|
||||||
|
const POLL_COUNT = {{ poll_count }};
|
||||||
|
const POLL_NUM = {{ poll_num }};
|
||||||
var selectedCount = 0;
|
var selectedCount = 0;
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<h1>DEMOS 2</h1>
|
<h1>DEMOS 2</h1>
|
||||||
<img src='{% static "img/demos2-sm.png" %}'>
|
<img src='{% static "img/demos2-sm.png" %}'>
|
||||||
<p class="lead">
|
<p class="lead">
|
||||||
Read more on the <a href="{% url 'landing_about' %}">About Page.</a>
|
{% comment %}Read more on the <a href="{% url 'landing_about' %}">About Page.</a>{% endcomment %}<!-- Currently this is not a production-ready page -->
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<a class="btn btn-lg btn-success " href="{% url 'account_signup' %}" role="button">Join</a>
|
<a class="btn btn-lg btn-success " href="{% url 'account_signup' %}" role="button">Join</a>
|
||||||
|
|
|
@ -37,21 +37,6 @@ $("label input[type=checkbox]").change(function() {
|
||||||
updateCheckboxInteractivity();
|
updateCheckboxInteractivity();
|
||||||
});
|
});
|
||||||
|
|
||||||
function dropDownFragsNotZero(frags) {
|
|
||||||
var valid = false;
|
|
||||||
|
|
||||||
for(var i = 0; i < frags.length; i++) {
|
|
||||||
var frag = frags[i];
|
|
||||||
|
|
||||||
if(frag !== "0") {
|
|
||||||
valid = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVotingInputValid() {
|
function isVotingInputValid() {
|
||||||
var valid = true;
|
var valid = true;
|
||||||
|
|
||||||
|
@ -60,6 +45,10 @@ function isVotingInputValid() {
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(selectedCount < MAX_SELECTIONS) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
// This will highlight when people haven't selected enough options
|
// This will highlight when people haven't selected enough options
|
||||||
|
|
||||||
if(!valid) {
|
if(!valid) {
|
||||||
|
@ -204,6 +193,10 @@ function voteSuccessfullyReceived() {
|
||||||
title.text('Vote Successfully Received');
|
title.text('Vote Successfully Received');
|
||||||
var bodyText = "Thank you for voting!";
|
var bodyText = "Thank you for voting!";
|
||||||
|
|
||||||
|
if(POLL_NUM !== POLL_COUNT) {
|
||||||
|
bodyText += " You can vote on the next poll by closing down this dialog and clicking 'Next Poll'.";
|
||||||
|
}
|
||||||
|
|
||||||
var p = document.createElement("p");
|
var p = document.createElement("p");
|
||||||
p.innerHTML = bodyText;
|
p.innerHTML = bodyText;
|
||||||
body.empty();
|
body.empty();
|
||||||
|
|
Reference in a new issue