diff --git a/scipost_django/production/management/commands/advance_git_repos.py b/scipost_django/production/management/commands/advance_git_repos.py index 957d417be9d8f5513ec20013761183f4169232fc..c9640dfa9a3068a82b8b5c5e3ad888ea8ddc2e5c 100644 --- a/scipost_django/production/management/commands/advance_git_repos.py +++ b/scipost_django/production/management/commands/advance_git_repos.py @@ -21,13 +21,6 @@ from base64 import b64encode from production.models import ProofsRepository -from production.constants import ( - PROOFS_REPO_UNINITIALIZED, - PROOFS_REPO_CREATED, - PROOFS_REPO_TEMPLATE_ONLY, - PROOFS_REPO_TEMPLATE_FORMATTED, - PROOFS_REPO_PRODUCTION_READY, -) class Command(BaseCommand): @@ -476,11 +469,13 @@ class Command(BaseCommand): repos = ProofsRepository.objects.all() # Create the repos - repos_to_be_created = repos.filter(status=PROOFS_REPO_UNINITIALIZED) + repos_to_be_created = repos.filter( + status=ProofsRepository.PROOFS_REPO_UNINITIALIZED + ) for repo in repos_to_be_created: try: self._create_git_repo(repo) - repo.status = PROOFS_REPO_CREATED + repo.status = ProofsRepository.PROOFS_REPO_CREATED repo.save() except Exception as e: self.stdout.write( @@ -490,11 +485,13 @@ class Command(BaseCommand): ) # Copy the pure templates - repos_to_be_templated = repos.filter(status=PROOFS_REPO_CREATED) + repos_to_be_templated = repos.filter( + status=ProofsRepository.PROOFS_REPO_CREATED + ) for repo in repos_to_be_templated: try: self._copy_pure_templates(repo) - repo.status = PROOFS_REPO_TEMPLATE_ONLY + repo.status = ProofsRepository.PROOFS_REPO_TEMPLATE_ONLY repo.save() except Exception as e: self.stdout.write( @@ -504,11 +501,13 @@ class Command(BaseCommand): ) # Format the skeleton files - repos_to_be_formatted = repos.filter(status=PROOFS_REPO_TEMPLATE_ONLY) + repos_to_be_formatted = repos.filter( + status=ProofsRepository.PROOFS_REPO_TEMPLATE_ONLY + ) for repo in repos_to_be_formatted: try: self._format_skeleton(repo) - repo.status = PROOFS_REPO_TEMPLATE_FORMATTED + repo.status = ProofsRepository.PROOFS_REPO_TEMPLATE_FORMATTED repo.save() except Exception as e: self.stdout.write( @@ -518,12 +517,14 @@ class Command(BaseCommand): ) # Copy the arXiv source files - repos_to_be_copied = repos.filter(status=PROOFS_REPO_TEMPLATE_FORMATTED) + repos_to_be_copied = repos.filter( + status=ProofsRepository.PROOFS_REPO_TEMPLATE_FORMATTED + ) for repo in repos_to_be_copied: try: if "arxiv.org" in repo.stream.submission.preprint.url: self._copy_arxiv_source_files(repo) - repo.status = PROOFS_REPO_PRODUCTION_READY + repo.status = ProofsRepository.PROOFS_REPO_PRODUCTION_READY repo.save() except Exception as e: self.stdout.write( diff --git a/scipost_django/production/models.py b/scipost_django/production/models.py index adb36134677f9246520b1ae0ce586790caba602e..035ffff3f458bc6affa42a58d48df558ec1d58d7 100644 --- a/scipost_django/production/models.py +++ b/scipost_django/production/models.py @@ -246,6 +246,22 @@ class ProofsRepository(models.Model): ProofsRepository is a GitLab repository of Proofs for a Submission. """ + PROOFS_REPO_UNINITIALIZED = "uninitialized" + PROOFS_REPO_CREATED = "created" + PROOFS_REPO_TEMPLATE_ONLY = "template_only" + PROOFS_REPO_TEMPLATE_FORMATTED = "template_formatted" + PROOFS_REPO_PRODUCTION_READY = "production_ready" + PROOFS_REPO_STATUSES = ( + (PROOFS_REPO_UNINITIALIZED, "The repository does not exist"), + (PROOFS_REPO_CREATED, "The repository exists but is empty"), + (PROOFS_REPO_TEMPLATE_ONLY, "The repository contains the bare template"), + ( + PROOFS_REPO_TEMPLATE_FORMATTED, + "The repository contains the automatically formatted template", + ), + (PROOFS_REPO_PRODUCTION_READY, "The repository is ready for production"), + ) + stream = models.OneToOneField( ProductionStream, on_delete=models.CASCADE, @@ -371,7 +387,7 @@ def production_stream_create_proofs_repo(sender, instance, created, **kwargs): if created: ProofsRepository.objects.create( stream=instance, - status=PROOFS_REPO_UNINITIALIZED, + status=ProofsRepository.PROOFS_REPO_UNINITIALIZED, ) diff --git a/scipost_django/profiles/views.py b/scipost_django/profiles/views.py index 113a72382d0caff1d76b33d96fee4ff5c547d403..528eb74a0b5230726ac9901462dc481f646abd3b 100644 --- a/scipost_django/profiles/views.py +++ b/scipost_django/profiles/views.py @@ -2,6 +2,7 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" +from functools import reduce from django.contrib import messages from django.contrib.auth.mixins import UserPassesTestMixin from django.urls import reverse, reverse_lazy @@ -51,12 +52,18 @@ class ProfileAutocompleteView(autocomplete.Select2QuerySetView): return None qs = Profile.objects.all() if self.q: - qs = qs.filter( - Q(first_name__icontains=self.q) - | Q(last_name__icontains=self.q) - | Q(emails__email__icontains=self.q) - | Q(orcid_id__icontains=self.q) - ).distinct() + # Iteratively filter by each word in the query + qs = reduce( + lambda qs, q: qs.filter( + Q(first_name__icontains=q) + | Q(last_name__icontains=q) + | Q(emails__email__icontains=q) + | Q(orcid_id__icontains=q) + ).distinct(), + self.q.split(), + qs, + ) + return qs @@ -368,9 +375,9 @@ def _hx_profile_specialties(request, profile_id): elif request.POST.get("action") == "remove": profile.specialties.remove(specialty) current_spec_slugs = [s.slug for s in profile.specialties.all()] - other_specialties = Specialty.objects.filter( - acad_field=profile.acad_field - ).exclude(slug__in=profile.specialties.values_list("slug")) + other_specialties = Specialty.objects.filter(acad_field=profile.acad_field).exclude( + slug__in=profile.specialties.values_list("slug") + ) context = { "profile": profile, "other_specialties": other_specialties,