Skip to content

Commit bad80c8

Browse files
Merge pull request #129 from abhishekarya286/contestpage
Fix #118: Added contest page functionality (submit for review then add)
2 parents 8da0e7b + e704eba commit bad80c8

File tree

9 files changed

+187
-13
lines changed

9 files changed

+187
-13
lines changed

oshc/main/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
from django.contrib import admin
55

6-
from main.models import chatSession
6+
from main.models import chatSession, Contest
77

88

99
class chatSessionAdmin(admin.ModelAdmin):
1010
list_display = ('title', 'start_date')
1111

1212

1313
admin.site.register(chatSession, chatSessionAdmin)
14+
admin.site.register(Contest)

oshc/main/migrations/0001_initial.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Generated by Django 1.11.2 on 2017-09-16 20:45
2+
# Generated by Django 1.11.2 on 2017-10-07 16:35
33
from __future__ import unicode_literals
44

55
from django.db import migrations, models
@@ -16,14 +16,38 @@ class Migration(migrations.Migration):
1616
migrations.CreateModel(
1717
name='chatSession',
1818
fields=[
19-
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20-
('title', models.CharField(help_text='Session title', max_length=128)),
21-
('profile_name', models.CharField(help_text="The person's name", max_length=128)),
22-
('profile_url', models.URLField(help_text="The Url of the person's website")),
23-
('description', models.TextField(help_text='Session details', max_length=512)),
19+
('id', models.AutoField(auto_created=True,
20+
primary_key=True,
21+
serialize=False, verbose_name='ID')),
22+
('title', models.CharField(help_text='Session title',
23+
max_length=128)),
24+
('profile_name', models.CharField(
25+
help_text="The person's name", max_length=128)),
26+
('profile_url', models.URLField(
27+
help_text="The Url of the person's website")),
28+
('description', models.TextField(
29+
help_text='Session details', max_length=512)),
2430
('start_date', models.DateTimeField()),
2531
('end_date', models.DateTimeField()),
26-
('register_url', models.URLField(help_text='URL for the event registration')),
32+
('register_url', models.URLField(
33+
help_text='URL for the event registration')),
34+
],
35+
),
36+
migrations.CreateModel(
37+
name='Contest',
38+
fields=[
39+
('id', models.AutoField(auto_created=True,
40+
primary_key=True,
41+
serialize=False, verbose_name='ID')),
42+
('name', models.CharField(help_text='Contest name',
43+
max_length=128)),
44+
('link',
45+
models.URLField(help_text="URL of the contest's website")),
46+
('description', models.TextField(
47+
help_text='Contest details', max_length=512, null=True)),
48+
('start_date', models.DateField(null=True)),
49+
('end_date', models.DateField(null=True)),
50+
('approved', models.BooleanField(default=False)),
2751
],
2852
),
2953
]

oshc/main/models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ class chatSession(models.Model):
1515

1616
def __str__(self):
1717
return self.title
18+
19+
20+
class Contest(models.Model):
21+
name = models.CharField(max_length=128, help_text="Contest name")
22+
link = models.URLField(help_text="URL of the contest's website")
23+
description = models.TextField(max_length=512,
24+
help_text="Contest details", null=True)
25+
start_date = models.DateField(null=True)
26+
end_date = models.DateField(null=True)
27+
approved = models.BooleanField(default=False)
28+
29+
def __str__(self):
30+
return self.name

oshc/main/templates/base.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
</ul>
3434
</li>
3535
<li><a href="https://github.com/OpenSourceHelpCommunity" target="_blank">Resources</a></li>
36+
<li><a href="{% url 'contests' %}" target="_blank">Contests</a></li>
3637
<li><a href="mailto:[email protected]" target="_blank">Contact</a></li>
3738
<li><a href="https://opensourcehelp.herokuapp.com/" target="_blank">Join Us!</a></li>
3839
</ul>

oshc/main/templates/contest_edit.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{% extends 'base.html' %}
2+
3+
{% block content %}
4+
5+
<form name="newContest" method="POST" class="form-horizontal" action = "{% url 'add_contest' %}">
6+
{% csrf_token %}
7+
<div class="form-group">
8+
<label style="margin-top:70px;" for="name" class="control-label col-xs-2">Name:</label>
9+
<div class="col-xs-3">
10+
<input type="text" style="margin-top:70px;" class="form-control" id="name" name="name" placeholder="Contest Name" required>
11+
</div>
12+
</div>
13+
14+
<div class="form-group">
15+
<label for="link" class="control-label col-xs-2">Contest's Website:</label>
16+
<div class="col-xs-3">
17+
<input type="url" class="form-control" id="link" name="link" placeholder="https://www.testweb.com" required>
18+
</div>
19+
</div>
20+
21+
<div class="form-group">
22+
<label for="start_date" class="control-label col-xs-2">Start Date:</label>
23+
<div class="col-xs-3">
24+
<input type="start_date" class="form-control" id="start_date" name="start_date" placeholder="YYYY-MM-DD">
25+
</div>
26+
</div>
27+
28+
<div class="form-group">
29+
<label for="end_date" class="control-label col-xs-2">End Date:</label>
30+
<div class="col-xs-3">
31+
<input type="end_date" class="form-control" id="end_date" name="end_date" placeholder="YYYY-MM-DD">
32+
</div>
33+
</div>
34+
35+
<div class="form-group">
36+
<label for="desc" class="control-label col-xs-2">Description:</label>
37+
<div class="col-xs-3">
38+
<textarea class="form-control" id="desc" name="desc" placeholder="Tell something about it.." rows="3"></textarea>
39+
</div>
40+
</div>
41+
42+
<div class="form-group">
43+
<div class="col-xs-offset-3 col-xs-8">
44+
<button type="submit" class="save btn btn-default">SUBMIT</button>
45+
</div>
46+
</div>
47+
48+
</form>
49+
50+
{% endblock %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends 'base.html' %}
2+
{% load static %}
3+
{% block content %}
4+
5+
<div class="jumbotron text-xs-center">
6+
<div class="container text-center">
7+
<h1 class="display-3">Thank You!</h1>
8+
<p class="lead"><strong>Your contest has been submitted for review.</strong></p>
9+
<hr>
10+
<p class="lead">
11+
<a class="btn btn-primary btn-sm" href="{% url 'home' %}" role="button">Continue to homepage</a>
12+
</p>
13+
</div>
14+
</div>
15+
16+
{% endblock %}

oshc/main/templates/contests.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{% extends 'base.html' %}
2+
{% load static %}
3+
{% block content %}
4+
<style>
5+
h3 {
6+
text-align: center;
7+
}
8+
span
9+
{
10+
display: block;
11+
}
12+
</style>
13+
<section class="main-section">
14+
<div class="container">
15+
<h3>List of Upcoming Contests</h3>
16+
<div class="container-fluid">
17+
<div class="row">
18+
{% for contest in contest_list %}
19+
{% if contest.approved %}
20+
<div class="col-lg-4">
21+
<div class="panel panel-default">
22+
<div class="panel-heading" style="background-color: #0275d8;color:white">{{contest.name}}</div>
23+
<div class="panel-body">
24+
<span><span class="glyphicon glyphicon-globe"></span> <a href="{{contest.link}}">{{contest.link}}</a></span>
25+
<span><span class="glyphicon glyphicon-time"></span> {{contest.start_date}}-{{contest.end_date}}</span>
26+
<span><span class="glyphicon glyphicon-info-sign"></span> {{contest.description}}</span>
27+
</div>
28+
</div>
29+
</div>
30+
{% endif %}
31+
{% endfor %}
32+
</div>
33+
</div>
34+
<div class="Button" align="center" style="margin-bottom:70px; margin-top:20px;">
35+
<a href="{% url 'contest_new' %}" class="btn btn-default" style="background-color:#0275d8;color:white;">Submit a New Contest</a>
36+
</div>
37+
</div>
38+
</section>
39+
{% endblock %}

oshc/main/urls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33

44
urlpatterns = [
55
url(r'^$', views.home, name="home"),
6-
url(r'^session/', views.request_session, name="request_session")
6+
url(r'^session/', views.request_session, name="request_session"),
7+
url(r'^contests/', views.contests, name="contests"),
8+
url(r'^contest_new/', views.contest_new, name="contest_new"),
9+
url(r'^add_contest/', views.add_contest, name="add_contest"),
10+
url(r'^submit_contest/', views.submit_contest, name="submit_contest"),
711
]

oshc/main/views.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from django.shortcuts import render
2-
2+
from django.http import HttpResponseRedirect
3+
from main.models import chatSession, Contest
4+
from datetime import datetime
35
from django.shortcuts import render_to_response
4-
56
from django.template import RequestContext
67

7-
from main.models import chatSession
8-
98

109
def home(request):
1110
session_list = chatSession.objects.order_by('start_date')[:3]
@@ -17,6 +16,33 @@ def request_session(request):
1716
return render(request, 'session.html')
1817

1918

19+
def contests(request):
20+
contest_list = Contest.objects.all()
21+
return render(request, 'contests.html',
22+
context={'contest_list': contest_list})
23+
24+
25+
def contest_new(request):
26+
return render(request, 'contest_edit.html')
27+
28+
29+
def add_contest(request):
30+
contest = Contest()
31+
contest.name = request.POST.get("name", "null")
32+
contest.link = request.POST.get("link", "null")
33+
start_date = request.POST.get("start_date", "null")
34+
end_date = request.POST.get("end_date", "null")
35+
contest.description = request.POST.get("desc", "null")
36+
contest.end_date = datetime.strptime(end_date, '%Y-%m-%d').date()
37+
contest.start_date = datetime.strptime(start_date, '%Y-%m-%d').date()
38+
contest.save()
39+
return HttpResponseRedirect("/submit_contest/")
40+
41+
42+
def submit_contest(request):
43+
return render(request, 'contest_submission.html')
44+
45+
2046
def handler404(request):
2147
response = render_to_response('404.html', {},
2248
context_instance=RequestContext(request))

0 commit comments

Comments
 (0)