Skip to content
Snippets Groups Projects

Refactor

Merged Jan Maximilian Michal requested to merge refactor into master
2 files
+ 2
2
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 12
10
import argparse
import argparse
import csv
import csv
 
import json
import os
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'grady.settings')
import secrets
import secrets
import sys
import sys
import json
import django
import django
django.setup()
from django.contrib.auth.models import User
from django.contrib.auth.models import User
from core.models import Student, Submission
import util.importer
import util.importer
 
from core.models import Student, Submission
 
 
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'grady.settings')
 
 
django.setup()
 
def parseme():
def parseme():
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser()
@@ -81,7 +83,7 @@ def parseme():
@@ -81,7 +83,7 @@ def parseme():
return parser.parse_args()
return parser.parse_args()
def handle_passwordlist(output=sys.stdout, instance="", **kwargs):
def handle_passwordlist(output=sys.stdout, instance=""):
with open('/usr/share/dict/words') as words:
with open('/usr/share/dict/words') as words:
choose_from = list({word.strip().lower()
choose_from = list({word.strip().lower()
for word in words if 5 < len(word) < 8})
for word in words if 5 < len(word) < 8})
@@ -99,7 +101,7 @@ def handle_passwordlist(output=sys.stdout, instance="", **kwargs):
@@ -99,7 +101,7 @@ def handle_passwordlist(output=sys.stdout, instance="", **kwargs):
student.user.username, password, instance])
student.user.username, password, instance])
def handle_enableusers(switch, exclude, include, **kwargs):
def handle_enableusers(switch, exclude, include):
if include:
if include:
for user in User.objects.filter(username__in=include):
for user in User.objects.filter(username__in=include):
@@ -111,7 +113,7 @@ def handle_enableusers(switch, exclude, include, **kwargs):
@@ -111,7 +113,7 @@ def handle_enableusers(switch, exclude, include, **kwargs):
user.save()
user.save()
def handle_replaceusernames(matno2username_dict, **kwargs):
def handle_replaceusernames(matno2username_dict):
matno2username = json.JSONDecoder().decode(matno2username_dict.read())
matno2username = json.JSONDecoder().decode(matno2username_dict.read())
for student in Student.objects.all():
for student in Student.objects.all():
if student.matrikel_no in matno2username:
if student.matrikel_no in matno2username:
@@ -120,12 +122,12 @@ def handle_replaceusernames(matno2username_dict, **kwargs):
@@ -120,12 +122,12 @@ def handle_replaceusernames(matno2username_dict, **kwargs):
student.user.save()
student.user.save()
def handle_extractsubmissions(output, **kwargs):
def handle_extractsubmissions():
for submission in Submission.objects.filter(feedback__isnull=False).order_by('type'):
for submission in Submission.objects.filter(feedback__isnull=False).order_by('type'):
print(submission.feedback.score, repr(submission.text), file=open(str(submission.type).replace(' ', '_'), 'a'))
print(submission.feedback.score, repr(submission.text), file=open(str(submission.type).replace(' ', '_'), 'a'))
def handle_importer(**kwargs):
def handle_importer():
util.importer.start()
util.importer.start()
def main():
def main():
Loading