Skip to content

Commit c7dac59

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 fc7dd93 commit c7dac59

File tree

8 files changed

+146
-7
lines changed

8 files changed

+146
-7
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 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',

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
+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_20190727_1348'),
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

+24-5
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'){
@@ -25,7 +37,13 @@ $(document).ready(function(){
2537
$('.important-message').text(message);
2638
$('.form-submission-popup').css('display', 'block');
2739
}
28-
40+
else if(userAuthenticated === 'false'){
41+
$('.important-message').text(
42+
'You tried to access a webpage, which is available to only' +
43+
' authenticated users. Please join the community or Login(if' +
44+
' already a member of organization)');
45+
$('.form-submission-popup').css('display', 'block');
46+
}
2947

3048

3149
function activate_dropdown(){
@@ -41,7 +59,7 @@ $(document).ready(function(){
4159

4260
function check_user_authenticated_or_not() {
4361
if(Cookies.get('authenticated')){
44-
modify_html_elements('none', 'none','block', 'block', 'block');
62+
modify_html_elements('none', 'none','block', 'block', 'block', 'block');
4563
}
4664
}
4765

@@ -58,20 +76,21 @@ $(document).ready(function(){
5876
function modify_html_elements(popup_form_display, login_option_display,
5977
profile_option_display,
6078
logout__option_display,
61-
form_option_display) {
79+
form_option_display, teams_option_display) {
6280
$('.form-popup').css('display', popup_form_display);
6381
login_user_el.css('display', login_option_display);
6482
$('.user-profile').css('display', profile_option_display);
6583
logout_user_el.css('display', logout__option_display);
6684
$('.forms-dropdown-option').css('display', form_option_display);
85+
$('.teams-dropdown-option'.css('display', teams_option_display));
6786
}
6887

6988
function manipulate_web_page_data(oauth_provider, http_response_text) {
7089
var json_data = JSON.parse(http_response_text);
7190
if (json_data.valid) {
7291
Cookies.set('authenticated', true);
7392
Cookies.set('username', json_data.user);
74-
modify_html_elements('none', 'none','block', 'block', 'block');
93+
modify_html_elements('none', 'none','block', 'block', 'block', 'block');
7594
}
7695
else {
7796
display_error_message(oauth_provider, json_data.message);
@@ -136,7 +155,7 @@ $(document).ready(function(){
136155
logout_user_el.click(function () {
137156
Cookies.remove('authenticated');
138157
Cookies.remove('username');
139-
modify_html_elements('none', 'block','none', 'none', 'none');
158+
modify_html_elements('none', 'block','none', 'none', 'none', 'none');
140159
});
141160

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

templates/base.html

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

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

templates/teams.html

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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><h5>Team</h5></th>
22+
<th class="text-center"><h5>No. of Members</h5></th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
{% for team in object_list %}
27+
<tr>
28+
<td>
29+
<div>
30+
<h6 class="team-name">{{ team.name }}</h6>
31+
<p class="team-desc"><em>{{ team.description }}</em></p>
32+
</div>
33+
</td>
34+
<td class="text-center bold-text">
35+
{{ team.members_count }}
36+
{% if team.increased_count > 0 %}
37+
(<i class="fa fa-arrow-up light-green-color"
38+
aria-hidden="true">
39+
</i>
40+
{{ team.increased_count }} members)
41+
{% endif %}
42+
</td>
43+
</tr>
44+
{% endfor %}
45+
</tbody>
46+
</table>
47+
<p class="custom-green-color-font">Note: The increased members count
48+
refreshes every week.</p>
49+
</div>
50+
51+
{% endblock %}

0 commit comments

Comments
 (0)