Example #1
0
 class Meta:
     model = Algorithm
     fields = (
         "title",
         "description",
         "publications",
         "modalities",
         "structures",
         "organizations",
         "logo",
         "social_image",
         "public",
         "use_flexible_inputs",
         "repo_name",
         "inputs",
         "outputs",
         "workstation",
         "workstation_config",
         "credits_per_job",
         "detail_page_markdown",
         "job_create_page_markdown",
         "additional_terms_markdown",
         "result_template",
         "image_requires_gpu",
         "image_requires_memory_gb",
         "recurse_submodules",
     )
     widgets = {
         "description": TextInput,
         "detail_page_markdown": MarkdownEditorWidget,
         "job_create_page_markdown": MarkdownEditorWidget,
         "additional_terms_markdown": MarkdownEditorWidget,
         "result_template": MarkdownEditorWidget,
         "publications": Select2MultipleWidget,
         "modalities": Select2MultipleWidget,
         "structures": Select2MultipleWidget,
         "organizations": Select2MultipleWidget,
     }
     help_texts = {
         "workstation_config": format_lazy(
             (
                 "The workstation configuration to use for this algorithm. "
                 "If a suitable configuration does not exist you can "
                 '<a href="{}">create a new one</a>.'
             ),
             reverse_lazy("workstation-configs:create"),
         ),
         "publications": format_lazy(
             (
                 "The publications associated with this reader study. "
                 'If your publication is missing click <a href="{}">here</a> to add it '
                 "and then refresh this page."
             ),
             reverse_lazy("publications:create"),
         ),
     }
 class Meta:
     model = Algorithm
     fields = (
         "title",
         "description",
         "logo",
         "public",
         "workstation",
         "workstation_config",
         "credits_per_job",
         "detail_page_markdown",
         "job_create_page_markdown",
         "additional_terms_markdown",
         "result_template",
     )
     widgets = {
         "description": TextInput,
         "detail_page_markdown": MarkdownEditorWidget,
         "job_create_page_markdown": MarkdownEditorWidget,
         "additional_terms_markdown": MarkdownEditorWidget,
         "result_template": MarkdownEditorWidget,
     }
     help_texts = {
         "workstation_config": format_lazy(
             (
                 "The workstation configuration to use for this algorithm. "
                 "If a suitable configuration does not exist you can "
                 '<a href="{}">create a new one</a>.'
             ),
             reverse_lazy("workstation-configs:create"),
         ),
     }
Example #3
0
class AdminsUpdate(
        LoginRequiredMixin,
        ObjectPermissionRequiredMixin,
        SuccessMessageMixin,
        FormView,
):
    form_class = AdminsForm
    template_name = "admins/admins_form.html"
    success_message = "Admins successfully updated"
    permission_required = "change_challenge"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.request.challenge

    def get_success_url(self):
        return reverse(
            "admins:list",
            kwargs={"challenge_short_name": self.request.challenge.short_name},
        )

    def form_valid(self, form):
        challenge = self.request.challenge
        form.add_or_remove_user(challenge=challenge, site=self.request.site)
        return super().form_valid(form)
Example #4
0
 class Meta:
     model = ExternalChallenge
     fields = (
         "short_name",
         "homepage",
         *common_information_items,
         *common_images_items,
         *event_items,
         *data_items,
     )
     widgets = {
         "workshop_date": forms.TextInput(attrs={"type": "date"}),
         "description": forms.Textarea,
         "task_types": Select2MultipleWidget,
         "modalities": Select2MultipleWidget,
         "structures": Select2MultipleWidget,
         "organizations": Select2MultipleWidget,
         "series": Select2MultipleWidget,
         "publications": Select2MultipleWidget,
     }
     help_texts = {
         "publications": format_lazy(
             (
                 "The publications associated with this archive. "
                 'If your publication is missing click <a href="{}">here</a> to add it '
                 "and then refresh this page."
             ),
             reverse_lazy("publications:create"),
         )
     }
Example #5
0
class SubmissionDetail(
    LoginRequiredMixin, ObjectPermissionRequiredMixin, DetailView
):
    model = Submission
    permission_required = "view_submission"
    raise_exception = True
    login_url = reverse_lazy("userena_signin")
class PageDelete(
    LoginRequiredMixin,
    ObjectPermissionRequiredMixin,
    ChallengeFilteredQuerysetMixin,
    DeleteView,
):
    model = Page
    slug_url_kwarg = "page_title"
    slug_field = "title__iexact"
    success_message = "Page was successfully deleted"
    permission_required = "change_challenge"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.request.challenge

    def get_success_url(self):
        return reverse(
            "pages:list",
            kwargs={"challenge_short_name": self.request.challenge.short_name},
        )

    def delete(self, request, *args, **kwargs):
        messages.success(self.request, self.success_message)
        return super().delete(request, *args, **kwargs)
Example #7
0
class MethodDetail(
    LoginRequiredMixin, ObjectPermissionRequiredMixin, DetailView
):
    model = Method
    permission_required = "view_method"
    raise_exception = True
    login_url = reverse_lazy("userena_signin")
Example #8
0
 class Meta:
     model = Challenge
     fields = [
         *common_information_items,
         "display_forum_link",
         "disclaimer",
         "contact_email",
         "banner",
         *common_images_items,
         *event_items,
         *registration_items,
         "use_teams",
     ]
     widgets = {
         "workshop_date": forms.TextInput(attrs={"type": "date"}),
         "task_types": Select2MultipleWidget,
         "modalities": Select2MultipleWidget,
         "structures": Select2MultipleWidget,
         "organizations": Select2MultipleWidget,
         "series": Select2MultipleWidget,
         "publications": Select2MultipleWidget,
         "registration_page_text": SummernoteInplaceWidget(),
     }
     help_texts = {
         "publications": format_lazy(
             (
                 "The publications associated with this archive. "
                 'If your publication is missing click <a href="{}">here</a> to add it '
                 "and then refresh this page."
             ),
             reverse_lazy("publications:create"),
         )
     }
class PhaseUpdate(
        LoginRequiredMixin,
        ObjectPermissionRequiredMixin,
        SuccessMessageMixin,
        UpdateView,
):
    form_class = PhaseUpdateForm
    success_message = "Configuration successfully updated"
    permission_required = "change_phase"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_object(self, queryset=None):
        return Phase.objects.get(challenge=self.request.challenge,
                                 slug=self.kwargs["slug"])

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs.update({"challenge": self.request.challenge})
        return kwargs

    def get_success_url(self):
        return reverse(
            "evaluation:leaderboard",
            kwargs={
                "challenge_short_name": self.request.challenge.short_name,
                "slug": self.kwargs["slug"],
            },
        )
Example #10
0
 class Meta:
     model = Archive
     fields = (
         "title",
         "description",
         "publications",
         "modalities",
         "structures",
         "organizations",
         "logo",
         "workstation",
         "workstation_config",
         "algorithms",
         "public",
         "detail_page_markdown",
     )
     widgets = {
         "description": TextInput,
         "detail_page_markdown": MarkdownEditorWidget,
         "algorithms": Select2MultipleWidget,
         "publications": Select2MultipleWidget,
         "modalities": Select2MultipleWidget,
         "structures": Select2MultipleWidget,
         "organizations": Select2MultipleWidget,
     }
     help_texts = {
         "workstation_config":
         format_lazy(
             ("The workstation configuration to use for this archive. "
              "If a suitable configuration does not exist you can "
              '<a href="{}">create a new one</a>.'),
             reverse_lazy("workstation-configs:create"),
         ),
     }
class RawImageUploadSessionDetail(
    LoginRequiredMixin, ObjectPermissionRequiredMixin, DetailView
):
    model = RawImageUploadSession
    permission_required = f"{RawImageUploadSession._meta.app_label}.view_{RawImageUploadSession._meta.model_name}"
    raise_exception = True
    login_url = reverse_lazy("userena_signin")
Example #12
0
class RegistrationRequestUpdate(
    LoginRequiredMixin,
    ObjectPermissionRequiredMixin,
    SuccessMessageMixin,
    UpdateView,
):
    model = RegistrationRequest
    fields = ("status",)
    success_message = "Registration successfully updated"
    permission_required = "change_challenge"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.request.challenge

    def get_success_url(self):
        return reverse(
            "participants:registration-list",
            kwargs={"challenge_short_name": self.object.challenge.short_name},
        )

    def form_valid(self, form):
        redirect = super().form_valid(form)
        # TODO: check if the status has actually changed
        if self.object.status == RegistrationRequest.ACCEPTED:
            send_participation_request_accepted_email(
                self.request, self.object
            )
        if self.object.status == RegistrationRequest.REJECTED:
            send_participation_request_rejected_email(
                self.request, self.object
            )
        return redirect
class MethodCreate(LoginRequiredMixin, ObjectPermissionRequiredMixin,
                   CreateView):
    model = Method
    form_class = MethodForm
    permission_required = "change_challenge"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.request.challenge

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs.update({
            "user": self.request.user,
            "challenge": self.request.challenge
        })
        return kwargs

    def form_valid(self, form):
        form.instance.creator = self.request.user

        uploaded_file: StagedAjaxFile = form.cleaned_data["chunked_upload"][0]
        form.instance.staged_image_uuid = uploaded_file.uuid

        return super().form_valid(form)
class MethodList(LoginRequiredMixin, PermissionListMixin, ListView):
    model = Method
    permission_required = "view_method"
    login_url = reverse_lazy("account_login")

    def get_queryset(self):
        queryset = super().get_queryset()
        return queryset.filter(phase__challenge=self.request.challenge)
class SubmissionCreate(LoginRequiredMixin, ObjectPermissionRequiredMixin,
                       SubmissionCreateBase):
    form_class = SubmissionForm
    permission_required = "create_phase_submission"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.phase
Example #16
0
class DocPageCreate(
        LoginRequiredMixin,
        PermissionRequiredMixin,
        CreateView,
):
    model = DocPage
    form_class = DocPageCreateForm
    permission_required = "documentation.add_docpage"
    raise_exception = True
    login_url = reverse_lazy("account_login")
Example #17
0
class DocPageUpdate(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
    model = DocPage
    form_class = DocPageUpdateForm
    permission_required = "documentation.change_docpage"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def form_valid(self, form):
        response = super().form_valid(form)
        self.object.position(form.cleaned_data["position"])
        return response
Example #18
0
class SubmissionList(LoginRequiredMixin, PermissionListMixin, ListView):
    model = Submission
    permission_required = "view_submission"
    login_url = reverse_lazy("userena_signin")

    def get_queryset(self):
        queryset = super().get_queryset()
        return (
            queryset.filter(phase__challenge=self.request.challenge)
            .select_related("creator__user_profile", "phase__challenge")
            .prefetch_related("evaluation_set")
        )
class EvaluationUpdate(
        LoginRequiredMixin,
        ObjectPermissionRequiredMixin,
        SuccessMessageMixin,
        UpdateView,
):
    model = Evaluation
    fields = ("published", )
    success_message = "Result successfully updated."
    permission_required = "change_evaluation"
    raise_exception = True
    login_url = reverse_lazy("account_login")
class PageList(
    LoginRequiredMixin,
    ObjectPermissionRequiredMixin,
    ChallengeFilteredQuerysetMixin,
    ListView,
):
    model = Page
    permission_required = "change_challenge"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.request.challenge
Example #21
0
class ParticipantsList(LoginRequiredMixin, ObjectPermissionRequiredMixin,
                       ListView):
    template_name = "participants/participants_list.html"
    permission_required = "change_challenge"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.request.challenge

    def get_queryset(self):
        challenge = self.request.challenge
        return challenge.get_participants().select_related(
            "user_profile", "verification")
Example #22
0
class RegistrationRequestList(LoginRequiredMixin,
                              ObjectPermissionRequiredMixin, ListView):
    model = RegistrationRequest
    permission_required = "change_challenge"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.request.challenge

    def get_queryset(self):
        queryset = super().get_queryset()
        queryset = queryset.filter(Q(challenge=self.request.challenge))
        return queryset
class LegacySubmissionCreate(LoginRequiredMixin, ObjectPermissionRequiredMixin,
                             SubmissionCreateBase):
    form_class = LegacySubmissionForm
    permission_required = "change_challenge"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.request.challenge

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs.update({"challenge": self.request.challenge})
        return kwargs
class RawImageUploadSessionList(
    LoginRequiredMixin, PermissionListMixin, PaginatedTableListView,
):
    model = RawImageUploadSession
    permission_required = f"{RawImageUploadSession._meta.app_label}.view_{RawImageUploadSession._meta.model_name}"
    login_url = reverse_lazy("userena_signin")
    row_template = "cases/rawimageuploadsession_row.html"
    search_fields = [
        "pk",
    ]
    columns = [
        Column(title="ID", sort_field="pk"),
        Column(title="Created", sort_field="created"),
        Column(title="Status", sort_field="status"),
    ]
    default_sort_column = 1
Example #25
0
class TeamCreate(LoginRequiredMixin, UserIsChallengeParticipantOrAdminMixin,
                 CreateView):
    model = Team
    fields = ("name", "department", "institution", "website")
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def form_valid(self, form):
        form.instance.challenge = self.request.challenge
        form.instance.owner = self.request.user
        try:
            return super().form_valid(form)

        except ValidationError as e:
            form._errors[NON_FIELD_ERRORS] = ErrorList(e.messages)
            return super().form_invalid(form)
Example #26
0
class TeamDelete(LoginRequiredMixin, UserIsTeamOwnerOrChallengeAdminMixin,
                 DeleteView):
    model = Team
    success_message = "Team successfully deleted"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def delete(self, request, *args, **kwargs):
        messages.success(self.request, self.success_message)
        return super().delete(request, *args, **kwargs)

    def get_success_url(self):
        return reverse(
            "teams:list",
            kwargs={"challenge_short_name": self.object.challenge.short_name},
        )
Example #27
0
class TeamList(LoginRequiredMixin, UserIsChallengeParticipantOrAdminMixin,
               ListView):
    model = Team
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        users_teams = TeamMember.objects.filter(
            team__challenge=self.request.challenge, user=self.request.user)
        context.update({"users_teams": users_teams})
        return context

    def get_queryset(self):
        queryset = super().get_queryset()
        return queryset.filter(Q(challenge=self.request.challenge))
Example #28
0
class AddCasesForm(UploadRawImagesForm):
    interface = ModelChoiceField(
        queryset=ComponentInterface.objects.filter(
            kind__in=InterfaceKind.interface_type_image()),
        help_text=format_lazy(
            ('See the <a href="{}">list of interfaces</a> for more '
             "information about each interface. "
             "Please contact support if your desired output is missing."),
            reverse_lazy("algorithms:component-interface-list"),
        ),
    )

    def save(self, *args, **kwargs):
        self._linked_task.kwargs.update(
            {"interface_pk": self.cleaned_data["interface"].pk})
        return super().save(*args, **kwargs)
Example #29
0
class PageDetail(UserPassesTestMixin, ChallengeFilteredQuerysetMixin,
                 DetailView):
    model = Page
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def test_func(self):
        user = self.request.user
        page = self.get_object()
        return page.can_be_viewed_by(user=user)

    def get_context_object_name(self, obj):
        return "currentpage"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context.update(self.object.detail_context)
        return context
class PageCreate(
    LoginRequiredMixin,
    ObjectPermissionRequiredMixin,
    ChallengeFormKwargsMixin,
    CreateView,
):
    model = Page
    form_class = PageCreateForm
    permission_required = "change_challenge"
    raise_exception = True
    login_url = reverse_lazy("account_login")

    def get_permission_object(self):
        return self.request.challenge

    def form_valid(self, form):
        form.instance.challenge = self.request.challenge
        return super().form_valid(form)