diff --git a/hypha/apply/api/v1/screening/views.py b/hypha/apply/api/v1/screening/views.py index baa152b081980c7d1463fbe7650eb62fd0c0fa50..eb904fe61cef41d7ebe8422391054eea6d4c15f7 100644 --- a/hypha/apply/api/v1/screening/views.py +++ b/hypha/apply/api/v1/screening/views.py @@ -79,5 +79,8 @@ class SubmissionScreeningStatusViewSet( 'detail': "Can't set default as more than one screening status is already set." }) screening_status = ScreeningStatus.objects.get(default=True, yes=yes) + if submission.has_default_screening_status_set: + default_status = submission.screening_statuses.get() + submission.screening_statuses.remove(default_status) submission.screening_statuses.add(screening_status) - return Response(status=status.HTTP_201_CREATED) + return Response(ser.data, status=status.HTTP_201_CREATED) diff --git a/hypha/apply/api/v1/urls.py b/hypha/apply/api/v1/urls.py index 673a4daa9d727223db702cd54b68c64465726b7b..e1529d33911b8033e2307863ddbe867224bac052 100644 --- a/hypha/apply/api/v1/urls.py +++ b/hypha/apply/api/v1/urls.py @@ -3,7 +3,7 @@ from rest_framework_nested import routers from hypha.apply.api.v1.determination.views import SubmissionDeterminationViewSet from hypha.apply.api.v1.review.views import SubmissionReviewViewSet -from hypha.apply.api.v1.screening.views import ScreeningStatusViewSet +from hypha.apply.api.v1.screening.views import ScreeningStatusViewSet, SubmissionScreeningStatusViewSet from .views import ( CommentViewSet, @@ -28,6 +28,7 @@ submission_router.register(r'actions', SubmissionActionViewSet, basename='submis submission_router.register(r'comments', SubmissionCommentViewSet, basename='submission-comments') submission_router.register(r'reviews', SubmissionReviewViewSet, basename='reviews') submission_router.register(r'determinations', SubmissionDeterminationViewSet, basename='determinations') +submission_router.register(r'screening_statuses', SubmissionScreeningStatusViewSet, basename='screening_statuses') urlpatterns = [ path('user/', CurrentUser.as_view(), name='user'), diff --git a/hypha/apply/funds/forms.py b/hypha/apply/funds/forms.py index 4b4d4edb78798acbe2fa33adc34b856776b746c5..9b8811eeee5bf1973b4437cb83377d4ae0a0dbe6 100644 --- a/hypha/apply/funds/forms.py +++ b/hypha/apply/funds/forms.py @@ -11,7 +11,7 @@ from django_select2.forms import Select2Widget from hypha.apply.categories.models import MetaTerm from hypha.apply.users.models import User -from .models import ApplicationSubmission, AssignedReviewers, Reminder, ReviewerRole +from .models import ApplicationSubmission, AssignedReviewers, Reminder, ReviewerRole, ScreeningStatus from .utils import render_icon from .widgets import MetaTermSelect2Widget, Select2MultiCheckboxesWidget from .workflow import get_action_mapping @@ -97,12 +97,29 @@ class ScreeningSubmissionForm(ApplicationSubmissionModelForm): model = ApplicationSubmission fields = ('screening_statuses',) + # screening_statuses = forms.ModelMultipleChoiceField(queryset=ScreeningStatus.objects.filter(yes=True)) + def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') super().__init__(*args, **kwargs) + instance = kwargs.get('instance') + if instance and instance.has_default_screening_status_set: + screening_status = instance.screening_statuses.get(default=True) + self.fields['screening_statuses'].queryset = ScreeningStatus.objects.filter( + yes=screening_status.yes + ) self.should_show = False if self.user.is_apply_staff: self.should_show = True + + def clean(self): + cleaned_data = super().clean() + instance = self.instance + default_status = instance.screening_statuses.get(default=True) + if default_status not in cleaned_data['screening_statuses']: + self.add_error('screening_statuses', 'Can\'t remove default screening status.') + return cleaned_data + # self.add_error('start_date', 'Please select start date.') class UpdateSubmissionLeadForm(ApplicationSubmissionModelForm): diff --git a/hypha/apply/funds/management/commands/export_submissions_csv.py b/hypha/apply/funds/management/commands/export_submissions_csv.py index 90ef23cf0e8d3cb2452087f0c84e3b290b988674..61bbe8a1146d4001be10bed347653ccaa191e5fe 100644 --- a/hypha/apply/funds/management/commands/export_submissions_csv.py +++ b/hypha/apply/funds/management/commands/export_submissions_csv.py @@ -44,5 +44,4 @@ class Command(BaseCommand): submission_value = submission.value except KeyError: submission_value = 0 - import ipdb; ipdb.set_trace() writer.writerow([submission.id, submission.title, submission.full_name, submission.email, submission_value, submission.duration, submission_reapplied, submission.stage, submission.phase, submission.screening_status, submission.submit_time.strftime('%Y-%m-%d'), submission_region, submission_country, submission_focus, submission_type]) diff --git a/hypha/apply/funds/models/submissions.py b/hypha/apply/funds/models/submissions.py index 307a21a52ef0e59bab11ea655b5f714180d9a3a5..5d2c5ca90cae0793c5715669bce9d55a3239fd9f 100644 --- a/hypha/apply/funds/models/submissions.py +++ b/hypha/apply/funds/models/submissions.py @@ -804,6 +804,10 @@ class ApplicationSubmission( def _get_REQUIRED_value(self, name): return self.data(name) + @property + def has_default_screening_status_set(self): + return self.screening_statuses.filter(default=True).exists() + @receiver(post_transition, sender=ApplicationSubmission) def log_status_update(sender, **kwargs): diff --git a/hypha/apply/funds/templates/funds/applicationsubmission_detail.html b/hypha/apply/funds/templates/funds/applicationsubmission_detail.html index e0d294c2b2c3c1c1079ce9ccf89435b5373fccf2..3a2efbe349ebfe00b6d7bf68a3685f9116a8886b 100644 --- a/hypha/apply/funds/templates/funds/applicationsubmission_detail.html +++ b/hypha/apply/funds/templates/funds/applicationsubmission_detail.html @@ -173,4 +173,5 @@ <script src="{% static 'js/apply/submission-text-cleanup.js' %}"></script> <script src="{% static 'js/apply/edit-comment.js' %}"></script> <script src="{% static 'js/apply/flag.js' %}"></script> + <script src="{% static 'js/apply/screening-status.js' %}"></script> {% endblock %} diff --git a/hypha/apply/funds/templates/funds/includes/screening_status_block.html b/hypha/apply/funds/templates/funds/includes/screening_status_block.html index a67aaf4e312bdd1b57e8a19d6b01deb81aac7d4d..9b688d44af6d78370d3dbc4481bfffcfbe99343e 100644 --- a/hypha/apply/funds/templates/funds/includes/screening_status_block.html +++ b/hypha/apply/funds/templates/funds/includes/screening_status_block.html @@ -6,21 +6,26 @@ <div> {{ default_yes }} </div> - <div> - <svg class="icon icon--private-eye" style="margin-right: 2em;"><use xlink:href="#like"></use></svg> + <div class="abcdef" data-id="{{ object.id }}" data-yes="true"> + <svg class="icon icon--private-eye" style="cursor: pointer;"><use xlink:href="#like"></use></svg> </div> </div> <div> <div> {{ default_no }} </div> - <div> - <svg class="icon icon--private-eye" style="margin-right: 2em;"><use xlink:href="#dislike"></use></svg> + <div class="abcdef" data-id="{{ object.id }}" data-yes="false"> + <svg class="icon icon--private-eye" style="cursor: pointer;"><use xlink:href="#dislike"></use></svg> </div> </div> </div> - - <p> - <!-- {% if object.screening_statuses.exists %}{{ object.screening_statuses|default:"Awaiting Screen status" }}{% endif %} <a data-fancybox data-src="#screen-application" class="link link--secondary-change" href="#">Change</a> --> - </p> + <hr> + <div> + {% for status in object.screening_statuses.all %} + <p>{{ status.title }}</p> + {% endfor %} + {% if object.has_default_screening_status_set %} + <p><a id="screening-options" data-fancybox="" data-src="#screen-application" class="link link--secondary-change" href="#">Screening Options</a></p> + {% endif %} + </div> </div> diff --git a/hypha/apply/funds/views.py b/hypha/apply/funds/views.py index fa8deffb6b7ff293b8b14efb39e5684df93399c4..589bf9364be2103baa59ff48f98837f6ad9169f6 100644 --- a/hypha/apply/funds/views.py +++ b/hypha/apply/funds/views.py @@ -578,7 +578,6 @@ class ScreeningSubmissionView(DelegatedViewMixin, UpdateView): context_name = 'screening_form' def form_valid(self, form): - import ipdb; ipdb.set_trace() old = copy(self.get_object()) response = super().form_valid(form) # Record activity @@ -587,7 +586,7 @@ class ScreeningSubmissionView(DelegatedViewMixin, UpdateView): request=self.request, user=self.request.user, source=self.object, - related=str(old.screening_status), + related=','.join([s.title for s in old.screening_statuses.all()]), ) return response diff --git a/hypha/static_src/src/javascript/apply/flag.js b/hypha/static_src/src/javascript/apply/flag.js index 932622b582da6ea26d9931ce63d774060f1db262..dde91ef2648e0e1fdb1455c5e6b7aada6d7b91ad 100644 --- a/hypha/static_src/src/javascript/apply/flag.js +++ b/hypha/static_src/src/javascript/apply/flag.js @@ -21,6 +21,7 @@ url: '/apply/submissions/' + id + '/' + type + '/flag/', type: 'POST', success: function (json) { + console.log(json.result); if (json.result) { $current.addClass('flagged'); } diff --git a/hypha/static_src/src/javascript/apply/screening-status.js b/hypha/static_src/src/javascript/apply/screening-status.js new file mode 100644 index 0000000000000000000000000000000000000000..170ac4b2dc8824e596ca0ce60498441ca770d72c --- /dev/null +++ b/hypha/static_src/src/javascript/apply/screening-status.js @@ -0,0 +1,26 @@ +(function ($) { + + 'use strict'; + + $('.abcdef').on('click', function (e) { + e.preventDefault(); + + console.log('Coming here'); + var $current = $(this); + var id = $current.data('id'); + var yes = $current.data('yes'); + + $.ajax({ + url: '/api/v1/submissions/' + id + '/screening_statuses/default/', + type: 'POST', + data: {yes: yes}, + success: function (json) { + if (json && $('#screening-options').length === 0) { + var screeningOptions = $('<p><a id="screening-options" data-fancybox="" data-src="#screen-application" class="link link--secondary-change" href="#">Screening Options</a></p>'); + $(screeningOptions).insertAfter($current); + } + } + }); + }); + +})(jQuery);