Skip to content

Commit

Permalink
Merge pull request #125 from EBI-Metagenomics/banner-message-api
Browse files Browse the repository at this point in the history
Banner message api
  • Loading branch information
mberacochea authored Mar 13, 2020
2 parents 25290c5 + 43db7ec commit 83c9f0a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
10 changes: 9 additions & 1 deletion emgapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.conf.urls import url

from rest_framework import routers

from . import views
Expand Down Expand Up @@ -399,4 +401,10 @@
r'antismash-geneclusters',
views.AntiSmashGeneClustersViewSet,
base_name='antismash-geneclusters'
)
)

urlpatterns = [
url(r'^v1/banner-message',
views.BannerMessageView.as_view(),
name='banner-message'),
]
33 changes: 20 additions & 13 deletions emgapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,18 @@

from django.conf import settings
from django.db.models import Prefetch, Count, Q
from django.http import Http404
from django.http import Http404, HttpResponse
from django.middleware import csrf
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.views.decorators.clickjacking import xframe_options_exempt

from django_filters.rest_framework import DjangoFilterBackend

from rest_framework.response import Response

from rest_framework import filters
from rest_framework import viewsets, mixins
from rest_framework import filters, viewsets, mixins, permissions, renderers, status
from rest_framework.decorators import detail_route, list_route
from rest_framework import permissions
from rest_framework import renderers
from rest_framework import status
from rest_framework.views import APIView

from . import models as emg_models
from . import serializers as emg_serializers
Expand Down Expand Up @@ -333,7 +329,7 @@ def list(self, request, *args, **kwargs):
`/studies`
`/studies?fields[studies]=accession,study_name,samples_count,biomes`
retrieve only selected fileds
retrieve only selected fields
`/studies?include=biomes` with biomes
Expand Down Expand Up @@ -467,7 +463,7 @@ def list(self, request, *args, **kwargs):
`/super-studies`
`/super-studies?fields[super-studies]=super_study_id,title`
retrieve only selected fileds
retrieve only selected fields
`/super-studies?include=biomes` with biomes
Expand Down Expand Up @@ -570,7 +566,7 @@ def list(self, request, *args, **kwargs):
`/samples` retrieves list of samples
`/samples?fields[samples]=accession,runs_count,biome`
retrieve only selected fileds
retrieve only selected fields
`/samples?include=runs` with related runs
Expand Down Expand Up @@ -626,7 +622,7 @@ def list(self, request, *args, **kwargs):
`/runs`
`/runs?fields[runs]=accession,experiment_type` retrieve only
selected fileds
selected fields
Filter by:
---
Expand Down Expand Up @@ -674,7 +670,7 @@ def list(self, request, *args, **kwargs):
`/assembly`
`/assembly?fields[assembly]=accession` retrieve only
selected fileds
selected fields
Filter by:
---
Expand Down Expand Up @@ -1445,4 +1441,15 @@ class AntiSmashGeneClustersViewSet(mixins.RetrieveModelMixin,
)

ordering = ('-name',)



class BannerMessageView(APIView):

def get(self, request):
"""Get the content of the banner message if any
"""
message = ""
if settings.BANNER_MESSAGE_FILE and os.path.isfile(settings.BANNER_MESSAGE_FILE):
with open(settings.BANNER_MESSAGE_FILE, 'r') as msg_file:
message = msg_file.read().strip()
return Response({"message": message})
11 changes: 7 additions & 4 deletions emgapianns/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.settings import api_settings
from rest_framework import viewsets
from rest_framework import status
from rest_framework import viewsets, status
from rest_framework.exceptions import NotFound

from emgapi import serializers as emg_serializers
from emgapi import models as emg_models
Expand Down Expand Up @@ -476,7 +476,7 @@ class AnalysisPfamRelationshipViewSet( # NOQA
m_mixins.AnalysisJobAnnotationMixin,
m_viewsets.ListReadOnlyModelViewSet):
"""
Retrieves Pfram entries for the given accession
Retrieves Pfam entries for the given accession
Example:
---
`/analyses/MGYA00102827/pfam-entries`
Expand Down Expand Up @@ -872,14 +872,17 @@ def get_queryset(self):
self.kwargs.get(self.lookup_field, None).strip())
organism = m_models.Organism.objects.filter(lineage=lineage) \
.only('id')

if len(organism) == 0:
raise Http404(("Attribute error '%s'." % self.lookup_field))
raise NotFound("Lineage not found. Lineage: " + lineage)

job_ids = m_models.AnalysisJobTaxonomy.objects \
.filter(
M_Q(taxonomy__organism__in=organism) |
M_Q(taxonomy_lsu__organism__in=organism) |
M_Q(taxonomy_ssu__organism__in=organism)
).distinct('job_id')

return emg_models.AnalysisJob.objects \
.filter(job_id__in=job_ids) \
.available(self.request)
Expand Down
6 changes: 6 additions & 0 deletions emgcli/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,9 @@ def show_toolbar(request):
RESULTS_DIR = EMG_CONF['emg']['results_dir']
except KeyError:
RESULTS_DIR = os.path.join(expanduser("~"), 'results')

try:
# Banner message, the content of this file will be shown on the website.
BANNER_MESSAGE_FILE = EMG_CONF['emg']['banner_message_file']
except KeyError:
BANNER_MESSAGE_FILE = None
11 changes: 5 additions & 6 deletions emgcli/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
from rest_framework_jwt.views import verify_jwt_token

from emgapi.urls import router as emg_router
from emgapi.urls import mydata_router
from emgapi.urls import utils_router
from emgapianns.urls import mongo_router, urlpatterns as mongo_url_patterns
from emgapi.urls import mydata_router, utils_router, urlpatterns as emgapi_urlpatterns
from emgapianns.urls import mongo_router, urlpatterns as mongo_urlpatterns
from emgapianns.urls import router as emg_ext_router

from openapi_codec import OpenAPICodec
Expand Down Expand Up @@ -109,10 +108,10 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
name='verify_jwt_token_v1'),
]

# emgapianns custom endpoints
urlpatterns += mongo_url_patterns
urlpatterns += mongo_urlpatterns
urlpatterns += emgapi_urlpatterns

# Admin
# admin
urlpatterns += [
url('admin/', admin.site.urls),
]
Expand Down

0 comments on commit 83c9f0a

Please sign in to comment.