Skip to content

Commit fc7dd93

Browse files
kvgargKVGarg
kvgarg
authored andcommitted
openhub/: Use openhub_django pypi package
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
1 parent 3b91d32 commit fc7dd93

File tree

8 files changed

+278
-123
lines changed

8 files changed

+278
-123
lines changed

.ci/build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ fi
4444

4545
# Run meta review system
4646
python manage.py run_meta_review_system
47+
# Run openhub system
48+
python manage.py import_openhub_data
4749

4850
rm _site/$ISSUES_JSON
4951

.coafile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[all]
22
files = **.py, **.js, **.sh
3-
ignore = .git/**, **/__pycache__/**, gci/client.py, */migrations/**, private/*, openhub/**, **/leaflet_dist/**
3+
ignore = .git/**, **/__pycache__/**, gci/client.py, */migrations/**, private/*, **/leaflet_dist/**
44
max_line_length = 80
55
use_spaces = True
66
preferred_quotation = '

community/settings.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,27 @@
1313
import os
1414
import sys
1515

16+
from community.git import get_api_key, get_org_name
17+
from community.config import TokenMissing
18+
1619
from .filters import NoDebugFilter
1720

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

2124

25+
# Check environment variables needed by openhub-django
26+
# If not, available, set these variables
27+
try:
28+
OH_TOKEN = get_api_key('OH')
29+
except TokenMissing:
30+
os.environ['OH_TOKEN'] = ''
31+
32+
ORG_NAME = os.environ.get('ORG_NAME')
33+
if not ORG_NAME:
34+
ORG_NAME = get_org_name()
35+
os.environ['ORG_NAME'] = ORG_NAME
36+
2237
# Quick-start development settings - unsuitable for production
2338
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
2439

@@ -37,8 +52,7 @@
3752
'gci',
3853
'gsoc',
3954
'data',
40-
'openhub',
41-
'model',
55+
'openhub_django.apps.OpenhubDjangoConfig',
4256
'gamification',
4357
'meta_review',
4458
'django.contrib.contenttypes',

community/urls.py

+3-119
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
22
Community URL configuration.
33
"""
4-
4+
from django.conf.urls import url
5+
from django.urls import include
56
from django_distill import distill_url
67
from django.conf.urls.static import static
78
from django.conf import settings
@@ -15,27 +16,6 @@
1516
from gamification.views import GamificationResults
1617
from meta_review.views import ContributorsMetaReview
1718
from inactive_issues.inactive_issues_scraper import inactive_issues_json
18-
from openhub.views import index as openhub_index
19-
from model.views import index as model_index
20-
from openhub.models import (
21-
PortfolioProject,
22-
OutsideCommitter,
23-
AffiliatedCommitter,
24-
OutsideProject,
25-
Organization,
26-
)
27-
from model.views import (
28-
PortfolioProjectListView,
29-
PortfolioProjectDetailView,
30-
AffiliatedCommitterListView,
31-
AffiliatedCommitterDetailView,
32-
OrganizationListView,
33-
OrganizationDetailView,
34-
OutsideProjectListView,
35-
OutsideProjectDetailView,
36-
OutsideCommitterListView,
37-
OutsideCommitterDetailView,
38-
)
3919
from unassigned_issues.unassigned_issues_scraper import (
4020
unassigned_issues_activity_json,
4121
)
@@ -47,31 +27,6 @@ def get_index():
4727
return None
4828

4929

50-
def get_all_portfolioprojects():
51-
for portfolioproject in PortfolioProject.objects.all():
52-
yield {'pk': portfolioproject.id}
53-
54-
55-
def get_all_outsidecommitters():
56-
for outsidecommitter in OutsideCommitter.objects.all():
57-
yield {'pk': outsidecommitter.id}
58-
59-
60-
def get_all_outsideprojects():
61-
for outsideproject in OutsideProject.objects.all():
62-
yield {'pk': outsideproject.id}
63-
64-
65-
def get_all_affiliatedcommitters():
66-
for affiliatedcommitter in AffiliatedCommitter.objects.all():
67-
yield {'pk': affiliatedcommitter.id}
68-
69-
70-
def get_organization():
71-
for organization in Organization.objects.all():
72-
yield {'pk': organization.id}
73-
74-
7530
urlpatterns = [
7631
distill_url(
7732
r'^$', HomePageView.as_view(),
@@ -127,78 +82,6 @@ def get_organization():
12782
distill_func=get_index,
12883
distill_file='static/inactive-issues.json',
12984
),
130-
distill_url(
131-
r'openhub/$', openhub_index,
132-
name='community-openhub',
133-
distill_func=get_index,
134-
distill_file='openhub/index.html',
135-
),
136-
distill_url(
137-
r'model/$', model_index,
138-
name='community-model',
139-
distill_func=get_index,
140-
distill_file='model/index.html',
141-
),
142-
distill_url(
143-
r'model/openhub/outside_committers/$',
144-
OutsideCommitterListView.as_view(),
145-
name='outsidecommitters',
146-
distill_func=get_index,
147-
),
148-
distill_url(
149-
r'model/openhub/outside_committer/(?P<pk>\d+)/$',
150-
OutsideCommitterDetailView.as_view(),
151-
name='outsidecommitter-detail',
152-
distill_func=get_all_outsidecommitters,
153-
),
154-
distill_url(
155-
r'model/openhub/outside_projects/$',
156-
OutsideProjectListView.as_view(),
157-
name='outsideprojects',
158-
distill_func=get_index,
159-
),
160-
distill_url(
161-
r'model/openhub/outside_project/(?P<pk>\d+)/$',
162-
OutsideProjectDetailView.as_view(),
163-
name='outsideproject-detail',
164-
distill_func=get_all_outsideprojects,
165-
),
166-
distill_url(
167-
r'model/openhub/affiliated_committers/$',
168-
AffiliatedCommitterListView.as_view(),
169-
name='affiliatedcommitters',
170-
distill_func=get_index,
171-
),
172-
distill_url(
173-
r'model/openhub/affiliated_committer/(?P<pk>\d+)/$',
174-
AffiliatedCommitterDetailView.as_view(),
175-
name='affiliatedcommitter-detail',
176-
distill_func=get_all_affiliatedcommitters,
177-
),
178-
distill_url(
179-
r'model/openhub/portfolio_projects/$',
180-
PortfolioProjectListView.as_view(),
181-
name='portfolioprojects',
182-
distill_func=get_index,
183-
),
184-
distill_url(
185-
r'model/openhub/portfolio_project/(?P<pk>\d+)/$',
186-
PortfolioProjectDetailView.as_view(),
187-
name='portfolioproject-detail',
188-
distill_func=get_all_portfolioprojects,
189-
),
190-
distill_url(
191-
r'model/openhub/organization/$',
192-
OrganizationListView.as_view(),
193-
name='organization',
194-
distill_func=get_index,
195-
),
196-
distill_url(
197-
r'model/openhub/org/(?P<pk>\d+)/$',
198-
OrganizationDetailView.as_view(),
199-
name='org-detail',
200-
distill_func=get_organization,
201-
),
20285
distill_url(
20386
r'static/unassigned-issues.json', unassigned_issues_activity_json,
20487
name='unassigned_issues_activity_json',
@@ -211,4 +94,5 @@ def get_organization():
21194
distill_func=get_index,
21295
distill_file='gamification/index.html',
21396
),
97+
url(r'openhub/', include('openhub.urls'))
21498
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

openhub/urls.py

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""
2+
OpenHub-Django URL configuration.
3+
"""
4+
5+
from django_distill import distill_url
6+
7+
from openhub_django.models import (
8+
PortfolioProject,
9+
OutsideCommitter,
10+
AffiliatedCommitter,
11+
OutsideProject,
12+
Organization,
13+
)
14+
from .views import (
15+
Homepage,
16+
PortfolioProjectListView,
17+
PortfolioProjectDetailView,
18+
AffiliatedCommitterListView,
19+
AffiliatedCommitterDetailView,
20+
OrganizationListView,
21+
OrganizationDetailView,
22+
OutsideProjectListView,
23+
OutsideProjectDetailView,
24+
OutsideCommitterListView,
25+
OutsideCommitterDetailView,
26+
)
27+
28+
29+
def get_index():
30+
# The index URI regex, ^$, contains no parameters, named or otherwise.
31+
# You can simply just return nothing here.
32+
return None
33+
34+
35+
def get_all_portfolioprojects():
36+
for portfolioproject in PortfolioProject.objects.all():
37+
yield {'pk': portfolioproject.id}
38+
39+
40+
def get_all_outsidecommitters():
41+
for outsidecommitter in OutsideCommitter.objects.all():
42+
yield {'pk': outsidecommitter.id}
43+
44+
45+
def get_all_outsideprojects():
46+
for outsideproject in OutsideProject.objects.all():
47+
yield {'pk': outsideproject.id}
48+
49+
50+
def get_all_affiliatedcommitters():
51+
for affiliatedcommitter in AffiliatedCommitter.objects.all():
52+
yield {'pk': affiliatedcommitter.id}
53+
54+
55+
def get_organization():
56+
for organization in Organization.objects.all():
57+
yield {'pk': organization.id}
58+
59+
60+
urlpatterns = [
61+
distill_url(
62+
r'^$', Homepage.as_view(),
63+
name='community-openhub',
64+
distill_func=get_index,
65+
),
66+
distill_url(
67+
r'outside_committers/$',
68+
OutsideCommitterListView.as_view(),
69+
name='outsidecommitters',
70+
distill_func=get_index,
71+
),
72+
distill_url(
73+
r'outside_committer/(?P<pk>\d+)/$',
74+
OutsideCommitterDetailView.as_view(),
75+
name='outsidecommitter-detail',
76+
distill_func=get_all_outsidecommitters,
77+
),
78+
distill_url(
79+
r'outside_projects/$',
80+
OutsideProjectListView.as_view(),
81+
name='outsideprojects',
82+
distill_func=get_index,
83+
),
84+
distill_url(
85+
r'outside_project/(?P<pk>\d+)/$',
86+
OutsideProjectDetailView.as_view(),
87+
name='outsideproject-detail',
88+
distill_func=get_all_outsideprojects,
89+
),
90+
distill_url(
91+
r'affiliated_committers/$',
92+
AffiliatedCommitterListView.as_view(),
93+
name='affiliatedcommitters',
94+
distill_func=get_index,
95+
),
96+
distill_url(
97+
r'affiliated_committer/(?P<pk>\d+)/$',
98+
AffiliatedCommitterDetailView.as_view(),
99+
name='affiliatedcommitter-detail',
100+
distill_func=get_all_affiliatedcommitters,
101+
),
102+
distill_url(
103+
r'portfolio_projects/$',
104+
PortfolioProjectListView.as_view(),
105+
name='portfolioprojects',
106+
distill_func=get_index,
107+
),
108+
distill_url(
109+
r'portfolio_project/(?P<pk>\d+)/$',
110+
PortfolioProjectDetailView.as_view(),
111+
name='portfolioproject-detail',
112+
distill_func=get_all_portfolioprojects,
113+
),
114+
distill_url(
115+
r'organization/$',
116+
OrganizationListView.as_view(),
117+
name='organization',
118+
distill_func=get_index,
119+
),
120+
distill_url(
121+
r'org/(?P<pk>\d+)/$',
122+
OrganizationDetailView.as_view(),
123+
name='org-detail',
124+
distill_func=get_organization,
125+
),
126+
]

0 commit comments

Comments
 (0)