From 9c5c705cd095b4c9608741d6b03c309409cd5f9a Mon Sep 17 00:00:00 2001 From: Bruno Amaral Date: Thu, 31 Mar 2022 22:59:52 +0100 Subject: [PATCH 1/3] move dockerfile to correct context --- Dockerfile.django => django/Dockerfile.django | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Dockerfile.django => django/Dockerfile.django (100%) diff --git a/Dockerfile.django b/django/Dockerfile.django similarity index 100% rename from Dockerfile.django rename to django/Dockerfile.django From fdae5fd368863870811b4df45e022c7da35800b0 Mon Sep 17 00:00:00 2001 From: Bruno Amaral Date: Thu, 31 Mar 2022 23:01:57 +0100 Subject: [PATCH 2/3] create rss app and bind urls --- django/admin/urls.py | 32 +++++++------ django/rss/__init__.py | 0 django/rss/admin.py | 3 ++ django/rss/apps.py | 6 +++ django/rss/migrations/__init__.py | 0 django/rss/models.py | 3 ++ django/rss/tests.py | 3 ++ django/rss/views.py | 78 +++++++++++++++++++++++++++++++ 8 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 django/rss/__init__.py create mode 100644 django/rss/admin.py create mode 100644 django/rss/apps.py create mode 100644 django/rss/migrations/__init__.py create mode 100644 django/rss/models.py create mode 100644 django/rss/tests.py create mode 100644 django/rss/views.py diff --git a/django/admin/urls.py b/django/admin/urls.py index 8c73c3a8..fc2c2b3f 100644 --- a/django/admin/urls.py +++ b/django/admin/urls.py @@ -16,25 +16,31 @@ from django.contrib import admin from django.urls import include, path, re_path from rest_framework import routers -from api import views +from api.views import * +from rss.views import * router = routers.DefaultRouter() -router.register(r'articles', views.ArticleViewSet, views.RelevantList) -router.register(r'trials', views.TrialViewSet) -router.register(r'sources', views.SourceViewSet) +router.register(r'articles', ArticleViewSet, RelevantList) +router.register(r'trials', TrialViewSet) +router.register(r'sources', SourceViewSet) urlpatterns = [ path('admin/', admin.site.urls), path('api-auth/', include('rest_framework.urls')), - path('articles/all/', views.AllArticleViewSet.as_view()), - path('trials/all/', views.AllTrialViewSet.as_view()), - re_path('^articles/relevant/$', views.RelevantList.as_view()), - path('articles/prediction/none/', views.ArticlesPredictionNone.as_view()), - re_path('^articles/source/(?P.+)/$', views.ArticlesBySourceList.as_view()), - re_path('^trials/source/(?P.+)/$', views.TrialsBySourceList.as_view()), - re_path('^articles/unsent/$', views.UnsentList.as_view()), - path('articles/related/', views.RelatedArticles.as_view({'get': 'list'})), - path('articles/count/', views.ArticlesCount.as_view({'get': 'list'})), + path('articles/all/', AllArticleViewSet.as_view()), + path('trials/all/', AllTrialViewSet.as_view()), + re_path('^articles/relevant/$', RelevantList.as_view()), + path('articles/prediction/none/', ArticlesPredictionNone.as_view()), + re_path('^articles/source/(?P.+)/$', ArticlesBySourceList.as_view()), + re_path('^trials/source/(?P.+)/$', TrialsBySourceList.as_view()), + re_path('^articles/unsent/$', UnsentList.as_view()), + path('articles/related/', RelatedArticles.as_view({'get': 'list'})), + path('articles/count/', ArticlesCount.as_view({'get': 'list'})), path('', include(router.urls)), + path('latest/articles/feed/', LatestArticlesFeed()), + path('latest/trials/feed/', LatestTrialsFeed()), + path('machine-learning/feed/', MachineLearningFeed()), + path('articles/prediction/none/feed/', ToPredictFeed()), + ] diff --git a/django/rss/__init__.py b/django/rss/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/django/rss/admin.py b/django/rss/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/django/rss/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/django/rss/apps.py b/django/rss/apps.py new file mode 100644 index 00000000..a7118809 --- /dev/null +++ b/django/rss/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class RssConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'rss' diff --git a/django/rss/migrations/__init__.py b/django/rss/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/django/rss/models.py b/django/rss/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/django/rss/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/django/rss/tests.py b/django/rss/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/django/rss/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/django/rss/views.py b/django/rss/views.py new file mode 100644 index 00000000..2e5a781a --- /dev/null +++ b/django/rss/views.py @@ -0,0 +1,78 @@ +from django.shortcuts import render + +# Create your views here. +from django.contrib.syndication.views import Feed +from django.urls import reverse +from gregory.models import Articles, Trials + +class LatestArticlesFeed(Feed): + title = "Gregory MS - latest research articles" + link = "/articles/" + description = "Real time results for research on Multiple Sclerosis." + + def items(self): + return Articles.objects.order_by('-discovery_date')[:5] + + def item_title(self, item): + return item.title + + def item_description(self, item): + return item.summary + + # # item_link is only needed if NewsItem has no get_absolute_url method. + def item_link(self, item): + return 'https://gregory-ms.com/articles/' + str(item.pk) + '/' + +class LatestTrialsFeed(Feed): + title = "Gregory MS - latest clinical trials" + link = "/trials/" + description = "Real time results for research on Multiple Sclerosis." + + def items(self): + return Trials.objects.order_by('-discovery_date')[:5] + + def item_title(self, item): + return item.title + + def item_description(self, item): + return item.summary + + # # item_link is only needed if NewsItem has no get_absolute_url method. + def item_link(self, item): + return 'https://gregory-ms.com/trials/' + str(item.pk) + '/' + +class MachineLearningFeed(Feed): + title = "Gregory MS - Relevant articles by machine learning" + link = "/articles/" + description = "Real time results for research on Multiple Sclerosis." + + def items(self): + return Articles.objects.filter(ml_prediction_gnb=True)[:20] + + def item_title(self, item): + return item.title + + def item_description(self, item): + return item.summary + + # # item_link is only needed if NewsItem has no get_absolute_url method. + def item_link(self, item): + return 'https://gregory-ms.com/articles/' + str(item.pk) + '/' + +class ToPredictFeed(Feed): + title = "Gregory MS - Relevant articles by machine learning" + link = "/articles/" + description = "Real time results for research on Multiple Sclerosis." + + def items(self): + return Articles.objects.filter(ml_prediction_gnb=None)[:20] + + def item_title(self, item): + return item.title + + def item_description(self, item): + return item.summary + + # # item_link is only needed if NewsItem has no get_absolute_url method. + def item_link(self, item): + return 'https://gregory-ms.com/articles/' + str(item.pk) + '/' \ No newline at end of file From 608b23332123e6a5a2996b8101c58b590808d157 Mon Sep 17 00:00:00 2001 From: Bruno Amaral Date: Thu, 31 Mar 2022 23:05:59 +0100 Subject: [PATCH 3/3] make sure to separate feeds from API --- django/admin/urls.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/django/admin/urls.py b/django/admin/urls.py index fc2c2b3f..c7e6246d 100644 --- a/django/admin/urls.py +++ b/django/admin/urls.py @@ -38,9 +38,9 @@ path('articles/related/', RelatedArticles.as_view({'get': 'list'})), path('articles/count/', ArticlesCount.as_view({'get': 'list'})), path('', include(router.urls)), - path('latest/articles/feed/', LatestArticlesFeed()), - path('latest/trials/feed/', LatestTrialsFeed()), - path('machine-learning/feed/', MachineLearningFeed()), - path('articles/prediction/none/feed/', ToPredictFeed()), + path('feed/latest/articles/', LatestArticlesFeed()), + path('feed/latest/trials/', LatestTrialsFeed()), + path('feed/machine-learning/', MachineLearningFeed()), + path('feed/articles/prediction/none/', ToPredictFeed()), ]