Skip to content

Commit

Permalink
openhub/: Use openhub_django pypi package
Browse files Browse the repository at this point in the history
Overriding the default openhub_django URLs
so as to define new ones and pass the
header and footer context of webpages and
make openhub_django templates look similar
to that of commuity website.

Closes coala#285
  • Loading branch information
kvgarg authored and KVGarg committed Aug 3, 2019
1 parent 6e8b8dd commit b671c01
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ fi

# Run meta review system
python manage.py run_meta_review_system
# Run openhub system
python manage.py import_openhub_data

rm _site/$ISSUES_JSON

Expand Down
2 changes: 1 addition & 1 deletion .coafile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[all]
files = **.py, **.js, **.sh
ignore = .git/**, **/__pycache__/**, gci/client.py, */migrations/**, private/*, openhub/**, **/leaflet_dist/**
ignore = .git/**, **/__pycache__/**, gci/client.py, */migrations/**, private/*, **/leaflet_dist/**
max_line_length = 80
use_spaces = True
preferred_quotation = '
Expand Down
18 changes: 16 additions & 2 deletions community/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@
import os
import sys

from community.git import get_api_key, get_org_name
from community.config import TokenMissing

from .filters import NoDebugFilter

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Check environment variables needed by openhub-django
# If not, available, set these variables
try:
OH_TOKEN = get_api_key('OH')
except TokenMissing:
os.environ['OH_TOKEN'] = ''

ORG_NAME = os.environ.get('ORG_NAME')
if not ORG_NAME:
ORG_NAME = get_org_name()
os.environ['ORG_NAME'] = ORG_NAME

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

Expand All @@ -37,8 +52,7 @@
'gci',
'gsoc',
'data',
'openhub',
'model',
'openhub_django.apps.OpenhubDjangoConfig',
'gamification',
'meta_review',
'django.contrib.contenttypes',
Expand Down
122 changes: 3 additions & 119 deletions community/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
Community URL configuration.
"""

from django.conf.urls import url
from django.urls import include
from django_distill import distill_url
from django.conf.urls.static import static
from django.conf import settings
Expand All @@ -15,27 +16,6 @@
from gamification.views import GamificationResults
from meta_review.views import ContributorsMetaReview
from inactive_issues.inactive_issues_scraper import inactive_issues_json
from openhub.views import index as openhub_index
from model.views import index as model_index
from openhub.models import (
PortfolioProject,
OutsideCommitter,
AffiliatedCommitter,
OutsideProject,
Organization,
)
from model.views import (
PortfolioProjectListView,
PortfolioProjectDetailView,
AffiliatedCommitterListView,
AffiliatedCommitterDetailView,
OrganizationListView,
OrganizationDetailView,
OutsideProjectListView,
OutsideProjectDetailView,
OutsideCommitterListView,
OutsideCommitterDetailView,
)
from unassigned_issues.unassigned_issues_scraper import (
unassigned_issues_activity_json,
)
Expand All @@ -47,31 +27,6 @@ def get_index():
return None


def get_all_portfolioprojects():
for portfolioproject in PortfolioProject.objects.all():
yield {'pk': portfolioproject.id}


def get_all_outsidecommitters():
for outsidecommitter in OutsideCommitter.objects.all():
yield {'pk': outsidecommitter.id}


def get_all_outsideprojects():
for outsideproject in OutsideProject.objects.all():
yield {'pk': outsideproject.id}


def get_all_affiliatedcommitters():
for affiliatedcommitter in AffiliatedCommitter.objects.all():
yield {'pk': affiliatedcommitter.id}


def get_organization():
for organization in Organization.objects.all():
yield {'pk': organization.id}


urlpatterns = [
distill_url(
r'^$', HomePageView.as_view(),
Expand Down Expand Up @@ -127,78 +82,6 @@ def get_organization():
distill_func=get_index,
distill_file='static/inactive-issues.json',
),
distill_url(
r'openhub/$', openhub_index,
name='community-openhub',
distill_func=get_index,
distill_file='openhub/index.html',
),
distill_url(
r'model/$', model_index,
name='community-model',
distill_func=get_index,
distill_file='model/index.html',
),
distill_url(
r'model/openhub/outside_committers/$',
OutsideCommitterListView.as_view(),
name='outsidecommitters',
distill_func=get_index,
),
distill_url(
r'model/openhub/outside_committer/(?P<pk>\d+)/$',
OutsideCommitterDetailView.as_view(),
name='outsidecommitter-detail',
distill_func=get_all_outsidecommitters,
),
distill_url(
r'model/openhub/outside_projects/$',
OutsideProjectListView.as_view(),
name='outsideprojects',
distill_func=get_index,
),
distill_url(
r'model/openhub/outside_project/(?P<pk>\d+)/$',
OutsideProjectDetailView.as_view(),
name='outsideproject-detail',
distill_func=get_all_outsideprojects,
),
distill_url(
r'model/openhub/affiliated_committers/$',
AffiliatedCommitterListView.as_view(),
name='affiliatedcommitters',
distill_func=get_index,
),
distill_url(
r'model/openhub/affiliated_committer/(?P<pk>\d+)/$',
AffiliatedCommitterDetailView.as_view(),
name='affiliatedcommitter-detail',
distill_func=get_all_affiliatedcommitters,
),
distill_url(
r'model/openhub/portfolio_projects/$',
PortfolioProjectListView.as_view(),
name='portfolioprojects',
distill_func=get_index,
),
distill_url(
r'model/openhub/portfolio_project/(?P<pk>\d+)/$',
PortfolioProjectDetailView.as_view(),
name='portfolioproject-detail',
distill_func=get_all_portfolioprojects,
),
distill_url(
r'model/openhub/organization/$',
OrganizationListView.as_view(),
name='organization',
distill_func=get_index,
),
distill_url(
r'model/openhub/org/(?P<pk>\d+)/$',
OrganizationDetailView.as_view(),
name='org-detail',
distill_func=get_organization,
),
distill_url(
r'static/unassigned-issues.json', unassigned_issues_activity_json,
name='unassigned_issues_activity_json',
Expand All @@ -211,4 +94,5 @@ def get_organization():
distill_func=get_index,
distill_file='gamification/index.html',
),
url(r'openhub/', include('openhub.urls'))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
126 changes: 126 additions & 0 deletions openhub/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
"""
OpenHub-Django URL configuration.
"""

from django_distill import distill_url

from openhub_django.models import (
PortfolioProject,
OutsideCommitter,
AffiliatedCommitter,
OutsideProject,
Organization,
)
from .views import (
Homepage,
PortfolioProjectListView,
PortfolioProjectDetailView,
AffiliatedCommitterListView,
AffiliatedCommitterDetailView,
OrganizationListView,
OrganizationDetailView,
OutsideProjectListView,
OutsideProjectDetailView,
OutsideCommitterListView,
OutsideCommitterDetailView,
)


def get_index():
# The index URI regex, ^$, contains no parameters, named or otherwise.
# You can simply just return nothing here.
return None


def get_all_portfolioprojects():
for portfolioproject in PortfolioProject.objects.all():
yield {'pk': portfolioproject.id}


def get_all_outsidecommitters():
for outsidecommitter in OutsideCommitter.objects.all():
yield {'pk': outsidecommitter.id}


def get_all_outsideprojects():
for outsideproject in OutsideProject.objects.all():
yield {'pk': outsideproject.id}


def get_all_affiliatedcommitters():
for affiliatedcommitter in AffiliatedCommitter.objects.all():
yield {'pk': affiliatedcommitter.id}


def get_organization():
for organization in Organization.objects.all():
yield {'pk': organization.id}


urlpatterns = [
distill_url(
r'^$', Homepage.as_view(),
name='community-openhub',
distill_func=get_index,
),
distill_url(
r'outside_committers/$',
OutsideCommitterListView.as_view(),
name='outsidecommitters',
distill_func=get_index,
),
distill_url(
r'outside_committer/(?P<pk>\d+)/$',
OutsideCommitterDetailView.as_view(),
name='outsidecommitter-detail',
distill_func=get_all_outsidecommitters,
),
distill_url(
r'outside_projects/$',
OutsideProjectListView.as_view(),
name='outsideprojects',
distill_func=get_index,
),
distill_url(
r'outside_project/(?P<pk>\d+)/$',
OutsideProjectDetailView.as_view(),
name='outsideproject-detail',
distill_func=get_all_outsideprojects,
),
distill_url(
r'affiliated_committers/$',
AffiliatedCommitterListView.as_view(),
name='affiliatedcommitters',
distill_func=get_index,
),
distill_url(
r'affiliated_committer/(?P<pk>\d+)/$',
AffiliatedCommitterDetailView.as_view(),
name='affiliatedcommitter-detail',
distill_func=get_all_affiliatedcommitters,
),
distill_url(
r'portfolio_projects/$',
PortfolioProjectListView.as_view(),
name='portfolioprojects',
distill_func=get_index,
),
distill_url(
r'portfolio_project/(?P<pk>\d+)/$',
PortfolioProjectDetailView.as_view(),
name='portfolioproject-detail',
distill_func=get_all_portfolioprojects,
),
distill_url(
r'organization/$',
OrganizationListView.as_view(),
name='organization',
distill_func=get_index,
),
distill_url(
r'org/(?P<pk>\d+)/$',
OrganizationDetailView.as_view(),
name='org-detail',
distill_func=get_organization,
),
]
Loading

0 comments on commit b671c01

Please sign in to comment.