-
Notifications
You must be signed in to change notification settings - Fork 45
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 #255
- Loading branch information
Showing
28 changed files
with
983 additions
and
234 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
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
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from data.org_cluster_map_handler import handle as org_cluster_map_handler | ||
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): | ||
output_dir = options.get('output_dir') | ||
if not output_dir: | ||
org_cluster_map_handler() | ||
else: | ||
org_cluster_map_handler(output_dir) | ||
# Fetch & Store data for activity graph to be displayed on home-page | ||
activity_json('static/activity-data.js') |
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,18 @@ | ||
# Generated by Django 2.1.7 on 2019-08-01 17:52 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('data', '0005_auto_20190801_1442'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='contributor', | ||
name='teams', | ||
field=models.ManyToManyField(related_name='contributors', to='data.Team'), | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import os | ||
import json | ||
|
||
import logging | ||
|
||
import getorg | ||
|
||
from data.models import Contributor | ||
|
||
|
||
def handle(output_dir='cluster_map'): | ||
""" | ||
Creates a organization cluster map using the contributors location | ||
stored in the database | ||
:param output_dir: Directory where all the required CSS and JS files | ||
are copied by 'getorg' package | ||
""" | ||
logger = logging.getLogger(__name__) | ||
logger.info("'cluster_map/' is the default directory for storing" | ||
" organization map related files. If arg 'output_dir'" | ||
' not provided it will be used as a default directory by' | ||
" 'getorg' package.") | ||
|
||
# For creating the organization map, the 'getorg' uses a 'Nominatim' named | ||
# package which geocodes the contributor location and then uses that class | ||
# to create the map. Since, we're not dealing with that function which use | ||
# that 'Nominatim' package because we're fetching a JSON data and storing | ||
# it in our db. Therefore, defining our own simple class that can aid us | ||
# to create a cluster map. | ||
class Location: | ||
|
||
def __init__(self, longitude, latitude): | ||
self.longitude = longitude | ||
self.latitude = latitude | ||
|
||
org_location_dict = {} | ||
|
||
for contrib in Contributor.objects.filter(location__isnull=False): | ||
user_location = json.loads(contrib.location) | ||
location = Location(user_location['longitude'], | ||
user_location['latitude']) | ||
org_location_dict[contrib.login] = location | ||
logger.debug(f'{contrib.login} location {user_location} added on map') | ||
getorg.orgmap.output_html_cluster_map(org_location_dict, | ||
folder_name=output_dir) | ||
|
||
move_and_make_changes_in_files(output_dir) | ||
|
||
|
||
def move_and_make_changes_in_files(output_dir): | ||
""" | ||
Move static files from 'output_dir' to django static folder which | ||
is being required by the map.html which is being auto-generated | ||
by getorg. | ||
:param output_dir: Directory from where the files have to be moved | ||
""" | ||
|
||
move_leaflet_dist_folder(output_dir) | ||
|
||
os.rename( | ||
src=get_file_path(os.getcwd(), output_dir, 'org-locations.js'), | ||
dst=get_file_path(os.getcwd(), 'static', 'org-locations.js') | ||
) | ||
|
||
os.remove(get_file_path(os.getcwd(), output_dir, 'map.html')) | ||
|
||
|
||
def move_leaflet_dist_folder(output_dir): | ||
source_path = get_file_path(os.getcwd(), output_dir, 'leaflet_dist') | ||
destination_path = get_file_path(os.getcwd(), 'static', 'leaflet_dist') | ||
|
||
# Remove existing leaflet_dir if exists | ||
for root, dirs, files in os.walk(destination_path): | ||
for file in files: | ||
os.remove(os.path.join(destination_path, file)) | ||
os.rmdir(root) | ||
|
||
os.renames(source_path, destination_path) | ||
|
||
|
||
def get_file_path(*args): | ||
return '/'.join(args) |
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,22 @@ | ||
from django.test import TestCase | ||
|
||
from data.models import Contributor | ||
from data.org_cluster_map_handler import handle as org_cluster_map_handler | ||
|
||
|
||
class CreateOrgClusterMapAndActivityGraphTest(TestCase): | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
Contributor.objects.create(login='test', | ||
name='Test User', | ||
location='{"latitude": 12.9,' | ||
'"longitude": 77.8}') | ||
Contributor.objects.create(login='testuser', | ||
name='Test User 2') | ||
|
||
def test_with_output_dir(self): | ||
org_cluster_map_handler() | ||
|
||
def test_without_output_dir(self): | ||
org_cluster_map_handler(output_dir='org_map') |
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.