diff --git a/.ci/build.sh b/.ci/build.sh index 56c2be06..b6613ffc 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -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 diff --git a/.coafile b/.coafile index d2942cee..1444f2e3 100644 --- a/.coafile +++ b/.coafile @@ -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 = ' diff --git a/community/settings.py b/community/settings.py index fa375669..fec0c803 100644 --- a/community/settings.py +++ b/community/settings.py @@ -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', None) +if ORG_NAME is None: + 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 +52,7 @@ 'gci', 'gsoc', 'data', - 'openhub', - 'model', + 'openhub_django.apps.OpenhubDjangoConfig', 'gamification', 'meta_review', 'django.contrib.contenttypes', diff --git a/community/urls.py b/community/urls.py index 287bae25..4c86bd59 100644 --- a/community/urls.py +++ b/community/urls.py @@ -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 @@ -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, ) @@ -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(), @@ -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\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\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\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\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\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', @@ -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) diff --git a/openhub/urls.py b/openhub/urls.py index e69de29b..51f1a797 100644 --- a/openhub/urls.py +++ b/openhub/urls.py @@ -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\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\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\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\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\d+)/$', + OrganizationDetailView.as_view(), + name='org-detail', + distill_func=get_organization, + ), +] diff --git a/openhub/views.py b/openhub/views.py index e69de29b..2a5f8bb5 100644 --- a/openhub/views.py +++ b/openhub/views.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 5c915a34..b47521b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/templates/base.html b/templates/base.html index 6db2a31f..aa55e9d0 100644 --- a/templates/base.html +++ b/templates/base.html @@ -93,7 +93,6 @@