SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit a28607fa authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Merge branch 'exportcontribs' into release2017w16

parents c58efeff 0b5b29f6
No related branches found
No related tags found
No related merge requests found
...@@ -125,7 +125,7 @@ subject_areas_dict = {} ...@@ -125,7 +125,7 @@ subject_areas_dict = {}
for k in subject_areas_raw_dict.keys(): for k in subject_areas_raw_dict.keys():
subject_areas_dict.update(dict(subject_areas_raw_dict[k])) subject_areas_dict.update(dict(subject_areas_raw_dict[k]))
CONTRIBUTOR_NORMAL = 1
CONTRIBUTOR_STATUS = ( CONTRIBUTOR_STATUS = (
# status determine the type of Contributor: # status determine the type of Contributor:
# 0: newly registered (unverified; not allowed to submit, comment or vote) # 0: newly registered (unverified; not allowed to submit, comment or vote)
...@@ -137,7 +137,7 @@ CONTRIBUTOR_STATUS = ( ...@@ -137,7 +137,7 @@ CONTRIBUTOR_STATUS = (
# -3: barred from SciPost (abusive behaviour) # -3: barred from SciPost (abusive behaviour)
# -4: disabled account (deceased) # -4: disabled account (deceased)
(0, 'newly registered'), (0, 'newly registered'),
(1, 'normal user'), (CONTRIBUTOR_NORMAL, 'normal user'),
(-1, 'not a professional scientist'), (-1, 'not a professional scientist'),
(-2, 'other account already exists'), (-2, 'other account already exists'),
(-3, 'barred from SciPost'), (-3, 'barred from SciPost'),
......
import csv
from datetime import datetime
from django.core.management.base import BaseCommand
from ...constants import CONTRIBUTOR_NORMAL
from ...models import Contributor
class Command(BaseCommand):
"""
Use this command to export the Contributor table. One could filter the export
by simply using the --group argument.
For example, one could run:
$ ./manage.py export_contributors --group 'Registered Contributors'
"""
def add_arguments(self, parser):
parser.add_argument(
'--group',
dest='group',
default=False,
type=str,
help='Filter the contributors by their group name'
)
def handle(self, *args, **kwargs):
# File variables
filename = 'export_%s_contributors_%s.csv' % (datetime.now().strftime('%Y_%m_%d_%H_%M'),
kwargs.get('group', ''))
filename = filename.replace(' ', '_')
fieldnames = ['first_name', 'last_name', 'email_address']
# Query
queryset = Contributor.objects.filter(user__is_active=True, status=CONTRIBUTOR_NORMAL)
if kwargs['group']:
queryset = queryset.filter(user__groups__name=kwargs['group'])
# Open + write the file
with open(filename, 'w', newline='') as _file:
writer = csv.writer(_file, quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(fieldnames)
n = 0
for contributor in queryset:
user = contributor.user
writer.writerow([user.first_name, user.last_name, user.email])
n += 1
self.stdout.write(self.style.SUCCESS('Successfully wrote %i Contributors to file %s.' % (
n, filename
)))
import datetime
import hashlib
import random
import re import re
import string
from django.utils import timezone from django.utils import timezone
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
...@@ -17,7 +13,6 @@ from django.core.mail import EmailMessage, EmailMultiAlternatives ...@@ -17,7 +13,6 @@ from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
from django.template import Context, Template from django.template import Context, Template
from django.utils.http import is_safe_url from django.utils.http import is_safe_url
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment