diff --git a/scipost/management/commands/add_groups_and_permissions.py b/scipost/management/commands/add_groups_and_permissions.py index b1bec7e869bd53965dfc402c1d8f29b86eb9634b..86a4ef7af77102d1c21cb930873bd6a59ee4d58f 100644 --- a/scipost/management/commands/add_groups_and_permissions.py +++ b/scipost/management/commands/add_groups_and_permissions.py @@ -5,21 +5,22 @@ from django.contrib.contenttypes.models import ContentType from scipost.models import Contributor + class Command(BaseCommand): help = 'Defines groups and permissions' - + def add_arguments(self, parser): """Append arguments optionally for setup of Contributor roles.""" - parser.add_argument('-u', '--setup-user', metavar='<username>', type=str, required=False, + parser.add_argument('-u', '--setup-user', metavar='<username>', type=str, required=False, help='Username to make registered contributor') - parser.add_argument('-a', '--make-admin', required=False, action='store_true', + parser.add_argument('-a', '--make-admin', required=False, action='store_true', help='Grant admin permissions to user (superuser only)') - parser.add_argument('-t', '--make-tester', required=False, action='store_true', + parser.add_argument('-t', '--make-tester', required=False, action='store_true', help='Grant test permissions to user') def handle(self, *args, **options): """Append all user Groups and setup a Contributor roles to user.""" - + # Create Groups SciPostAdmin, created = Group.objects.get_or_create(name='SciPost Administrators') AdvisoryBoard, created = Group.objects.get_or_create(name='Advisory Board') @@ -203,7 +204,7 @@ class Command(BaseCommand): ) self.stdout.write(self.style.SUCCESS('Successfully created groups and permissions.')) - + if options['setup_user']: # Username is given, check options try: @@ -222,8 +223,8 @@ class Command(BaseCommand): elif options['make_admin']: # Make admin failed, user not a superuser self.stdout.write(self.style.WARNING('User %s is not a superuser.' % user)) - + if options['make_tester']: # Setup test contributor user.groups.add(Testers) - self.stdout.write(self.style.SUCCESS('Successfully made %s tester.' % user)) \ No newline at end of file + self.stdout.write(self.style.SUCCESS('Successfully made %s tester.' % user)) diff --git a/scipost/management/commands/populate_db.py b/scipost/management/commands/populate_db.py new file mode 100644 index 0000000000000000000000000000000000000000..26e2d1a3ac72011e41781b943cedfd7e015b137d --- /dev/null +++ b/scipost/management/commands/populate_db.py @@ -0,0 +1,20 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth.models import User + +from ...models import Contributor + + +class Command(BaseCommand): + def add_arguments(self, parser): + parser.add_argument( + '--username', type=str, required=True, + help='Username of user to use for contributor model') + + def create_contributor(self, username): + user = User.objects.get(username=username) + contributor = Contributor(user=user, status=1, title="MR") + contributor.vetted_by = contributor + contributor.save() + + def handle(self, *args, **options): + self.create_contributor(options['username']) diff --git a/scipost/models.py b/scipost/models.py index bc1395d9aed8ff8bd567928510bda2093a80d1bb..2962da77cc4716fcf50d66db6668033d42deb937 100644 --- a/scipost/models.py +++ b/scipost/models.py @@ -258,7 +258,7 @@ class Contributor(models.Model): def public_info_as_table(self): """Prints out all publicly-accessible info as a table.""" - + template = Template(''' <table> <tr><td>Title: </td><td> </td><td>{{ title }}</td></tr>