Skip to content

Commit b7a0836

Browse files
committed
community/: Display org teams
The webpage will be displaying all the organization teams, to the authenticated users only. If tried to access w/o auth, the user will be redirected to homepage with an error message. Closes coala#287
1 parent 1a00c1d commit b7a0836

File tree

8 files changed

+152
-6
lines changed

8 files changed

+152
-6
lines changed

Diff for: community/urls.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
from django.conf.urls.static import static
88
from django.conf import settings
99

10-
from community.views import HomePageView, JoinCommunityView
10+
from community.views import (
11+
HomePageView, JoinCommunityView,
12+
OrganizationTeams
13+
)
1114
from gci.views import GCIStudentsList
1215
from gci.feeds import LatestTasksFeed as gci_tasks_rss
1316
from twitter.view_twitter import index as twitter_index
@@ -40,6 +43,12 @@ def get_index():
4043
distill_func=get_index,
4144
distill_file='join/index.html',
4245
),
46+
distill_url(
47+
r'teams/', OrganizationTeams.as_view(),
48+
name='org-teams',
49+
distill_func=get_index,
50+
distill_file='teams/index.html',
51+
),
4352
distill_url(
4453
r'gci/tasks/rss.xml', gci_tasks_rss(),
4554
name='gci-tasks-rss',

Diff for: community/views.py

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from trav import Travis
88

99
from django.views.generic.base import TemplateView
10+
from django.views.generic import ListView
1011

1112
from .git import (
1213
get_org_name,
@@ -206,3 +207,14 @@ def get_context_data(self, **kwargs):
206207
'JOIN_COMMUNITY_FORM_NAME', None
207208
)
208209
return context
210+
211+
212+
class OrganizationTeams(ListView):
213+
214+
template_name = 'teams.html'
215+
model = Team
216+
217+
def get_context_data(self, **kwargs):
218+
context = super().get_context_data(**kwargs)
219+
context = get_header_and_footer(context)
220+
return context

Diff for: data/migrations/0008_auto_20190802_0745.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 2.1.7 on 2019-08-02 07:45
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('data', '0007_auto_20190802_2015'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='team',
15+
name='description',
16+
field=models.TextField(default=None, max_length=500, null=True),
17+
),
18+
migrations.AddField(
19+
model_name='team',
20+
name='increased_count',
21+
field=models.PositiveSmallIntegerField(default=0),
22+
),
23+
migrations.AddField(
24+
model_name='team',
25+
name='members_count',
26+
field=models.PositiveSmallIntegerField(default=0),
27+
),
28+
]

Diff for: data/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
class Team(models.Model):
55
name = models.CharField(max_length=200, default=None)
6+
description = models.TextField(max_length=500, default=None, null=True)
7+
members_count = models.PositiveSmallIntegerField(default=0)
8+
increased_count = models.PositiveSmallIntegerField(default=0)
69

710
def __str__(self):
811
return self.name

Diff for: static/css/teams.css

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.light-green-color {
2+
color: green;
3+
}
4+
5+
.organization-teams {
6+
margin: auto;
7+
width: 60%;
8+
min-width: 330px;
9+
}
10+
11+
.team-name {
12+
font-size: 1.5em;
13+
}
14+
15+
.team-desc {
16+
padding-left: 20px;
17+
}

Diff for: static/js/main.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ $(document).ready(function(){
77
var urlParams = new URLSearchParams(location.search);
88
var formSubmitted = urlParams.get('form_submitted');
99
var formType = urlParams.get('form_type');
10+
var userAuthenticated = urlParams.get('auth');
11+
12+
var current_search_location = window.location;
13+
console.log(current_search_location);
14+
if(current_search_location.toString().search('teams')>0){
15+
var is_authenticated = Cookies.set('authenticated');
16+
var username = Cookies.set('username');
17+
if(is_authenticated !== true && username === undefined){
18+
window.location = window.location.origin + '?auth=false';
19+
}
20+
}
21+
1022
if(formSubmitted==='True'){
1123
var message = '';
1224
if(formType==='login'){
@@ -29,6 +41,13 @@ $(document).ready(function(){
2941
$('.important-message').text(message);
3042
$('.form-submission-popup').css('display', 'block');
3143
}
44+
else if(userAuthenticated === 'false'){
45+
$('.important-message').text(
46+
'You tried to access a webpage, which is available to only' +
47+
' authenticated users. Please join the community or Login(if' +
48+
' already a member of organization)');
49+
$('.form-submission-popup').css('display', 'block');
50+
}
3251

3352
function activate_dropdown(){
3453
if ($('nav').width() < 992 ){
@@ -43,7 +62,8 @@ $(document).ready(function(){
4362

4463
function check_user_authenticated_or_not() {
4564
if(Cookies.get('authenticated')){
46-
modify_html_elements('none', 'none','block', 'block', 'block');
65+
modify_html_elements('none', 'none','block', 'block', 'block',
66+
'block');
4767
}
4868
}
4969

@@ -60,12 +80,13 @@ $(document).ready(function(){
6080
function modify_html_elements(popup_form_display, login_option_display,
6181
profile_option_display,
6282
logout__option_display,
63-
form_option_display) {
83+
form_option_display, teams_option_display) {
6484
$('.form-popup').css('display', popup_form_display);
6585
login_user_el.css('display', login_option_display);
6686
$('.user-profile').css('display', profile_option_display);
6787
logout_user_el.css('display', logout__option_display);
6888
$('.forms-dropdown-option').css('display', form_option_display);
89+
$('.teams-dropdown-option'.css('display', teams_option_display));
6990
}
7091

7192
function manipulate_web_page_data(oauth_provider, http_response_text) {
@@ -74,7 +95,8 @@ $(document).ready(function(){
7495
// Cookies expires in 3 days
7596
Cookies.set('authenticated', true, {expires: 3});
7697
Cookies.set('username', json_data.user, {expires: 3});
77-
modify_html_elements('none', 'none','block', 'block', 'block');
98+
modify_html_elements('none', 'none','block', 'block', 'block',
99+
'block');
78100
}
79101
else {
80102
display_error_message(oauth_provider, json_data.message);
@@ -145,7 +167,7 @@ $(document).ready(function(){
145167
logout_user_el.click(function () {
146168
Cookies.remove('authenticated');
147169
Cookies.remove('username');
148-
modify_html_elements('none', 'block','none', 'none', 'none');
170+
modify_html_elements('none', 'block','none', 'none', 'none', 'none');
149171
});
150172

151173
$('.login-with-github').click(function(e) {

Diff for: templates/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
</ul>
7575

7676
<ul id="organisation-dropdown" class="dropdown-content">
77-
<li><a href="#">Teams</a></li>
77+
<li class="teams-dropdown-option display-none"><a href="{% url 'org-teams' %}" class="">Teams</a></li>
7878
<li><a href="{% url 'community-data' %}">Contributors Information</a></li>
7979
<li><a href="#">Mentors</a></li>
8080
<li><a href="{% url 'community-gci' %}">Google Code-in Students</a></li>

Diff for: templates/teams.html

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{% extends 'base.html' %}
2+
{% load staticfiles %}
3+
4+
{% block add_css_files %}
5+
<link rel="stylesheet" href="{% static 'css/teams.css' %}">
6+
{% endblock %}
7+
8+
{% block main-content %}
9+
<div class="web-page-details apply-flex center-content">
10+
<h3 style="padding-right: 15px">~</h3>
11+
<h3 class="page-name">
12+
<img src="{{ org.logo_url }}" alt="{{ org.name }}">
13+
Organization Teams
14+
</h3>
15+
<h3 style="padding-left: 15px">~</h3>
16+
</div>
17+
<div class="organization-teams">
18+
<table class="highlight">
19+
<thead>
20+
<tr class="custom-green-color-font">
21+
<th>
22+
<h5>Team</h5>
23+
</th>
24+
<th class="text-center">
25+
<h5>No. of Members</h5>
26+
</th>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
{% for team in object_list %}
31+
<tr>
32+
<td>
33+
<div>
34+
<h6 class="team-name">{{ team.name }}</h6>
35+
<p class="team-desc"><em>{{ team.description }}</em></p>
36+
</div>
37+
</td>
38+
<td class="text-center bold-text">
39+
{{ team.members_count }}
40+
{% if team.increased_count > 0 %}
41+
(<i class="fa fa-arrow-up light-green-color"
42+
aria-hidden="true">
43+
</i>
44+
{{ team.increased_count }} members)
45+
{% endif %}
46+
</td>
47+
</tr>
48+
{% endfor %}
49+
</tbody>
50+
</table>
51+
<p class="custom-green-color-font">Note: The increased members count
52+
refreshes every week.</p>
53+
</div>
54+
55+
{% endblock %}

0 commit comments

Comments
 (0)