Skip to content

Commit 8740cd4

Browse files
KVGargkvgarg
authored and
kvgarg
committed
Enhance the community website homepage
The enhancement includes addition of materialize css, JQuery, responsiveness, and easy-navigation of website features. The easy-navigatibility is achieved by adding a navbar with display of meta -review and gamification leaderboard on homepage. Apart from this, the activity graph url is omitted from website by displaying the graph itslef on the homepage on large devices. Closes #255
1 parent d76bcc2 commit 8740cd4

25 files changed

+996
-193
lines changed

.ci/build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ python manage.py fetch_deployed_data _site $ISSUES_JSON \
2727

2828
python manage.py migrate
2929
python manage.py import_contributors_data
30+
python manage.py create_org_cluster_map_and_activity_graph org_map
3031
python manage.py import_issues_data
3132
python manage.py import_merge_requests_data
3233
python manage.py create_config_data

.coafile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[all]
22
files = **.py, **.js, **.sh
3-
ignore = .git/**, **/__pycache__/**, gci/client.py, */migrations/**, private/*, openhub/**
3+
ignore = .git/**, **/__pycache__/**, gci/client.py, */migrations/**, private/*, openhub/**, **/leaflet_dist/**
44
max_line_length = 80
55
use_spaces = True
66
preferred_quotation = '
@@ -42,6 +42,7 @@ files = static/**/*.js
4242
bears = JSHintBear
4343
allow_unused_variables = True
4444
javascript_strictness = False
45+
environment_jquery = True
4546

4647
[all.yml]
4748
bears = YAMLLintBear

.moban.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ packages:
1616
- unassigned_issues
1717

1818
dependencies:
19+
- getorg~=0.3.1
1920
- git+https://gitlab.com/coala/coala-utils.git
2021
- git-url-parse
2122
- django>2.1,<2.2

activity/scraper.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def get_data(self):
136136
return self.data
137137

138138

139-
def activity_json(request):
139+
def activity_json(filename):
140140

141141
org_name = get_org_name()
142142

@@ -152,4 +152,5 @@ def activity_json(request):
152152
real_data = Scraper(parsed_json['issues'], datetime.datetime.today())
153153
real_data = real_data.get_data()
154154

155-
return HttpResponse(json.dumps(real_data))
155+
with open(filename, 'w+') as f:
156+
json.dump(real_data, f, indent=4)

community/urls.py

-14
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
from django_distill import distill_url
66
from django.conf.urls.static import static
77
from django.conf import settings
8-
from django.views.generic import TemplateView
98

109
from community.views import HomePageView, info
1110
from gci.views import index as gci_index
1211
from gci.feeds import LatestTasksFeed as gci_tasks_rss
13-
from activity.scraper import activity_json
1412
from twitter.view_twitter import index as twitter_index
1513
from log.view_log import index as log_index
1614
from data.views import index as contributors_index
@@ -87,18 +85,6 @@ def get_organization():
8785
distill_func=get_index,
8886
distill_file='info.txt',
8987
),
90-
distill_url(
91-
r'static/activity-data.json', activity_json,
92-
name='activity_json',
93-
distill_func=get_index,
94-
distill_file='static/activity-data.json',
95-
),
96-
distill_url(
97-
r'activity/', TemplateView.as_view(template_name='activity.html'),
98-
name='activity',
99-
distill_func=get_index,
100-
distill_file='activity/index.html',
101-
),
10288
distill_url(
10389
r'gci/tasks/rss.xml', gci_tasks_rss(),
10490
name='gci-tasks-rss',

community/views.py

+96-9
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,115 @@
1-
from django.http import HttpResponse
2-
from django.views.generic.base import TemplateView
1+
import logging
2+
3+
import requests
34

45
from trav import Travis
56

7+
from django.http import HttpResponse
8+
from django.views.generic.base import TemplateView
9+
610
from .git import (
711
get_deploy_url,
812
get_org_name,
913
get_owner,
1014
get_upstream_deploy_url,
15+
get_remote_url
1116
)
17+
from data.models import Team
18+
from gamification.models import Participant as GamificationParticipant
19+
from meta_review.models import Participant as MetaReviewer
20+
21+
22+
def initialize_org_context_details():
23+
org_name = get_org_name()
24+
org_details = {
25+
'name': org_name,
26+
'blog_url': f'https://blog.{org_name}.io/',
27+
'twitter_url': f'https://twitter.com/{org_name}_io/',
28+
'facebook_url': f'https://www.facebook.com/{org_name}Analyzer',
29+
'repo_url': get_remote_url().href,
30+
'docs': f'https://{org_name}.io/docs',
31+
'newcomer_docs': f'https://{org_name}.io/newcomer',
32+
'coc': f'https://{org_name}.io/coc',
33+
'logo_url': (f'https://api.{org_name}.io/en/latest/_static/images/'
34+
f'{org_name}_logo.svg'),
35+
'gitter_chat': f'https://gitter.im/{org_name}/{org_name}/',
36+
'github_core_repo': f'https://github.com/{org_name}/{org_name}/',
37+
'licence_type': 'GNU AGPL v3.0'
38+
}
39+
return org_details
40+
41+
42+
def get_header_and_footer(context):
43+
context['isTravis'] = Travis.TRAVIS
44+
context['travisLink'] = Travis.TRAVIS_BUILD_WEB_URL
45+
context['org'] = initialize_org_context_details()
46+
print('Running on Travis: {}, build link: {}'.format(context['isTravis'],
47+
context['travisLink']
48+
))
49+
return context
1250

1351

1452
class HomePageView(TemplateView):
1553
template_name = 'index.html'
1654

17-
def get_context_data(self, **kwargs):
18-
context = super().get_context_data(**kwargs)
19-
context['isTravis'] = Travis.TRAVIS
20-
context['travisLink'] = Travis.TRAVIS_BUILD_WEB_URL
55+
def get_team_details(self, org_name):
56+
teams = [
57+
f'{org_name} newcomers',
58+
f'{org_name} developers',
59+
f'{org_name} admins'
60+
]
61+
team_details = {}
62+
for team_name in teams:
63+
team = Team.objects.get(name=team_name)
64+
team_details[team_name] = team.contributors.count()
65+
return team_details
66+
67+
def get_quote_of_the_day(self):
68+
69+
try:
70+
qod = requests.get('http://quotes.rest/qod?category=inspire')
71+
qod.raise_for_status()
72+
except requests.HTTPError as err:
73+
error_info = f'HTTPError while fetching Quote of the day! {err}'
74+
logging.error(error_info)
75+
return
2176

22-
print('Running on Travis: {}, build link: {}'.format(
23-
context['isTravis'],
24-
context['travisLink']))
77+
qod_data = qod.json()
78+
return {
79+
'quote': qod_data['contents']['quotes'][0]['quote'],
80+
'author': qod_data['contents']['quotes'][0]['author'],
81+
}
2582

83+
def get_top_meta_review_users(self, count):
84+
participants = MetaReviewer.objects.all()[:count]
85+
return participants
86+
87+
def get_top_gamification_users(self, count):
88+
return enumerate(GamificationParticipant.objects.all()[:count])
89+
90+
def get_context_data(self, **kwargs):
91+
context = super().get_context_data(**kwargs)
92+
context = get_header_and_footer(context)
93+
org_name = context['org']['name']
94+
context['org']['team_details'] = dict(self.get_team_details(org_name))
95+
about_org = (f'{org_name} (always spelled with a lowercase c!) is one'
96+
' of the welcoming open-source organizations for'
97+
f' newcomers. {org_name} stands for “COde AnaLysis'
98+
' Application” as it works well with animals and thus is'
99+
' well visualizable which makes it easy to memorize.'
100+
f' {org_name} provides a unified interface for linting'
101+
' and fixing the code with a single configuration file,'
102+
' regardless of the programming languages used. You can'
103+
f' use {org_name} from within your favorite editor,'
104+
' integrate it with your CI and, get the results as JSON'
105+
', or customize it to your needs with its flexible'
106+
' configuration syntax.')
107+
context['org']['about'] = about_org
108+
context['quote_details'] = self.get_quote_of_the_day()
109+
context['top_meta_review_users'] = self.get_top_meta_review_users(
110+
count=5)
111+
context['top_gamification_users'] = self.get_top_gamification_users(
112+
count=5)
26113
return context
27114

28115

data/contrib_data.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ def get_contrib_data():
2828
def import_data(contributor):
2929
logger = logging.getLogger(__name__)
3030
login = contributor.get('login', None)
31-
teams = contributor.get('teams')
31+
teams = contributor.pop('teams')
3232
try:
3333
contributor['issues_opened'] = contributor.pop('issues')
3434
contributor['num_commits'] = contributor.pop('contributions')
35-
contributor_location = contributor.get('location')
36-
if contributor_location:
37-
contributor['location'] = contributor_location
38-
contributor.pop('teams')
35+
contributor['location'] = contributor.get('location')
3936
c, create = Contributor.objects.get_or_create(
4037
**contributor
4138
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django.core.management.base import BaseCommand
2+
3+
from data.org_cluster_map_handler import handle as org_cluster_map_handler
4+
from activity.scraper import activity_json
5+
6+
7+
class Command(BaseCommand):
8+
help = 'Create a cluster map using contributors geolocation'
9+
10+
def add_arguments(self, parser):
11+
parser.add_argument('output_dir', nargs='?', type=str)
12+
13+
def handle(self, *args, **options):
14+
output_dir = options.get('output_dir')
15+
if not output_dir:
16+
org_cluster_map_handler()
17+
else:
18+
org_cluster_map_handler(output_dir)
19+
# Fetch & Store data for activity graph to be displayed on home-page
20+
activity_json('static/activity-data.js')
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.1.7 on 2019-06-15 13:31
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('data', '0005_contributor_location'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='contributor',
15+
name='teams',
16+
field=models.ManyToManyField(related_name='contributors', to='data.Team'),
17+
),
18+
]

data/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Contributor(models.Model):
1616
reviews = models.IntegerField(default=None, null=True)
1717
issues_opened = models.IntegerField(default=None, null=True)
1818
location = models.TextField(default=None, null=True)
19-
teams = models.ManyToManyField(Team)
19+
teams = models.ManyToManyField(Team, related_name='contributors')
2020

2121
def __str__(self):
2222
return self.login

0 commit comments

Comments
 (0)