Skip to content

Commit cc06a92

Browse files
committed
community/: Add a form for adding calendar events
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
1 parent 5e75cd9 commit cc06a92

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

community/forms.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,28 @@ class CommunityGoogleForm(forms.Form):
104104
help_text='DateTime Format should be YYYY-MM-DD HH:MM:SS',
105105
widget=forms.TextInput(attrs={'autocomplete': 'off'})
106106
)
107+
108+
109+
class CommunityEvent(forms.Form):
110+
user = forms.CharField(
111+
max_length=50, label='GitHub Username',
112+
widget=forms.TextInput(attrs={'autocomplete': 'off'})
113+
)
114+
title = forms.CharField(
115+
max_length=300, label='Event Title',
116+
widget=forms.TextInput(attrs={'autocomplete': 'off'})
117+
)
118+
description = forms.CharField(
119+
max_length=1000, label='Event Description', required=False,
120+
widget=forms.Textarea(attrs={'autocomplete': 'off'})
121+
)
122+
start_date_time = forms.DateTimeField(
123+
label='Event occurrence date and time(in UTC)',
124+
help_text='DateTime Format should be YYYY-MM-DD HH:MM:SS',
125+
widget=forms.TextInput(attrs={'autocomplete': 'off'})
126+
)
127+
end_date_time = forms.DateTimeField(
128+
label='Event end date and time(in UTC)', required=False,
129+
help_text='DateTime Format should be YYYY-MM-DD HH:MM:SS',
130+
widget=forms.TextInput(attrs={'autocomplete': 'off'})
131+
)

community/views.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
get_org_name,
1313
get_remote_url
1414
)
15-
from .forms import JoinCommunityForm, CommunityGoogleForm
15+
from .forms import JoinCommunityForm, CommunityGoogleForm, CommunityEvent
1616
from data.models import Team
1717
from gamification.models import Participant as GamificationParticipant
1818
from meta_review.models import Participant as MetaReviewer
@@ -42,6 +42,14 @@ def initialize_org_context_details():
4242
return org_details
4343

4444

45+
def get_community_event_form_variables(context):
46+
context['community_event_form'] = CommunityEvent()
47+
context['community_event_form_name'] = os.environ.get(
48+
'CALENDAR_NETLIFY_FORM_NAME', None
49+
)
50+
return context
51+
52+
4553
def get_community_google_form_variables(context):
4654
context['community_google_form'] = CommunityGoogleForm()
4755
context['community_google_form_name'] = os.environ.get(
@@ -55,6 +63,7 @@ def get_header_and_footer(context):
5563
context['travisLink'] = Travis.TRAVIS_BUILD_WEB_URL
5664
context['org'] = initialize_org_context_details()
5765
context = get_community_google_form_variables(context)
66+
context = get_community_event_form_variables(context)
5867
print('Running on Travis: {}, build link: {}'.format(context['isTravis'],
5968
context['travisLink']
6069
))

static/js/forms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $(document).ready(function () {
2222
username_input.attr('value', authenticated_username || 'Anonymous User');
2323
username_input.attr('disabled', true);
2424

25-
$('form').attr(
25+
$('.community-form form').attr(
2626
'action',window.location.pathname +
2727
'?form_submitted=True&form_type=community'
2828
);
@@ -86,7 +86,7 @@ $(document).ready(function () {
8686
display_form_or_error(mentor_students_form);
8787
});
8888

89-
$(':input').focusin(function () {
89+
$('.community-form :input').focusin(function () {
9090
if (is_user_authenticated===undefined &&
9191
authenticated_username===undefined) {
9292
$('.community-form').css('display', 'none');

static/js/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ $(document).ready(function(){
128128
$('.form-submission-popup').css('display', 'none');
129129
$('.oauth-error').css('display', 'none');
130130
$('.community-form').css('display', 'none');
131+
$('.community-form form').css('display', 'none');
131132
});
132133

133134
logout_user_el.click(function () {

templates/community_forms.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,58 @@ <h5 class="text-center custom-green-color-font bold-text">
5151
<input class="waves-effect waves-light btn-large large-font" type="submit" value="Submit">
5252
</div>
5353
</form>
54+
55+
56+
<form name="{{ community_event_form_name }}" method="post"
57+
netlify-honeypot="bot-field" class="calendar-event-form display-none"
58+
data-netlify="true" action="/">
59+
<h5 class="text-center custom-green-color-font bold-text">
60+
Community Event Details
61+
</h5>
62+
{% csrf_token %}
63+
{% for field in community_event_form %}
64+
<div class="row">
65+
<div class="input-field col s12">
66+
{% if field.name == 'user' %}
67+
<p>{{ field.label_tag }}</p>
68+
{% else %}
69+
{{ field.label_tag }}
70+
{% endif %}
71+
{{ field }}
72+
{% if field.help_text %}
73+
<i class="fa fa-info-circle" aria-hidden="true">{{ field.help_text }}</i>
74+
{% endif %}
75+
</div>
76+
</div>
77+
{% endfor %}
78+
<div class="validation-checkboxes">
79+
<p>
80+
<label>
81+
<input type="checkbox" required>
82+
<span>I am a member of {{ org.name }} developers group.</span>
83+
</label>
84+
</p>
85+
<p>
86+
<label>
87+
<input type="checkbox" required>
88+
<span>All of the above information provided by me has no false
89+
entries. If so, I am liable of getting blacklisted.</span>
90+
</label>
91+
</p>
92+
<p style="display: none">
93+
<label>
94+
<input type="checkbox" name="bot-field">
95+
<span>I am a bot</span>
96+
</label>
97+
</p>
98+
<p>
99+
<strong>
100+
Note: You will receive an email within 24 hrs, if any of the
101+
validation checks are not passed.
102+
</strong>
103+
</p>
104+
</div>
105+
<div class="apply-flex center-content submit-btn">
106+
<input class="waves-effect waves-light btn-large large-font" type="submit" value="Submit">
107+
</div>
108+
</form>

0 commit comments

Comments
 (0)