diff --git a/commentaries/factories.py b/commentaries/factories.py index 1f9a3fd2844931cad7b986eb92d695ffd72f46c9..940e958cb31ba3d2039c0e44c8ce1f58640930df 100644 --- a/commentaries/factories.py +++ b/commentaries/factories.py @@ -1,7 +1,6 @@ import factory from scipost.constants import SCIPOST_DISCIPLINES, SCIPOST_SUBJECT_AREAS -from scipost.factories import ContributorFactory from scipost.models import Contributor from journals.constants import SCIPOST_JOURNALS_DOMAINS from common.helpers import random_arxiv_identifier_with_version_number, random_external_doi @@ -16,7 +15,7 @@ class CommentaryFactory(factory.django.DjangoModelFactory): class Meta: model = Commentary - requested_by = factory.SubFactory(ContributorFactory) + requested_by = factory.Iterator(Contributor.objects.all()) type = factory.Iterator(COMMENTARY_TYPES, getter=lambda c: c[0]) discipline = factory.Iterator(SCIPOST_DISCIPLINES, getter=lambda c: c[0]) domain = factory.Iterator(SCIPOST_JOURNALS_DOMAINS, getter=lambda c: c[0]) @@ -48,7 +47,7 @@ class CommentaryFactory(factory.django.DjangoModelFactory): class VettedCommentaryFactory(CommentaryFactory): vetted = True - vetted_by = factory.SubFactory(ContributorFactory) + vetted_by = factory.Iterator(Contributor.objects.all()) class UnpublishedVettedCommentaryFactory(VettedCommentaryFactory): diff --git a/comments/factories.py b/comments/factories.py index de3bf41067008f93d86c590bd583c42884844e56..d74370a136d4a140fd82e8f6d060acf6497526b4 100644 --- a/comments/factories.py +++ b/comments/factories.py @@ -4,7 +4,7 @@ import pytz from django.utils import timezone from commentaries.factories import VettedCommentaryFactory -from scipost.factories import ContributorFactory +from scipost.models import Contributor from submissions.factories import EICassignedSubmissionFactory from theses.factories import VettedThesisLinkFactory @@ -17,12 +17,12 @@ timezone.now() class CommentFactory(factory.django.DjangoModelFactory): - author = factory.SubFactory(ContributorFactory) + author = factory.Iterator(Contributor.objects.all()) comment_text = factory.lazy_attribute(lambda x: Faker().paragraph()) remarks_for_editors = factory.lazy_attribute(lambda x: Faker().paragraph()) file_attachment = Faker().file_name(extension='pdf') status = STATUS_VETTED # All comments will have status vetted! - vetted_by = factory.SubFactory(ContributorFactory) + vetted_by = factory.Iterator(Contributor.objects.all()) date_submitted = Faker().date_time_between(start_date="-3y", end_date="now", tzinfo=pytz.UTC) class Meta: diff --git a/journals/factories.py b/journals/factories.py index 203fe8cb6ca4e14f252ec32dc1d8f9b36660aaba..8d8de8ee154b5922fe4f728ca37ef39f8e3accee 100644 --- a/journals/factories.py +++ b/journals/factories.py @@ -25,11 +25,12 @@ class JournalFactory(factory.django.DjangoModelFactory): class VolumeFactory(factory.django.DjangoModelFactory): in_journal = factory.SubFactory(JournalFactory) - number = factory.Sequence(lambda n: n + 1) + number = 9999 doi_label = factory.Faker('md5') @factory.post_generation def doi(self, create, extracted, **kwargs): + self.number = self.in_journal.volume_set.count() self.doi_label = self.in_journal.doi_label + '.' + str(self.number) @factory.post_generation @@ -45,12 +46,13 @@ class VolumeFactory(factory.django.DjangoModelFactory): class IssueFactory(factory.django.DjangoModelFactory): - in_volume = factory.SubFactory(VolumeFactory) - number = factory.Sequence(lambda n: n + 1) + in_volume = factory.Iterator(Volume.objects.all()) + number = 9999 doi_label = factory.Faker('md5') @factory.post_generation def doi(self, create, extracted, **kwargs): + self.number = self.in_volume.issue_set.count() self.doi_label = self.in_volume.doi_label + '.' + str(self.number) @factory.post_generation @@ -68,9 +70,9 @@ class IssueFactory(factory.django.DjangoModelFactory): class PublicationFactory(factory.django.DjangoModelFactory): accepted_submission = factory.SubFactory(PublishedSubmissionFactory) - paper_nr = factory.Sequence(lambda n: n) + paper_nr = 9999 pdf_file = Faker().file_name(extension='pdf') - in_issue = factory.SubFactory(IssueFactory) + in_issue = factory.Iterator(Issue.objects.all()) submission_date = factory.Faker('date') acceptance_date = factory.Faker('date') publication_date = factory.Faker('date') @@ -78,7 +80,7 @@ class PublicationFactory(factory.django.DjangoModelFactory): @factory.post_generation def doi(self, create, extracted, **kwargs): - paper_nr = self.in_issue.publication_set.count() + 1 + paper_nr = self.in_issue.publication_set.count() self.paper_nr = paper_nr self.doi_label = self.in_issue.doi_label + '.' + str(paper_nr).rjust(3, '0') diff --git a/scipost/factories.py b/scipost/factories.py index a10f06c567ecc6caab4e3ce5b65802f4da100b88..ce122a6556cc9fb8ffdc1666608f2197382a2b7a 100644 --- a/scipost/factories.py +++ b/scipost/factories.py @@ -7,7 +7,7 @@ from django.contrib.auth.models import Group from submissions.models import Submission from .models import Contributor, EditorialCollege, EditorialCollegeFellowship, Remark -from .constants import TITLE_CHOICES +from .constants import TITLE_CHOICES, SCIPOST_SUBJECT_AREAS from django_countries.data import COUNTRIES from faker import Faker @@ -21,6 +21,7 @@ class ContributorFactory(factory.django.DjangoModelFactory): personalwebpage = factory.Faker('url') country_of_employment = factory.Iterator(list(COUNTRIES)) affiliation = factory.Faker('company') + expertises = factory.Iterator(SCIPOST_SUBJECT_AREAS[0][1], getter=lambda c: [c[0]]) class Meta: model = Contributor diff --git a/scipost/management/commands/populate_db.py b/scipost/management/commands/populate_db.py index a8561b693908642e3534433312ad4616b6eb3332..4efe19d85887e5a79782a2b8defb1919286e049f 100644 --- a/scipost/management/commands/populate_db.py +++ b/scipost/management/commands/populate_db.py @@ -4,7 +4,7 @@ from commentaries.factories import VettedCommentaryFactory from comments.factories import CommentaryCommentFactory, SubmissionCommentFactory,\ ThesislinkCommentFactory from scipost.factories import SubmissionRemarkFactory -from journals.factories import JournalFactory, IssueFactory, PublicationFactory +from journals.factories import JournalFactory, VolumeFactory, IssueFactory, PublicationFactory from news.factories import NewsItemFactory from submissions.factories import EICassignedSubmissionFactory from theses.factories import VettedThesisLinkFactory @@ -50,12 +50,19 @@ class Command(BaseCommand): default=False, help='Add 5 Editorial College and Fellows (Contributors required)', ) + parser.add_argument( + '--pubset', + action='store_true', + dest='pubset', + default=False, + help='Add 5 Issues, Volumes and Journals', + ) parser.add_argument( '--issues', action='store_true', dest='issues', default=False, - help='Add 5 sets of {Journal, Volume and Issue}', + help='Add 5 Issues', ) parser.add_argument( '--submissions', @@ -95,7 +102,10 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): if kwargs['contributor'] or kwargs['all']: - self.create_contributors() + n = 5 + if kwargs['all']: + n += 10 + self.create_contributors(n) if kwargs['commentaries'] or kwargs['all']: self.create_commentaries() if kwargs['comments'] or kwargs['all']: @@ -107,6 +117,8 @@ class Command(BaseCommand): self.create_news_items() if kwargs['submissions'] or kwargs['all']: self.create_submissions() + if kwargs['pubset'] or kwargs['all']: + self.create_pubset() if kwargs['issues'] or kwargs['all']: self.create_issues() if kwargs['publications'] or kwargs['all']: @@ -116,9 +128,9 @@ class Command(BaseCommand): if kwargs['theses'] or kwargs['all']: self.create_theses() - def create_contributors(self): - ContributorFactory.create_batch(5) - self.stdout.write(self.style.SUCCESS('Successfully created 5 Contributors.')) + def create_contributors(self, n=5): + ContributorFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created %i Contributors.' % n)) def create_commentaries(self): VettedCommentaryFactory.create_batch(5) @@ -146,13 +158,18 @@ class Command(BaseCommand): EICassignedSubmissionFactory.create_batch(5) self.stdout.write(self.style.SUCCESS('Successfully created 5 Submissions.')) - def create_issues(self): + def create_pubset(self): + VolumeFactory.create_batch(5) IssueFactory.create_batch(5) self.stdout.write(self.style.SUCCESS( 'Successfully created 5x {Journal, Volume and Issue}.')) + def create_issues(self): + IssueFactory.create_batch(5) + self.stdout.write(self.style.SUCCESS( + 'Successfully created 5 Issue.')) + def create_publications(self): - JournalFactory.create_batch(4) PublicationFactory.create_batch(5) self.stdout.write(self.style.SUCCESS('Successfully created 5 Publications.')) diff --git a/submissions/factories.py b/submissions/factories.py index 39aab654c692e00a6518a5e7ecc633acf1b59f99..6c602275452772293c4f8303caf37c5baf63152a 100644 --- a/submissions/factories.py +++ b/submissions/factories.py @@ -3,6 +3,7 @@ import pytz from django.utils import timezone +from scipost.constants import SCIPOST_SUBJECT_AREAS from scipost.models import Contributor from journals.constants import SCIPOST_JOURNALS_DOMAINS from common.helpers import random_arxiv_identifier_without_version_number, random_scipost_journal @@ -19,14 +20,15 @@ class SubmissionFactory(factory.django.DjangoModelFactory): model = Submission author_list = factory.Faker('name') - submitted_by = Contributor.objects.first() + submitted_by = factory.Iterator(Contributor.objects.all()) submitted_to_journal = factory.Sequence(lambda n: random_scipost_journal()) title = factory.lazy_attribute(lambda x: Faker().sentence()) abstract = factory.lazy_attribute(lambda x: Faker().paragraph()) arxiv_link = factory.Faker('uri') arxiv_identifier_wo_vn_nr = factory.Sequence( lambda n: random_arxiv_identifier_without_version_number()) - domain = SCIPOST_JOURNALS_DOMAINS[0][0] + subject_area = factory.Iterator(SCIPOST_SUBJECT_AREAS[0][1], getter=lambda c: c[0]) + domain = factory.Iterator(SCIPOST_JOURNALS_DOMAINS, getter=lambda c: c[0]) abstract = Faker().paragraph() author_comments = Faker().paragraph() remarks_for_editors = Faker().paragraph() diff --git a/submissions/forms.py b/submissions/forms.py index e65974bd8efa69ab613392323aee3569e8dd27dd..70b2b792e8f3465889566fbb4e4ac600b6b59254 100644 --- a/submissions/forms.py +++ b/submissions/forms.py @@ -14,8 +14,19 @@ from crispy_forms.layout import Layout, Div, Field, HTML, Submit class SubmissionSearchForm(forms.Form): author = forms.CharField(max_length=100, required=False, label="Author(s)") - title_keyword = forms.CharField(max_length=100, label="Title", required=False) - abstract_keyword = forms.CharField(max_length=1000, required=False, label="Abstract") + title = forms.CharField(max_length=100, required=False) + abstract = forms.CharField(max_length=1000, required=False) + subject_area = forms.CharField(max_length=10, required=False, widget=forms.Select( + choices=((None, 'Show all'),) + SCIPOST_SUBJECT_AREAS[0][1])) + + def search_results(self): + """Return all Submission objects according to search""" + return Submission.objects.public_overcomplete().filter( + title__icontains=self.cleaned_data.get('title', ''), + author_list__icontains=self.cleaned_data.get('author', ''), + abstract__icontains=self.cleaned_data.get('abstract', ''), + subject_area__icontains=self.cleaned_data.get('subject_area', '') + ) ############################### @@ -158,8 +169,7 @@ class ConsiderRefereeInvitationForm(forms.Form): class SetRefereeingDeadlineForm(forms.Form): - deadline = forms.DateField(required=False, label='', - widget=forms.SelectDateWidget) + deadline = forms.DateField(required=False, label='', widget=forms.SelectDateWidget) class VotingEligibilityForm(forms.Form): diff --git a/submissions/templates/submissions/submissions.html b/submissions/templates/submissions/submissions.html index 3ad37262ba81ad38ee39bdaf773600a6aab58fc4..380ca755ab0b7e6abc482de47cdcd41c2ba268f0 100644 --- a/submissions/templates/submissions/submissions.html +++ b/submissions/templates/submissions/submissions.html @@ -23,7 +23,7 @@ <h2 class="card-title">Search SciPost Submissions:</h2> <form action="{% url 'submissions:submissions' %}" class="small" method="get"> {{ form|bootstrap:'4,8,sm' }} - <input class="btn btn-sm btn-secondary" type="submit" name="Submit" /> + <input class="btn btn-sm btn-secondary" type="submit" value="Search"/> </form> </div> </div> diff --git a/submissions/views.py b/submissions/views.py index 343f58ca9da91d5d722fdb3474945019159328b1..b49f185de05e6050d7eba0075423db59f14458c4 100644 --- a/submissions/views.py +++ b/submissions/views.py @@ -27,9 +27,9 @@ from .forms import SubmissionIdentifierForm, SubmissionForm, SubmissionSearchFor SubmissionCycleChoiceForm from .utils import SubmissionUtils +from journals.constants import SCIPOST_JOURNALS_SPECIALIZATIONS from scipost.forms import ModifyPersonalMessageForm, RemarkForm from scipost.models import Contributor, Remark, RegistrationInvitation - from scipost.services import ArxivCaller from scipost.utils import Utils from strings import arxiv_caller_errormessages_submissions @@ -186,12 +186,13 @@ class SubmissionCreateView(PermissionRequiredMixin, CreateView): class SubmissionListView(ListView): model = Submission template_name = 'submissions/submissions.html' - form = SubmissionSearchForm() + form = SubmissionSearchForm submission_search_list = [] paginate_by = 10 def get_queryset(self): queryset = Submission.objects.public_overcomplete() + self.form = self.form(self.request.GET) if 'to_journal' in self.kwargs: queryset = queryset.filter( latest_activity__gte=timezone.now() + datetime.timedelta(days=-60), @@ -204,26 +205,17 @@ class SubmissionListView(ListView): discipline=discipline, latest_activity__gte=timezone.now() + datetime.timedelta(weeks=-int(nrweeksback)) ) - elif 'Submit' in self.request.GET: - queryset = queryset.filter( - title__icontains=self.request.GET.get('title_keyword', ''), - author_list__icontains=self.request.GET.get('author', ''), - abstract__icontains=self.request.GET.get('abstract_keyword', '') - ) + elif self.form.is_valid() and self.form.has_changed(): + queryset = self.form.search_results() return queryset.order_by('-submission_date') def get_context_data(self, **kwargs): # Call the base implementation first to get a context - context = super(SubmissionListView, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) - # Keep any search fields previously filled - initialdata = { - 'author': self.request.GET.get('author', ''), - 'title_keyword': self.request.GET.get('title_keyword', ''), - 'abstract_keyword': self.request.GET.get('abstract_keyword', '') - } - context['form'] = SubmissionSearchForm(initial=initialdata) + # Form into the context! + context['form'] = self.form # To customize display in the template if 'to_journal' in self.kwargs: @@ -232,7 +224,7 @@ class SubmissionListView(ListView): context['discipline'] = self.kwargs['discipline'] context['nrweeksback'] = self.kwargs['nrweeksback'] context['browse'] = True - elif 'Submit' not in self.request.GET: + elif not self.form.is_valid() or not self.form.has_changed(): context['recent'] = True return context diff --git a/theses/factories.py b/theses/factories.py index 76bf49969a745b620acbf464707235056f985e73..c5461a1a6160fe74397f854ed00309966ed6c06c 100644 --- a/theses/factories.py +++ b/theses/factories.py @@ -5,7 +5,7 @@ from django.utils import timezone from common.helpers.factories import FormFactory from journals.constants import SCIPOST_JOURNALS_DOMAINS from scipost.constants import SCIPOST_DISCIPLINES, SCIPOST_SUBJECT_AREAS -from scipost.factories import ContributorFactory +from scipost.models import Contributor from .models import ThesisLink from .forms import VetThesisLinkForm @@ -20,7 +20,7 @@ class ThesisLinkFactory(factory.django.DjangoModelFactory): class Meta: model = ThesisLink - requested_by = factory.SubFactory(ContributorFactory) + requested_by = factory.Iterator(Contributor.objects.all()) type = factory.Iterator(THESIS_TYPES, getter=lambda c: c[0]) domain = factory.Iterator(SCIPOST_JOURNALS_DOMAINS, getter=lambda c: c[0]) discipline = factory.Iterator(SCIPOST_DISCIPLINES, getter=lambda c: c[0]) @@ -35,7 +35,7 @@ class ThesisLinkFactory(factory.django.DjangoModelFactory): class VettedThesisLinkFactory(ThesisLinkFactory): - vetted_by = factory.SubFactory(ContributorFactory) + vetted_by = factory.Iterator(Contributor.objects.all()) vetted = True