Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
kvgarg authored and KVGarg committed Aug 5, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent da7f253 commit 86db04a
Showing 11 changed files with 276 additions and 127 deletions.
2 changes: 2 additions & 0 deletions .ci/build.sh
Original file line number Diff line number Diff line change
@@ -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

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 = '
1 change: 1 addition & 0 deletions .moban.yaml
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ dependencies:
- git+https://gitlab.com/gitmate/open-source/IGitt.git@1fa5a0a21ea4fb8739d467c06972f748717adbdc
- requests
- git+https://github.com/andrewda/trav.git@ce805d12d3d1db0a51b1aa26bba9cd9ecc0d96b8
- openhub-django~=0.1.0
- python-dateutil
- pillow
- ruamel.yaml
1 change: 0 additions & 1 deletion .nocover.yaml
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ nocover_file_globs:
- gsoc/*.py
- ci_build/*.py
- meta_review/handler.py
- openhub/*.py
# Optional coverage. Once off scripts.
- inactive_issues/inactive_issues_scraper.py
- unassigned_issues/unassigned_issues_scraper.py
15 changes: 13 additions & 2 deletions community/settings.py
Original file line number Diff line number Diff line change
@@ -13,12 +13,24 @@
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__)))


# Set Environment variables needed by OpenHub-Django package
try:
OH_TOKEN = get_api_key('OH')
except TokenMissing:
os.environ['OH_TOKEN'] = ''

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/

@@ -37,8 +49,7 @@
'gci',
'gsoc',
'data',
'openhub',
'model',
'openhub_django.apps.OpenhubDjangoConfig',
'gamification',
'meta_review',
'django.contrib.contenttypes',
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
@@ -14,27 +15,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,
)
@@ -46,31 +26,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(),
@@ -120,78 +75,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',
@@ -204,4 +87,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,
),
]
129 changes: 129 additions & 0 deletions openhub/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
from django.views import generic

from community.views import get_header_and_footer
from openhub_django.models import (
PortfolioProject,
OutsideProject,
OutsideCommitter,
AffiliatedCommitter,
Organization,
)


class Homepage(generic.TemplateView):
template_name = 'openhub_django/index.html'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
context['portfolioprojects'] = 'portfolio_projects'
context['outsidecommitters'] = 'outside_committers'
context['affiliatedcommitters'] = 'affiliated_committers'
context['outsideprojects'] = 'outside_projects'
context['organization'] = 'organization'
return context


class PortfolioProjectListView(generic.ListView):
model = PortfolioProject
context_object_name = 'portfolio_project_list'
template_name = 'openhub_django/portfolioproject_list.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context


class PortfolioProjectDetailView(generic.DetailView):
model = PortfolioProject
template_name = 'openhub_django/portfolioproject_detail.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context


class OutsideProjectListView(generic.ListView):
model = OutsideProject
context_object_name = 'outside_project_list'
template_name = 'openhub_django/outsideproject_list.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context


class OutsideProjectDetailView(generic.DetailView):
model = OutsideProject
template_name = 'openhub_django/outsideproject_detail.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context


class OutsideCommitterListView(generic.ListView):
model = OutsideCommitter
context_object_name = 'outside_committer_list'
template_name = 'openhub_django/outsidecommitter_list.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context


class OutsideCommitterDetailView(generic.DetailView):
model = OutsideCommitter
template_name = 'openhub_django/outsidecommitter_detail.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context


class AffiliatedCommitterListView(generic.ListView):
model = AffiliatedCommitter
context_object_name = 'affiliated_committer_list'
template_name = 'openhub_django/affiliatedcommitter_list.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context


class AffiliatedCommitterDetailView(generic.DetailView):
model = AffiliatedCommitter
template_name = 'openhub_django/affiliatedcommitter_detail.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context


class OrganizationListView(generic.ListView):
model = Organization
context_object_name = 'organization_list'
template_name = 'openhub_django/organization_list.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context


class OrganizationDetailView(generic.DetailView):
model = Organization
template_name = 'openhub_django/organization_detail.html'

def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
return context
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ django-eventtools
git+https://gitlab.com/gitmate/open-source/IGitt.git@1fa5a0a21ea4fb8739d467c06972f748717adbdc
requests
git+https://github.com/andrewda/trav.git@ce805d12d3d1db0a51b1aa26bba9cd9ecc0d96b8
openhub-django~=0.1.0
python-dateutil
pillow
ruamel.yaml
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ testpaths =
gamification
ci_build
meta_review
model
unassigned_issues

python_files = test_*.py
@@ -71,7 +70,6 @@ source =
gamification
ci_build
meta_review
model
unassigned_issues

omit =
@@ -82,7 +80,6 @@ omit =
gsoc/*.py
ci_build/*.py
meta_review/handler.py
openhub/*.py
inactive_issues/inactive_issues_scraper.py
unassigned_issues/unassigned_issues_scraper.py
*/migrations/*.py
1 change: 0 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
@@ -86,7 +86,6 @@

<ul id="openhub-dropdown" class="dropdown-content">
<li><a href="{% url 'community-openhub' %}">Org. Portfolio Projects</a></li>
<li><a href="{% url 'community-model' %}">Imported data</a></li>
</ul>

<ul id="forms-dropdown" class="dropdown-content">

0 comments on commit 86db04a

Please sign in to comment.