Completed
Pull Request — master (#51)
by Paolo
06:48
created

zooma.views   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 24
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A AnnotateBreedsView.post() 0 10 1
A OntologiesReportView.get_context_data() 0 8 1
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
4
Created on Fri Sep 27 15:39:30 2019
5
6
@author: Paolo Cozzi <[email protected]>
7
"""
8
9
import logging
10
11
from django.http import JsonResponse
12
from django.views.generic import TemplateView
13
from django.contrib.auth.mixins import LoginRequiredMixin
14
15
from common.views import AjaxTemplateView
16
from image_app.models import missing_terms
17
18
from .tasks import AnnotateBreeds as AnnotateBreedsTask
19
20
# Get an instance of a logger
21
logger = logging.getLogger(__name__)
22
23
24
class OntologiesReportView(LoginRequiredMixin, TemplateView):
25
    template_name = 'zooma/ontologies_report.html'
26
27
    def get_context_data(self, **kwargs):
28
        # Call the base implementation first to get a context
29
        context = super().get_context_data(**kwargs)
30
31
        # call report from UID model
32
        context["missing_terms"] = missing_terms()
33
34
        return context
35
36
37
class AnnotateBreedsView(LoginRequiredMixin, AjaxTemplateView):
38
    # forcing POST methods only
39
    # https://stackoverflow.com/a/36865283/4385116
40
    http_method_names = ['post']
41
42
    def post(self, request):
43
        task = AnnotateBreedsTask()
44
45
        res = task.delay()
46
47
        logger.info(
48
            "Start AnnotateBreedsTask %s from user %s" % (
49
                res.task_id, request.user))
50
51
        return JsonResponse({'status': 'AnnotateBreeds Started'})
52