-
Notifications
You must be signed in to change notification settings - Fork 45
Redesign homepage #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Redesign homepage #250
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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): | ||
KVGarg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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 hidden or 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 hidden or 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): | ||
KVGarg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this sug
2DDB
gestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.