You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. import sys
  2. import logging
  3. sys.path.append('../api')
  4. from django.contrib.auth.views import LoginView as BaseLoginView
  5. from django.shortcuts import get_object_or_404
  6. from django.views.generic import TemplateView
  7. from django.views.generic.list import ListView
  8. from django.contrib.auth.mixins import LoginRequiredMixin
  9. from api.permissions import SuperUserMixin
  10. from api.models import Project
  11. from app import settings
  12. logger = logging.getLogger(__name__)
  13. class IndexView(TemplateView):
  14. template_name = 'index.html'
  15. class ProjectView(LoginRequiredMixin, TemplateView):
  16. template_name = 'annotation.html'
  17. def get_context_data(self, **kwargs):
  18. context = super().get_context_data(**kwargs)
  19. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  20. context['bundle_name'] = project.get_bundle_name()
  21. return context
  22. class ProjectsView(LoginRequiredMixin, TemplateView):
  23. template_name = 'projects.html'
  24. class DatasetView(SuperUserMixin, LoginRequiredMixin, ListView):
  25. template_name = 'dataset.html'
  26. paginate_by = 5
  27. extra_context = {
  28. 'bundle_name': 'dataset'
  29. }
  30. def get_queryset(self):
  31. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  32. return project.documents.all()
  33. class LabelView(SuperUserMixin, LoginRequiredMixin, TemplateView):
  34. template_name = 'admin.html'
  35. extra_context = {
  36. 'bundle_name': 'label'
  37. }
  38. class StatsView(SuperUserMixin, LoginRequiredMixin, TemplateView):
  39. template_name = 'admin.html'
  40. extra_context = {
  41. 'bundle_name': 'stats'
  42. }
  43. class GuidelineView(SuperUserMixin, LoginRequiredMixin, TemplateView):
  44. template_name = 'admin.html'
  45. extra_context = {
  46. 'bundle_name': 'guideline'
  47. }
  48. class DataUpload(SuperUserMixin, LoginRequiredMixin, TemplateView):
  49. template_name = 'admin.html'
  50. def get_context_data(self, **kwargs):
  51. context = super().get_context_data(**kwargs)
  52. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  53. context['bundle_name'] = project.get_bundle_name_upload()
  54. return context
  55. class DataDownload(SuperUserMixin, LoginRequiredMixin, TemplateView):
  56. template_name = 'admin.html'
  57. def get_context_data(self, **kwargs):
  58. context = super().get_context_data(**kwargs)
  59. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  60. context['bundle_name'] = project.get_bundle_name_download()
  61. return context
  62. class LoginView(BaseLoginView):
  63. template_name = 'login.html'
  64. redirect_authenticated_user = True
  65. extra_context = {
  66. 'github_login': bool(settings.SOCIAL_AUTH_GITHUB_KEY),
  67. 'aad_login': bool(settings.SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID),
  68. }
  69. def get_context_data(self, **kwargs):
  70. context = super(LoginView, self).get_context_data(**kwargs)
  71. context['social_login_enabled'] = any(value for key, value in context.items()
  72. if key.endswith('_login'))
  73. return context
  74. class DemoTextClassification(TemplateView):
  75. template_name = 'annotation.html'
  76. extra_context = {
  77. 'bundle_name': 'demo_text_classification',
  78. }
  79. class DemoNamedEntityRecognition(TemplateView):
  80. template_name = 'annotation.html'
  81. extra_context = {
  82. 'bundle_name': 'demo_named_entity',
  83. }
  84. class DemoTranslation(TemplateView):
  85. template_name = 'annotation.html'
  86. extra_context = {
  87. 'bundle_name': 'demo_translation',
  88. }