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 2, 2019
1 parent 5584daf commit c80fd0c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 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
1 change: 1 addition & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ $(document).ready(function(){
$('.form-submission-popup').css('display', 'none');
$('.oauth-error').css('display', 'none');
$('.community-form').css('display', 'none');
$('form').css('display', 'none');
});

logout_user_el.click(function () {
Expand Down
56 changes: 55 additions & 1 deletion templates/community_forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,58 @@ <h5 class="text-center custom-green-color-font bold-text">
<div class="apply-flex center-content submit-btn">
<input class="waves-effect waves-light btn-large large-font" type="submit" value="Submit">
</div>
</form>
</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><label for="{{ field.name }}">{{ field.label }}</label></p>
{% else %}
<label for="{{ field.name }}">{{ field.label }}</label>
{% 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 c80fd0c

Please sign in to comment.