diff --git a/affiliations/factories.py b/affiliations/factories.py new file mode 100644 index 0000000000000000000000000000000000000000..c01e316b1598c30d0bd732341c65464dbd1a64f1 --- /dev/null +++ b/affiliations/factories.py @@ -0,0 +1,26 @@ +import factory + +from .constants import INSTITUTION_TYPES +from .models import Institution, Affiliation + + +class InstitutionFactory(factory.django.DjangoModelFactory): + name = factory.Faker('company') + acronym = factory.lazy_attribute(lambda o: o.name[:16]) + country = factory.Faker('country_code') + type = factory.Iterator(INSTITUTION_TYPES, getter=lambda c: c[0]) + + class Meta: + model = Institution + django_get_or_create = ('name',) + + +class AffiliationFactory(factory.django.DjangoModelFactory): + institution = factory.SubFactory('affiliations.factories.InstitutionFactory') + contributor = factory.SubFactory('scipost.factories.ContributorFactory') + begin_date = factory.Faker('date_this_decade') + end_date = factory.Faker('future_date', end_date="+2y") + + class Meta: + model = Affiliation + django_get_or_create = ('institution', 'contributor') diff --git a/affiliations/forms.py b/affiliations/forms.py index 774a2e6a7895455701b1fbc7652c79cc6c4aa205..b46b37472ecbe4b35b7817c730bb02194d06b11d 100644 --- a/affiliations/forms.py +++ b/affiliations/forms.py @@ -1,6 +1,5 @@ from django import forms from django.forms import BaseModelFormSet, modelformset_factory -# from django.db.models import F from django_countries import countries from django_countries.fields import LazyTypedChoiceField diff --git a/colleges/factories.py b/colleges/factories.py new file mode 100644 index 0000000000000000000000000000000000000000..dc1a829b8427c6ffb2358776aabfb5e2bae15f67 --- /dev/null +++ b/colleges/factories.py @@ -0,0 +1,22 @@ +import factory + +from scipost.models import Contributor + +from .models import Fellowship + + +class BaseFellowshipFactory(factory.django.DjangoModelFactory): + contributor = factory.Iterator(Contributor.objects.all()) + start_date = factory.Faker('date_this_year') + until_date = factory.Faker('date_between', start_date="now", end_date="+2y") + + guest = factory.Faker('boolean', chance_of_getting_true=10) + + class Meta: + model = Fellowship + django_get_or_create = ('contributor', 'start_date') + abstract = True + + +class FellowshipFactory(BaseFellowshipFactory): + pass diff --git a/colleges/management/__init__.py b/colleges/management/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/colleges/management/commands/__init__.py b/colleges/management/commands/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/colleges/management/commands/create_fellowships.py b/colleges/management/commands/create_fellowships.py new file mode 100644 index 0000000000000000000000000000000000000000..b28ad5069950659c47e69e2794859309079bed2b --- /dev/null +++ b/colleges/management/commands/create_fellowships.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand + +from colleges import factories + + +class Command(BaseCommand): + help = 'Create random Fellowships objects using the factories.' + + def add_arguments(self, parser): + parser.add_argument( + 'number', action='store', default=0, type=int, + help='Number of Fellowships to add') + + def handle(self, *args, **kwargs): + self.create_fellowships(kwargs['number']) + + def create_fellowships(self, n): + factories.FellowshipFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created {n} Fellowships.'.format(n=n))) diff --git a/commentaries/factories.py b/commentaries/factories.py index 62f07eede1701e08f784abb3591ee728f34c1038..0e0f2df751417dc915d3e88002a2cb8e085d4a0c 100644 --- a/commentaries/factories.py +++ b/commentaries/factories.py @@ -30,10 +30,9 @@ class BaseCommentaryFactory(factory.django.DjangoModelFactory): pub_date = factory.Faker('date_this_decade') pub_abstract = factory.Faker('paragraph') - @factory.post_generation - def arxiv_link(self, create, extracted, **kwargs): - self.arxiv_link = 'https://arxiv.org/abs/%s' % self.arxiv_identifier - self.arxiv_or_DOI_string = self.arxiv_identifier + arxiv_link = factory.lazy_attribute(lambda o: 'https://arxiv.org/abs/%s' % o.arxiv_identifier) + arxiv_or_DOI_string = factory.lazy_attribute(lambda o: ( + o.arxiv_identifier if o.arxiv_identifier else o.pub_DOI)) @factory.post_generation def create_urls(self, create, extracted, **kwargs): @@ -77,3 +76,9 @@ class UnpublishedCommentaryFactory(BaseCommentaryFactory): class UnvettedUnpublishedCommentaryFactory(UnpublishedCommentaryFactory): vetted = False vetted_by = None + + +class PublishedCommentaryFactory(BaseCommentaryFactory): + arxiv_identifier = '' + arxiv_link = '' + arxiv_or_DOI_string = factory.lazy_attribute(lambda o: o.pub_DOI) diff --git a/commentaries/management/__init__.py b/commentaries/management/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/commentaries/management/commands/__init__.py b/commentaries/management/commands/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/commentaries/management/commands/create_commentaries.py b/commentaries/management/commands/create_commentaries.py new file mode 100644 index 0000000000000000000000000000000000000000..1353a86dd1794882a4587d0f916e98f7ddd9ad33 --- /dev/null +++ b/commentaries/management/commands/create_commentaries.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand + +from commentaries import factories + + +class Command(BaseCommand): + help = 'Create random Commentaries objects using the factories.' + + def add_arguments(self, parser): + parser.add_argument( + 'number', action='store', default=0, type=int, + help='Number of Commentaries to add') + + def handle(self, *args, **kwargs): + self.create_commentaries(kwargs['number']) + + def create_commentaries(self, n): + factories.CommentaryFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created {n} Commentaries.'.format(n=n))) diff --git a/comments/factories.py b/comments/factories.py index 46a68bf19b4539ebc3789bea13563ee7df653ad9..bd6a3c784d52457cf1ae506921b27bb73176df37 100644 --- a/comments/factories.py +++ b/comments/factories.py @@ -1,3 +1,4 @@ +import random import factory from commentaries.models import Commentary @@ -44,9 +45,15 @@ class CommentaryCommentFactory(CommentFactory): class SubmissionCommentFactory(CommentFactory): content_object = factory.Iterator(Submission.objects.all()) + @factory.post_generation + def replies(self, create, extracted, **kwargs): + if create: + for i in range(random.randint(0, 2)): + ReplyCommentFactory(content_object=self) + class ReplyCommentFactory(CommentFactory): - content_object = factory.SubFactory(SubmissionCommentFactory) + content_object = factory.SubFactory(SubmissionCommentFactory, replies=False) is_author_reply = factory.Faker('boolean') diff --git a/common/helpers/__init__.py b/common/helpers/__init__.py index 91c520216a14b8112d5c118dae34754c8e438d58..88f0fb9216d67f08929dc56e73245ed3da5fc8ee 100644 --- a/common/helpers/__init__.py +++ b/common/helpers/__init__.py @@ -93,14 +93,22 @@ def random_external_doi(): '1742-5468', '0550-3213(96)' )) - return '10.%s/%s.%s' % ( - random_digits(5), journal, random_pub_number()) + return '10.%s/%s.%s' % (random_digits(5), journal, random_pub_number()) def random_digits(n): return "".join(random.choice(string.digits) for _ in range(n)) +def generate_orcid(): + return '{}-{}-{}-{}'.format( + random_digits(4), + random_digits(4), + random_digits(4), + random_digits(4), + ) + + def filter_keys(dictionary, keys_to_keep): # Field is empty if not on model. return {key: dictionary.get(key, "") for key in keys_to_keep} diff --git a/journals/management/commands/create_issues.py b/journals/management/commands/create_issues.py new file mode 100644 index 0000000000000000000000000000000000000000..ea07e6ac7ca831da3148b22110b9ca7e4a28576f --- /dev/null +++ b/journals/management/commands/create_issues.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand + +from journals import factories + + +class Command(BaseCommand): + help = 'Create Issue objects using the factories.' + + def add_arguments(self, parser): + parser.add_argument( + 'number', action='store', default=0, type=int, + help='Number of Issues to add') + + def handle(self, *args, **kwargs): + self.create_issues(kwargs['number']) + + def create_issues(self, n): + factories.IssueFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created {n} Issues.'.format(n=n))) diff --git a/journals/management/commands/create_journals.py b/journals/management/commands/create_journals.py new file mode 100644 index 0000000000000000000000000000000000000000..eaaa425050f9016ea0ed2ca9dde902b553bad262 --- /dev/null +++ b/journals/management/commands/create_journals.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand + +from journals import factories + + +class Command(BaseCommand): + help = 'Create Journal objects using the factories.' + + def add_arguments(self, parser): + parser.add_argument( + 'number', action='store', default=0, type=int, + help='Number of Journals to add') + + def handle(self, *args, **kwargs): + self.create_journals(kwargs['number']) + + def create_journals(self, n): + factories.JournalFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created {n} Journals.'.format(n=n))) diff --git a/journals/management/commands/create_volumes.py b/journals/management/commands/create_volumes.py new file mode 100644 index 0000000000000000000000000000000000000000..29dce2f400ace4310f7996774503965260707425 --- /dev/null +++ b/journals/management/commands/create_volumes.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand + +from journals import factories + + +class Command(BaseCommand): + help = 'Create Volume objects using the factories.' + + def add_arguments(self, parser): + parser.add_argument( + 'number', action='store', default=0, type=int, + help='Number of Volumes to add') + + def handle(self, *args, **kwargs): + self.create_volumes(kwargs['number']) + + def create_volumes(self, n): + factories.VolumeFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created {n} Volumes.'.format(n=n))) diff --git a/news/management/__init__.py b/news/management/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/news/management/commands/__init__.py b/news/management/commands/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/news/management/commands/create_news.py b/news/management/commands/create_news.py new file mode 100644 index 0000000000000000000000000000000000000000..96e170762e48e6a2b57aa4e741786bff6b7247b2 --- /dev/null +++ b/news/management/commands/create_news.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand + +from news import factories + + +class Command(BaseCommand): + help = 'Create random News Item objects using the factories.' + + def add_arguments(self, parser): + parser.add_argument( + 'number', action='store', default=0, type=int, + help='Number of News items to add') + + def handle(self, *args, **kwargs): + self.create_news_items(kwargs['number']) + + def create_news_items(self, n): + factories.NewsItemFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created {n} News Items.'.format(n=n))) diff --git a/scipost/factories.py b/scipost/factories.py index 67cb4e2df31821db68e780bbf44fef72d83636c2..0e3f561745d184e402192cf4de0c5d5a1f88ad28 100644 --- a/scipost/factories.py +++ b/scipost/factories.py @@ -4,31 +4,36 @@ import random from django.contrib.auth import get_user_model from django.contrib.auth.models import Group +from common.helpers import generate_orcid from submissions.models import Submission from .models import Contributor, EditorialCollege, EditorialCollegeFellowship, Remark from .constants import TITLE_CHOICES, SCIPOST_SUBJECT_AREAS -from django_countries.data import COUNTRIES -from faker import Faker - class ContributorFactory(factory.django.DjangoModelFactory): - title = random.choice(list(dict(TITLE_CHOICES).keys())) + title = factory.Iterator(TITLE_CHOICES, getter=lambda c: c[0]) user = factory.SubFactory('scipost.factories.UserFactory', contributor=None) status = 1 # normal user - vetted_by = factory.SubFactory('scipost.factories.ContributorFactory', vetted_by=None) - personalwebpage = factory.Faker('url') - country_of_employment = factory.Iterator(list(COUNTRIES)) - affiliation = factory.Faker('company') + vetted_by = factory.Iterator(Contributor.objects.all()) + personalwebpage = factory.Faker('uri') expertises = factory.Iterator(SCIPOST_SUBJECT_AREAS[0][1], getter=lambda c: [c[0]]) - personalwebpage = factory.Faker('domain_name') + orcid_id = factory.lazy_attribute(lambda n: generate_orcid()) address = factory.Faker('address') + invitation_key = factory.Faker('md5') + activation_key = factory.Faker('md5') + key_expires = factory.Faker('future_datetime') class Meta: model = Contributor django_get_or_create = ('user',) + @factory.post_generation + def add_to_vetting_editors(self, create, extracted, **kwargs): + if create: + from affiliations.factories import AffiliationFactory + AffiliationFactory(contributor=self) + class VettingEditorFactory(ContributorFactory): @factory.post_generation @@ -69,7 +74,7 @@ class EditorialCollegeFactory(factory.django.DjangoModelFactory): class Meta: model = EditorialCollege - django_get_or_create = ('discipline', ) + django_get_or_create = ('discipline',) class EditorialCollegeFellowshipFactory(factory.django.DjangoModelFactory): @@ -85,7 +90,7 @@ class SubmissionRemarkFactory(factory.django.DjangoModelFactory): contributor = factory.Iterator(Contributor.objects.all()) submission = factory.Iterator(Submission.objects.all()) date = factory.Faker('date_time_this_decade') - remark = factory.lazy_attribute(lambda x: Faker().paragraph()) + remark = factory.Faker('paragraph') class Meta: model = Remark diff --git a/scipost/management/commands/create_contributors.py b/scipost/management/commands/create_contributors.py new file mode 100644 index 0000000000000000000000000000000000000000..025513c74d49b6f82a77268706cf84d314a950bb --- /dev/null +++ b/scipost/management/commands/create_contributors.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand + +from scipost import factories + + +class Command(BaseCommand): + help = 'Create random Contributor objects using the factories.' + + def add_arguments(self, parser): + parser.add_argument( + 'number', action='store', default=0, type=int, + help='Number of Contributors to add') + + def handle(self, *args, **kwargs): + self.create_contributors(kwargs['number']) + + def create_contributors(self, n): + factories.ContributorFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created {n} Contributors.'.format(n=n))) diff --git a/scipost/management/commands/create_remarks.py b/scipost/management/commands/create_remarks.py new file mode 100644 index 0000000000000000000000000000000000000000..19ebe3e92c5098192ae4880b149f5822018528f5 --- /dev/null +++ b/scipost/management/commands/create_remarks.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand + +from scipost import factories + + +class Command(BaseCommand): + help = 'Create random Remark objects (related to a Submission) using the factories.' + + def add_arguments(self, parser): + parser.add_argument( + 'number', action='store', default=0, type=int, + help='Number of Remarks to add') + + def handle(self, *args, **kwargs): + self.create_remarks(kwargs['number']) + + def create_remarks(self, n): + factories.SubmissionRemarkFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created {n} Remarks.'.format(n=n))) diff --git a/scipost/management/commands/populate_db.py b/scipost/management/commands/populate_db.py index 4c3819b066b4d9f2d11ddb1dffb6ef1e3a0790f8..4812d71e6fa2958a98c7792ff5c97579aa94b83e 100644 --- a/scipost/management/commands/populate_db.py +++ b/scipost/management/commands/populate_db.py @@ -1,33 +1,11 @@ from django.core.management.base import BaseCommand -from commentaries.factories import CommentaryFactory -from comments.factories import CommentaryCommentFactory, SubmissionCommentFactory,\ +from comments.factories import CommentaryCommentFactory,\ ThesislinkCommentFactory, ReplyCommentFactory -from scipost.factories import SubmissionRemarkFactory -from journals.factories import JournalFactory, VolumeFactory, IssueFactory -from news.factories import NewsItemFactory -from theses.factories import ThesisLinkFactory - -from ...factories import ContributorFactory, EditorialCollegeFactory,\ - EditorialCollegeFellowshipFactory class Command(BaseCommand): def add_arguments(self, parser): - parser.add_argument( - '--news', - action='store_true', - dest='news', - default=False, - help='Add NewsItems', - ) - parser.add_argument( - '--commentaries', - action='store_true', - dest='commentaries', - default=False, - help='Add 5 Commentaries', - ) parser.add_argument( '--comments', action='store_true', @@ -35,109 +13,13 @@ class Command(BaseCommand): default=False, help='Add 10 Comments', ) - parser.add_argument( - '--contributor', - action='store_true', - dest='contributor', - default=False, - help='Add 5 Contributors', - ) - parser.add_argument( - '--college', - action='store_true', - dest='editorial-college', - 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( - '--remarks', - action='store_true', - dest='remarks', - default=False, - help='Add 5 new Remarks linked to Submissions', - ) - parser.add_argument( - '--theses', - action='store_true', - dest='theses', - default=False, - help='Add 5 ThesisLinks', - ) - parser.add_argument( - '--all', - action='store_true', - dest='all', - default=False, - help='Add all available', - ) def handle(self, *args, **kwargs): - if kwargs['contributor'] or kwargs['all']: - n = 5 - if kwargs['all']: - # Add extra Contributors for a bit more diversity - n += 10 - self.create_contributors(n) - if kwargs['commentaries'] or kwargs['all']: - self.create_commentaries() - if kwargs['comments'] or kwargs['all']: + if kwargs['comments']: self.create_comments() - if kwargs['editorial-college'] or kwargs['all']: - self.create_editorial_college() - self.create_editorial_college_fellows() - if kwargs['news'] or kwargs['all']: - self.create_news_items() - if kwargs['pubset'] or kwargs['all']: - self.create_pubset() - if kwargs['remarks'] or kwargs['all']: - self.create_remarks() - if kwargs['theses'] or kwargs['all']: - self.create_theses() - - 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): - CommentaryFactory.create_batch(5) - self.stdout.write(self.style.SUCCESS('Successfully created 5 Commentaries.')) def create_comments(self): CommentaryCommentFactory.create_batch(3) - SubmissionCommentFactory.create_batch(4) ReplyCommentFactory.create_batch(2) ThesislinkCommentFactory.create_batch(3) self.stdout.write(self.style.SUCCESS('Successfully created 10 Comments.')) - - def create_editorial_college(self): - EditorialCollegeFactory.create_batch(5) - self.stdout.write(self.style.SUCCESS('Successfully created 5 Editorial College\'s.')) - - def create_editorial_college_fellows(self): - EditorialCollegeFellowshipFactory.create_batch(5) - self.stdout.write(self.style.SUCCESS('Successfully created 5 Editorial College Fellows.')) - - def create_news_items(self): - NewsItemFactory.create_batch(5) - self.stdout.write(self.style.SUCCESS('Successfully created 5 News items.')) - - def create_pubset(self): - JournalFactory.create_batch(4) # 4 == all Journals - VolumeFactory.create_batch(3) - IssueFactory.create_batch(12) - self.stdout.write(self.style.SUCCESS('Successfully created 12 Issues.')) - - def create_remarks(self): - SubmissionRemarkFactory.create_batch(5) - self.stdout.write(self.style.SUCCESS('Successfully created 5 Remarks.')) - - def create_theses(self): - ThesisLinkFactory.create_batch(5) - self.stdout.write(self.style.SUCCESS('Successfully created 5 ThesisLinks.')) diff --git a/submissions/factories.py b/submissions/factories.py index 27ecad095a819fbe1b9c9ca1cfea91db56a1875e..568ff2f7d43d7e507da0d22bba8ff7f94addf7bd 100644 --- a/submissions/factories.py +++ b/submissions/factories.py @@ -2,6 +2,7 @@ import factory import pytz import random +from comments.factories import SubmissionCommentFactory from scipost.constants import SCIPOST_SUBJECT_AREAS from scipost.models import Contributor from journals.constants import SCIPOST_JOURNALS_DOMAINS @@ -12,7 +13,7 @@ from .constants import STATUS_UNASSIGNED, STATUS_EIC_ASSIGNED, STATUS_RESUBMISSI STATUS_PUBLISHED, SUBMISSION_TYPE, STATUS_RESUBMITTED, STATUS_VETTED,\ REFEREE_QUALIFICATION, RANKING_CHOICES, QUALITY_SPEC, REPORT_REC,\ REPORT_STATUSES, STATUS_UNVETTED, STATUS_DRAFT -from .models import Submission, Report, RefereeInvitation +from .models import Submission, Report, RefereeInvitation, EICRecommendation from faker import Faker @@ -95,6 +96,17 @@ class EICassignedSubmissionFactory(SubmissionFactory): for i in range(random.randint(0, 2)): FulfilledRefereeInvitationFactory(submission=self) + @factory.post_generation + def comments(self, create, extracted, **kwargs): + if create: + for i in range(random.randint(0, 3)): + SubmissionCommentFactory(content_object=self) + + @factory.post_generation + def eic_recommendation(self, create, extracted, **kwargs): + if create: + EICRecommendationFactory(submission=self) + class ResubmittedSubmissionFactory(EICassignedSubmissionFactory): """ @@ -294,6 +306,11 @@ class AcceptedRefereeInvitationFactory(RefereeInvitationFactory): date_responded = factory.lazy_attribute(lambda o: Faker().date_time_between( start_date=o.date_invited, end_date="now", tzinfo=pytz.UTC)) + @factory.post_generation + def report(self, create, extracted, **kwargs): + if create: + VettedReportFactory(submission=self.submission, author=self.referee) + class FulfilledRefereeInvitationFactory(AcceptedRefereeInvitationFactory): fulfilled = True @@ -302,7 +319,8 @@ class FulfilledRefereeInvitationFactory(AcceptedRefereeInvitationFactory): @factory.post_generation def report(self, create, extracted, **kwargs): - VettedReportFactory(submission=self.submission, author=self.referee) + if create: + VettedReportFactory(submission=self.submission, author=self.referee) class CancelledRefereeInvitationFactory(AcceptedRefereeInvitationFactory): @@ -310,3 +328,18 @@ class CancelledRefereeInvitationFactory(AcceptedRefereeInvitationFactory): cancelled = True date_responded = factory.lazy_attribute(lambda o: Faker().date_time_between( start_date=o.date_invited, end_date="now", tzinfo=pytz.UTC)) + + +class EICRecommendationFactory(factory.django.DjangoModelFactory): + submission = factory.Iterator(Submission.objects.all()) + date_submitted = factory.lazy_attribute(lambda o: Faker().date_time_between( + start_date=o.submission.submission_date, end_date="now", tzinfo=pytz.UTC)) + remarks_for_authors = factory.Faker('paragraph') + requested_changes = factory.Faker('paragraph') + remarks_for_editorial_college = factory.Faker('paragraph') + recommendation = factory.Iterator(REPORT_REC[1:], getter=lambda c: c[0]) + version = 1 + active = True + + class Meta: + model = EICRecommendation diff --git a/theses/management/__init__.py b/theses/management/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/theses/management/commands/__init__.py b/theses/management/commands/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/theses/management/commands/create_theses.py b/theses/management/commands/create_theses.py new file mode 100644 index 0000000000000000000000000000000000000000..8c98134929bcf3ff3c5aecc8be334ba2df9c900e --- /dev/null +++ b/theses/management/commands/create_theses.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand + +from theses import factories + + +class Command(BaseCommand): + help = 'Create random Thesis objects using the factories.' + + def add_arguments(self, parser): + parser.add_argument( + 'number', action='store', default=0, type=int, + help='Number of Theses to add') + + def handle(self, *args, **kwargs): + self.create_theses(kwargs['number']) + + def create_theses(self, n): + factories.ThesisLinkFactory.create_batch(n) + self.stdout.write(self.style.SUCCESS('Successfully created {n} Theses.'.format(n=n)))