Skip to content

Commit

Permalink
community/: Add a form for adding calendar events
Browse files Browse the repository at this point in the history
Not everyone, will be able to fill forms.
Only the logged in users will be able to
fill them and some of the forms, can only
be filled by developers or contributors
who are a part of more than one team.
At every step, the check is performed whether
the user is authenticated or not, to avoid
false form submissions.

Closes #270
  • Loading branch information
KVGarg committed Aug 5, 2019
1 parent e05a821 commit 7274277
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
25 changes: 25 additions & 0 deletions community/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,28 @@ class CommunityGoogleForm(forms.Form):
help_text='DateTime Format should be YYYY-MM-DD HH:MM:SS',
widget=forms.TextInput(attrs={'autocomplete': 'off'})
)


class CommunityEvent(forms.Form):
user = forms.CharField(
max_length=50, label='GitHub Username',
widget=forms.TextInput(attrs={'autocomplete': 'off'})
)
title = forms.CharField(
max_length=300, label='Event Title',
widget=forms.TextInput(attrs={'autocomplete': 'off'})
)
description = forms.CharField(
max_length=1000, label='Event Description', required=False,
widget=forms.Textarea(attrs={'autocomplete': 'off'})
)
start_date_time = forms.DateTimeField(
label='Event occurrence date and time(in UTC)',
help_text='DateTime Format should be YYYY-MM-DD HH:MM:SS',
widget=forms.TextInput(attrs={'autocomplete': 'off'})
)
end_date_time = forms.DateTimeField(
label='Event end date and time(in UTC)', required=False,
help_text='DateTime Format should be YYYY-MM-DD HH:MM:SS',
widget=forms.TextInput(attrs={'autocomplete': 'off'})
)
11 changes: 10 additions & 1 deletion community/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
get_org_name,
get_remote_url
)
from .forms import JoinCommunityForm, CommunityGoogleForm
from .forms import JoinCommunityForm, CommunityGoogleForm, CommunityEvent
from data.models import Team
from gamification.models import Participant as GamificationParticipant
from meta_review.models import Participant as MetaReviewer
Expand Down Expand Up @@ -42,6 +42,14 @@ def initialize_org_context_details():
return org_details


def get_community_event_form_variables(context):
context['community_event_form'] = CommunityEvent()
context['community_event_form_name'] = os.environ.get(
'CALENDAR_NETLIFY_FORM_NAME', None
)
return context


def get_community_google_form_variables(context):
context['community_google_form'] = CommunityGoogleForm()
context['community_google_form_name'] = os.environ.get(
Expand All @@ -55,6 +63,7 @@ def get_header_and_footer(context):
context['travisLink'] = Travis.TRAVIS_BUILD_WEB_URL
context['org'] = initialize_org_context_details()
context = get_community_google_form_variables(context)
context = get_community_event_form_variables(context)
print('Running on Travis: {}, build link: {}'.format(context['isTravis'],
context['travisLink']
))
Expand Down
4 changes: 2 additions & 2 deletions static/js/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(document).ready(function () {
username_input.attr('value', authenticated_username || 'Anonymous User');
username_input.attr('disabled', true);

$('form').attr(
$('.community-form form').attr(
'action',window.location.pathname +
'?form_submitted=True&form_type=community'
);
Expand Down Expand Up @@ -86,7 +86,7 @@ $(document).ready(function () {
display_form_or_error(mentor_students_form);
});

$(':input').focusin(function () {
$('.community-form :input').focusin(function () {
if (is_user_authenticated===undefined &&
authenticated_username===undefined) {
$('.community-form').css('display', 'none');
Expand Down
1 change: 1 addition & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ $(document).ready(function(){
$('.form-submission-popup').css('display', 'none');
$('.oauth-error').css('display', 'none');
$('.community-form').css('display', 'none');
$('.community-form form').css('display', 'none');
});

logout_user_el.click(function () {
Expand Down
55 changes: 55 additions & 0 deletions templates/community_forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,58 @@ <h5 class="text-center custom-green-color-font bold-text">
<input class="waves-effect waves-light btn-large large-font" type="submit" value="Submit">
</div>
</form>


<form name="{{ community_event_form_name }}" method="post"
netlify-honeypot="bot-field" class="calendar-event-form display-none"
data-netlify="true" action="/">
<h5 class="text-center custom-green-color-font bold-text">
Community Event Details
</h5>
{% csrf_token %}
{% for field in community_event_form %}
<div class="row">
<div class="input-field col s12">
{% if field.name == 'user' %}
<p>{{ field.label_tag }}</p>
{% else %}
{{ field.label_tag }}
{% endif %}
{{ field }}
{% if field.help_text %}
<i class="fa fa-info-circle" aria-hidden="true">{{ field.help_text }}</i>
{% endif %}
</div>
</div>
{% endfor %}
<div class="validation-checkboxes">
<p>
<label>
<input type="checkbox" required>
<span>I am a member of {{ org.name }} developers group.</span>
</label>
</p>
<p>
<label>
<input type="checkbox" required>
<span>All of the above information provided by me has no false
entries. If so, I am liable of getting blacklisted.</span>
</label>
</p>
<p style="display: none">
<label>
<input type="checkbox" name="bot-field">
<span>I am a bot</span>
</label>
</p>
<p>
<strong>
Note: You will receive an email within 24 hrs, if any of the
validation checks are not passed.
</strong>
</p>
</div>
<div class="apply-flex center-content submit-btn">
<input class="waves-effect waves-light btn-large large-font" type="submit" value="Submit">
</div>
</form>

0 comments on commit 7274277

Please sign in to comment.