Skip to content

Commit 6fe3e7f

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 8daed65 commit 6fe3e7f

File tree

8 files changed

+149
-6
lines changed

8 files changed

+149
-6
lines changed

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 ci_build.view_log import BuildLogsView
@@ -39,6 +42,12 @@ def get_index():
3942
distill_func=get_index,
4043
distill_file='join/index.html',
4144
),
45+
distill_url(
46+
r'teams/', OrganizationTeams.as_view(),
47+
name='org-teams',
48+
distill_func=get_index,
49+
distill_file='teams/index.html',
50+
),
4251
distill_url(
4352
r'gci/tasks/rss.xml', gci_tasks_rss(),
4453
name='gci-tasks-rss',

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,
@@ -209,3 +210,14 @@ def get_context_data(self, **kwargs):
209210
'JOIN_COMMUNITY_FORM_NAME', None
210211
)
211212
return context
213+
214+
215+
class OrganizationTeams(ListView):
216+
217+
template_name = 'teams.html'
218+
model = Team
219+
220+
def get_context_data(self, **kwargs):
221+
context = super().get_context_data(**kwargs)
222+
context = get_header_and_footer(context)
223+
return context
+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+
]

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

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+
}

static/js/main.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ $(document).ready(function(){
88
var formSubmitted = urlParams.get('form_submitted');
99
var formType = urlParams.get('form_type');
1010

11+
var userAuthenticated = urlParams.get('auth');
12+
13+
var current_search_location = window.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+
1122
if(formSubmitted==='True'){
1223
var message = '';
1324
if(formType==='login'){
@@ -30,6 +41,13 @@ $(document).ready(function(){
3041
$('.important-message').text(message);
3142
$('.form-submission-popup').css('display', 'block');
3243
}
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+
}
3351

3452
function activate_dropdown(){
3553
if ($('nav').width() < 992 ){
@@ -44,7 +62,7 @@ $(document).ready(function(){
4462

4563
function check_user_authenticated_or_not() {
4664
if(Cookies.get('authenticated')){
47-
modify_html_elements('none', 'none','block', 'block');
65+
modify_html_elements('none', 'none','block', 'block', 'block');
4866
}
4967
}
5068

@@ -60,11 +78,12 @@ $(document).ready(function(){
6078

6179
function modify_html_elements(popup_form_display, login_option_display,
6280
logout__option_display,
63-
form_option_display) {
81+
form_option_display, teams_option_display) {
6482
$('.form-popup').css('display', popup_form_display);
6583
login_user_el.css('display', login_option_display);
6684
logout_user_el.css('display', logout__option_display);
6785
$('.forms-dropdown-option').css('display', form_option_display);
86+
$('.teams-dropdown-option').css('display', teams_option_display);
6887
}
6988

7089
function manipulate_web_page_data(oauth_provider, http_response_text) {
@@ -73,7 +92,7 @@ $(document).ready(function(){
7392
// Cookies expires in 3 days
7493
Cookies.set('authenticated', true, {expires: 3});
7594
Cookies.set('username', json_data.user, {expires: 3});
76-
modify_html_elements('none', 'none','block', 'block');
95+
modify_html_elements('none', 'none','block', 'block', 'block');
7796
}
7897
else {
7998
display_error_message(oauth_provider, json_data.message);
@@ -144,7 +163,7 @@ $(document).ready(function(){
144163
logout_user_el.click(function () {
145164
Cookies.remove('authenticated');
146165
Cookies.remove('username');
147-
modify_html_elements('none', 'block','none', 'none');
166+
modify_html_elements('none', 'block','none', 'none', 'none');
148167
});
149168

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

templates/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</ul>
6868

6969
<ul id="organisation-dropdown" class="dropdown-content">
70-
<li><a href="#">Teams</a></li>
70+
<li class="teams-dropdown-option display-none"><a href="{% url 'org-teams' %}" class="">Teams</a></li>
7171
<li><a href="{% url 'community-data' %}">Contributors Information</a></li>
7272
<li><a href="#">Mentors</a></li>
7373
<li><a href="{% url 'community-gci' %}">Google Code-in Students</a></li>

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)