diff --git a/castellum/contacts/forms.py b/castellum/contacts/forms.py index ce5c12418931d2fa79dd75da1133705589ae4b92..446592f227297e5aae000d04503f51f9ada94f42 100644 --- a/castellum/contacts/forms.py +++ b/castellum/contacts/forms.py @@ -210,11 +210,13 @@ class SearchForm(forms.Form): label=_('Search for name, phone number or email address'), required=True, ) + action = forms.CharField(required=False) def clean(self): cleaned_data = super().clean() search = cleaned_data.get('search', '') + action = cleaned_data.get('action', 'search') names = [] phone_numbers = [] @@ -227,11 +229,15 @@ class SearchForm(forms.Form): else: names.append(part) - if not (len(names) > 1 or phone_numbers or emails): - self.add_error( - 'search', - _('At least full name, phone number or email address have to be provided'), - ) + if action in ['create', 'force-create']: + if not len(names) > 1: + self.add_error('search', _('The full name is required to create a subject')) + else: + if not (len(names) > 1 or phone_numbers or emails): + self.add_error( + 'search', + _('At least full name, phone number or email address have to be provided'), + ) cleaned_data['first_name'] = names[0] if names else '' cleaned_data['last_name'] = ' '.join(names[1:]) diff --git a/castellum/subjects/templates/subjects/maintenance_subjectcreationrequest.html b/castellum/subjects/templates/subjects/maintenance_subjectcreationrequest.html index abab69c41204b64a2ca0dcd97f27254356311080..c3048bc9e3e3d8f5e1d354f93516bbd710674711 100644 --- a/castellum/subjects/templates/subjects/maintenance_subjectcreationrequest.html +++ b/castellum/subjects/templates/subjects/maintenance_subjectcreationrequest.html @@ -32,6 +32,7 @@
{% csrf_token %} +
diff --git a/castellum/subjects/templates/subjects/subject_search.html b/castellum/subjects/templates/subjects/subject_search.html index 199e6462d49e545b2aa4eddb2f0c4dabb38c4515..e364a6b12da3ac37b1efb57152131e5a83aaf442 100644 --- a/castellum/subjects/templates/subjects/subject_search.html +++ b/castellum/subjects/templates/subjects/subject_search.html @@ -4,220 +4,213 @@ {% block title %}{% translate "Subjects" %} · {{ block.super }}{% endblock %} {% block content %} + {% has_perm 'subjects.change_subject' user as can_change_subject %} + {% has_perm 'subjects.view_subject' user as can_view_subject %} + {% if subjectcreationrequest %} {% url 'subjects:maintenance-subjectcreationrequest-delete' subjectcreationrequest.pk as discard_url %}

{% blocktranslate with name=subjectcreationrequest.contact.full_name discard_url=discard_url %}Please make sure that {{ name }} does not yet exist in the database. If you find duplicates, you can also discard this request.{% endblocktranslate %}

{% endif %} -
- {% include 'utils/form_errors.html' with form=form %} - {% csrf_token %} - {% bootstrap_field form.search %} + {% if form.is_valid and can_view_subject and is_create %} + {% else %} + + {% include 'utils/form_errors.html' with form=form %} + {% csrf_token %} + + {% bootstrap_field form.search %} -
- -
-
+
+ + {% if can_change_subject %} + + {% endif %} +
+ + {% endif %} {% if form.is_valid %} - {% has_perm 'subjects.change_subject' user as can_change_subject %} - {% has_perm 'subjects.view_subject' user as can_view_subject %} - -
- {% if can_change_subject and form.cleaned_data.last_name %} -
- -
+ {% if can_change_subject and is_create %} +
+ {% for error in privacy_level_form.non_field_errors %} + + {% endfor %} + {% csrf_token %} + {% if subjectcreationrequest %} +
+
{{ subjectcreationrequest.contact|verbose_name:'title' }}
+
{{ subjectcreationrequest.contact|display:'title' }}
+ +
{{ subjectcreationrequest.contact|verbose_name:'first_name' }}
+
{{ subjectcreationrequest.contact|display:'first_name' }}
+ +
{{ subjectcreationrequest.contact|verbose_name:'last_name' }}
+
{{ subjectcreationrequest.contact|display:'last_name' }}
+ +
{{ subjectcreationrequest.contact|verbose_name:'gender' }}
+
{{ subjectcreationrequest.contact|display:'gender' }}
+ +
{{ subjectcreationrequest.contact|verbose_name:'date_of_birth' }}
+
{{ subjectcreationrequest.contact|display:'date_of_birth' }}
+ +
{{ subjectcreationrequest.contact|verbose_name:'email' }}
+
{{ subjectcreationrequest.contact|display:'email' }}
+ +
{{ subjectcreationrequest|verbose_name:'source' }}
+
{{ subjectcreationrequest|display:'source' }}
+
+ {% else %} +
+
{% translate 'First name' %}
+
{{ form.cleaned_data.first_name }}
+ +
{% translate 'Last name' %}
+
{{ form.cleaned_data.last_name }}
+ + {% if form.cleaned_data.email %} +
{% translate 'Email' %}
+
{{ form.cleaned_data.email }}
+ {% endif %} + + {% if form.cleaned_data.phone_number %} +
{% translate 'Phone number' %}
+
{{ form.cleaned_data.phone_number }}
+ {% endif %} +
+ {% endif %} + {% bootstrap_field privacy_level_form.privacy_level %} + {{ form.search.as_hidden }} + +
+ {% else %} + {% if form.cleaned_data.action == 'create' %} +

{% translate 'Please check these matches before creating a new subjects.' %}

+ {% endif %} + {% if not can_view_subject %} +

{% translate 'This list may be restricted based on your permissions.' %}

{% endif %} -
-
- {% if not can_view_subject %} -

{% translate 'This list may be restricted based on your permissions.' %}

- {% endif %} - -
    - {% for subject, contact, participations, can_access in matches %} -
  • -
    -
    - {% if can_access %} -
    - {% if contact.title %}{{ contact.title }}{% endif %} - {% if contact.first_name|lower == form.cleaned_data.first_name|lower %} - {{ contact.first_name }} - {% else %} - {{ contact.first_name }} - {% endif %} - {% if contact.last_name|lower == form.cleaned_data.last_name|lower %} - {{ contact.last_name }} - {% else %} - {{ contact.last_name }} - {% endif %} -
    - {% if can_view_subject %} -
    - {% if contact.date_of_birth %} -
    {{ contact.date_of_birth }}
    - {% endif %} - {% if contact.email %} -
    - {% if contact.email|lower == form.cleaned_data.email|lower %} - {{ contact.email }} - {% else %} - {{ contact.email }} - {% endif %} -
    - {% endif %} -
    - {% if subject.blocked %} - {{ subject|verbose_name:'blocked' }} - {% endif %} - {% endif %} +
      + {% for subject, contact, participations, can_access in matches %} +
    • +
      +
      + {% if can_access %} +
      + {% if contact.title %}{{ contact.title }}{% endif %} + {% if contact.first_name|lower == form.cleaned_data.first_name|lower %} + {{ contact.first_name }} {% else %} -

      {{ contact.full_name }}

      -
      {% translate 'access denied' %}
      + {{ contact.first_name }} {% endif %} -
      -
      - {% if can_view_subject %} - {% if can_access %} - {% translate 'Details' %} - {% else %} - - {% endif %} + {% if contact.last_name|lower == form.cleaned_data.last_name|lower %} + {{ contact.last_name }} + {% else %} + {{ contact.last_name }} {% endif %}
      -
      - {% if can_access %} -
        - {% for participation, can_recruit, can_conduct in participations %} -
      • -
        - {{ participation.study }} - {{ participation.study.contact_person }} - {{ participation|display:'status' }} - {% if participation.dropped_out %} - {{ participation|verbose_name:'dropped_out' }} - {% endif %} -
        -
        - {% if can_recruit %} - {% translate 'Recruitment' %} - {% endif %} - {% if can_conduct %} - {% translate 'Execution' %} + {% if can_view_subject %} +
        + {% if contact.date_of_birth %} +
        {{ contact.date_of_birth }}
        + {% endif %} + {% if contact.email %} +
        + {% if contact.email|lower == form.cleaned_data.email|lower %} + {{ contact.email }} + {% else %} + {{ contact.email }} {% endif %}
        -
      • - {% endfor %} -
      - {% endif %} -
    • - {% empty %} - - {% endfor %} -
    -
    - - {% if can_change_subject and form.cleaned_data.last_name %} -
    -
    - {% for error in privacy_level_form.non_field_errors %} - - {% endfor %} - {% csrf_token %} - {% if subjectcreationrequest %} -
    -
    {{ subjectcreationrequest.contact|verbose_name:'title' }}
    -
    {{ subjectcreationrequest.contact|display:'title' }}
    - -
    {{ subjectcreationrequest.contact|verbose_name:'first_name' }}
    -
    {{ subjectcreationrequest.contact|display:'first_name' }}
    - -
    {{ subjectcreationrequest.contact|verbose_name:'last_name' }}
    -
    {{ subjectcreationrequest.contact|display:'last_name' }}
    - -
    {{ subjectcreationrequest.contact|verbose_name:'gender' }}
    -
    {{ subjectcreationrequest.contact|display:'gender' }}
    - -
    {{ subjectcreationrequest.contact|verbose_name:'date_of_birth' }}
    -
    {{ subjectcreationrequest.contact|display:'date_of_birth' }}
    - -
    {{ subjectcreationrequest.contact|verbose_name:'email' }}
    -
    {{ subjectcreationrequest.contact|display:'email' }}
    - -
    {{ subjectcreationrequest|verbose_name:'source' }}
    -
    {{ subjectcreationrequest|display:'source' }}
    -
    - {% else %} -
    -
    {% translate 'First name' %}
    -
    {{ form.cleaned_data.first_name }}
    - -
    {% translate 'Last name' %}
    -
    {{ form.cleaned_data.last_name }}
    - - {% if form.cleaned_data.email %} -
    {% translate 'Email' %}
    -
    {{ form.cleaned_data.email }}
    + {% endif %} +
    + {% if subject.blocked %} + {{ subject|verbose_name:'blocked' }} + {% endif %} {% endif %} - - {% if form.cleaned_data.phone_number %} -
    {% translate 'Phone number' %}
    -
    {{ form.cleaned_data.phone_number }}
    + {% else %} +

    {{ contact.full_name }}

    +
    {% translate 'access denied' %}
    + {% endif %} +
    +
    + {% if can_view_subject %} + {% if can_access %} + {% translate 'Details' %} + {% else %} + {% endif %} - - {% endif %} - {% bootstrap_field privacy_level_form.privacy_level %} - {{ form.search.as_hidden }} - - -
    - {% endif %} -
-
- {% endif %} - -
+ + {% if can_access %} + + {% endif %} + + {% empty %} + + {% endfor %} + + + {% if can_change_subject and form.cleaned_data.action == 'create' %} + + {% endif %} {% endif %} + {% else %} + +

{% translate 'Current data situation' %}

+

{% translate 'Total number of subjects' %}: {{ count_total }}

+
+
{% translate 'Contact data updated in last 6 months' %}
+
{{ count_updated }} {% translate 'subjects' %}
+
+ +
+ +
{% translate 'Complete recruitment attributes' %}
+
{{ count_complete }} {% translate 'subjects' %}
+
+ +
+ +
{% translate 'Took part in a study' %}
+
{{ count_participated }} {% translate 'subjects' %}
+
+ +
+ +
{% translate 'Currently recruitable' %}
+
{{ count_recruitable }} {% translate 'subjects' %}
+
+ +
+
+ + {% endif %} {% endblock %} diff --git a/castellum/subjects/views.py b/castellum/subjects/views.py index 3b2582984a5bf578076853c010409d25ef2d6ba4..e3a8e9089fd7afb2574b470de1a53641a9937e40 100644 --- a/castellum/subjects/views.py +++ b/castellum/subjects/views.py @@ -144,9 +144,14 @@ class SubjectSearchView(LoginRequiredMixin, FormView): form = kwargs.get('form') if form and form.is_valid(): context['matches'] = list(self.get_matches(form.cleaned_data['search'])) + context['is_create'] = ( + (form.cleaned_data['action'] == 'create' and not context['matches']) + or form.cleaned_data['action'] == 'force-create' + ) if 'privacy_level_form' not in context: context['privacy_level_form'] = SubjectPrivacyLevelForm(user=self.request.user) + return context def form_valid(self, form):