forked from coala/community
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 https://gitlab.com/coala/GSoC/gsoc-2019/issues/142
- Loading branch information
Showing
20 changed files
with
886 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
data/management/commands/create_org_cluster_map_and_activity_graph.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import logging | ||
import json | ||
import getorg | ||
import os | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from data.models import Contributor | ||
from activity.scraper import activity_json | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Create a cluster map using contributors geolocation' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('output_dir', nargs='?', type=str) | ||
|
||
def handle(self, *args, **options): | ||
logger = logging.getLogger(__name__) | ||
output_dir = options.get('output_dir') | ||
|
||
if not output_dir: | ||
logger.debug('output_dir arg not provided! Setting output_dir' | ||
' to cluster_map/') | ||
output_dir = 'cluster_map' | ||
|
||
class Location: | ||
|
||
def __init__(self, longitude, latitude): | ||
self.longitude = longitude | ||
self.latitude = latitude | ||
|
||
org_location_dict = {} | ||
|
||
for contrib in Contributor.objects.all(): | ||
if not contrib.login.startswith('testuser') and contrib.location: | ||
user_location = json.loads(contrib.location) | ||
location = Location(user_location['longitude'], | ||
user_location['latitude']) | ||
org_location_dict[contrib.login] = location | ||
logger.debug('{} location {} added on map'.format( | ||
contrib.login, user_location)) | ||
getorg.orgmap.output_html_cluster_map(org_location_dict, | ||
folder_name=output_dir) | ||
|
||
self.move_and_make_changes_in_files(output_dir) | ||
|
||
# Fetch data for activity graph to be displayed on home-page | ||
activity_json('static/activity-data.js') | ||
|
||
def move_and_make_changes_in_files(self, output_dir): | ||
# Move leaflet_dist folder to static folder | ||
leaflet_source_path = '{}/{}/leaflet_dist/'.format(os.getcwd(), | ||
output_dir) | ||
leaflet_destination_path = '{}/{}/leaflet_dist/'.format(os.getcwd(), | ||
'static') | ||
os.renames(leaflet_source_path, leaflet_destination_path) | ||
# Move org_locations.js to static folder | ||
locations_source_path = '{}/{}/org-locations.js'.format(os.getcwd(), | ||
output_dir) | ||
locations_destination_path = '{}/{}/org-locations.js'.format( | ||
os.getcwd(), 'static') | ||
os.rename(locations_source_path, locations_destination_path) | ||
# Change map.html to support django | ||
with open('{}/map.html'.format(output_dir)) as f: | ||
django_supported_htmls = [] | ||
lines = f.readlines() | ||
for index in range(len(lines)): | ||
line = lines[index].strip() | ||
if line.__contains__('<html>'): | ||
django_supported_htmls.append('{% load staticfiles %}\n') | ||
django_supported_htmls.append(line+'\n') | ||
elif line.__contains__('</head>'): | ||
adjust_prop = ''' | ||
<style> | ||
#map { | ||
width: 60%; | ||
height: 300px; | ||
margin: auto; | ||
box-shadow: 0px 0px 25px 2px; | ||
} | ||
@media only screen and (max-width:750px){ | ||
#map { | ||
width: 90% | ||
} | ||
} | ||
</style>\n | ||
''' | ||
meta_charset = '<meta charset="utf-8">' | ||
adjust_prop = adjust_prop.strip().replace(' ', '') | ||
django_supported_htmls.insert(6, meta_charset+'\n') | ||
django_supported_htmls.append(adjust_prop+'\n') | ||
django_supported_htmls.append(line+'\n') | ||
elif line.__contains__('https://'): | ||
line = line.replace('https:', '').replace(' />', '>') | ||
django_supported_htmls.append(line.strip()+'\n') | ||
elif line.__contains__('<link '): | ||
line = line.replace('href="', 'href="{% static \'') | ||
line = line.replace('.css', '.css\' %}').replace(' />', '>') | ||
django_supported_htmls.append(line+'\n') | ||
elif line.__contains__('<script '): | ||
line = line.replace('src="', 'src="{% static \'') | ||
line = line.replace('.js', '.js\' %}') | ||
if line.__contains__(' type="text/javascript"'): | ||
line = line.replace(' type="text/javascript"', '') | ||
django_supported_htmls.append(line+'\n') | ||
elif line.__contains__('Mouse over') or len(line) == 0: | ||
pass | ||
else: | ||
django_supported_htmls.append(line+'\n') | ||
# Add map.html to templates folder | ||
html_map_path = '{}/{}/map.html' | ||
html_map_source_path = html_map_path.format(os.getcwd(), | ||
output_dir) | ||
html_map_destination_path = html_map_path.format(os.getcwd(), | ||
'templates') | ||
os.remove(html_map_source_path) | ||
with open(html_map_destination_path, 'w+') as f: | ||
f.writelines(django_supported_htmls) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
getorg~=0.3.1 | ||
git+https://gitlab.com/coala/coala-utils.git | ||
git-url-parse | ||
django>2.1,<2.2 | ||
|
Oops, something went wrong.