JsonDecodeError) from uiodata import subjects # may be something like http://devilry.myorganzation.com/some/subpath/ in production devilry_url = 'http://localhost:8000' # Log in # - login url may be somthing else if devilry does not handle the login, # however this example assumes that devilry is used for login, and the devilry # login form is at /authenticate/login login_url = '{0}/authenticate/login'.format(devilry_url) logincookie = login(login_url, username='******', password='******') # Create proxy classes which makes it natural to program against the # RESTful interface using python. restful_factory = RestfulFactory(devilry_url) SimplifiedNode = restful_factory.make("/administrator/restfulsimplifiednode/") SimplifiedSubject = restful_factory.make( "/administrator/restfulsimplifiedsubject/") SimplifiedPeriod = restful_factory.make( "/administrator/restfulsimplifiedperiod/") SimplifiedAssignment = restful_factory.make( "/administrator/restfulsimplifiedassignment/") SimplifiedAssignmentGroup = restful_factory.make( "/administrator/restfulsimplifiedassignmentgroup/") uio = {} matnat = {} ifi = {}
login_url = '{0}/authenticate/login'.format(devilry_url) logincookie = login(login_url, username=username, password=password) ## Login using other form parameters and url. ## (just an example for setups that do not authenticate through Devilry, this one for UiO.) #login_url = '{0}/login'.format(devilry_url) #logincookie = login(login_url, user=username, password=password) ## Load the RESTful API # Creates proxy classes which makes it natural to program against the RESTful # interface using python. Exactly what you load here depends on what you want # to access. See the _Public RESTful API_ section of the API docs at # http://devilry.org for a complete overview and documentation for all our # APIs: # http://devilry.org/devilry-django/dev/restfulapi/administrator/index.html#restful-apiadministrator restful_factory = RestfulFactory(devilry_url) SimplifiedPeriod = restful_factory.make( '/administrator/restfulsimplifiedperiod/') SimplifiedAssignment = restful_factory.make( '/administrator/restfulsimplifiedassignment/') SimplifiedAssignmentGroup = restful_factory.make( '/administrator/restfulsimplifiedassignmentgroup/') SimplifiedExaminer = restful_factory.make( '/administrator/restfulsimplifiedexaminer/') #################################################################### # The actual program #################################################################### def find_period():
JsonDecodeError) from uiodata import subjects # may be something like http://devilry.myorganzation.com/some/subpath/ in production devilry_url = 'http://localhost:8000' # Log in # - login url may be somthing else if devilry does not handle the login, # however this example assumes that devilry is used for login, and the devilry # login form is at /authenticate/login login_url = '{0}/authenticate/login'.format(devilry_url) logincookie = login(login_url, username='******', password='******') # Create proxy classes which makes it natural to program against the # RESTful interface using python. restful_factory = RestfulFactory(devilry_url) SimplifiedNode = restful_factory.make("/administrator/restfulsimplifiednode/") SimplifiedSubject = restful_factory.make("/administrator/restfulsimplifiedsubject/") SimplifiedPeriod = restful_factory.make("/administrator/restfulsimplifiedperiod/") SimplifiedAssignment = restful_factory.make("/administrator/restfulsimplifiedassignment/") SimplifiedAssignmentGroup = restful_factory.make("/administrator/restfulsimplifiedassignmentgroup/") uio = {} matnat = {} ifi = {} def all_search(): """Searches through Node, Subject and Period""" print 'Every node in the system:'
from devilrycliscriptslib.queries import find_period_id_by_shortnames from devilrycliscriptslib.queries import aggregate_points_for_each_student from devilrycliscriptslib.utils import split_path argparser = ArgumentParser(description=('Show a table with CSV results for each ' 'student on the entire period ' 'aggregated. Meaning of the numbers in ' 'the table: 0: No deliveries, 1: Not approved, 2: Approved')) add_common_args(argparser) argparser.add_argument('--period', required=True, help='Path to the period. E.g: "duck1010.spring2010"') args = argparser.parse_args() logincookie = login_using_args(args, getpass()) restful_factory = RestfulFactory(args.url) PeriodApi = restful_factory.make('/administrator/restfulsimplifiedperiod/') AssignmentApi = restful_factory.make('/administrator/restfulsimplifiedassignment/') AssignmentGroupApi = restful_factory.make('/administrator/restfulsimplifiedassignmentgroup/') def csv_approvedstats(students, all_assignments): """ Create a csv table of students. For each assignment, a number is added: 0: No deliveries 1: Not approved 2: Approved """ # Print header ({0:<20} format string makes positional arg 0 occupy 20 chars left aligned) sys.stdout.write('USER') # Ending comma prevent newline
login_url = '{0}/authenticate/login'.format(devilry_url) logincookie = login(login_url, username=username, password=password) ## Login using other form parameters and url. ## (just an example for setups that do not authenticate through Devilry, this one for UiO.) #login_url = '{0}/login'.format(devilry_url) #logincookie = login(login_url, user=username, password=password) ## Load the RESTful API # Creates proxy classes which makes it natural to program against the RESTful # interface using python. Exactly what you load here depends on what you want # to access. See the _Public RESTful API_ section of the API docs at # http://devilry.org for a complete overview and documentation for all our # APIs: # http://devilry.org/devilry-django/dev/restfulapi/administrator/index.html#restful-apiadministrator restful_factory = RestfulFactory(devilry_url) SimplifiedPeriod = restful_factory.make('/administrator/restfulsimplifiedperiod/') SimplifiedAssignment = restful_factory.make('/administrator/restfulsimplifiedassignment/') SimplifiedAssignmentGroup = restful_factory.make('/administrator/restfulsimplifiedassignmentgroup/') SimplifiedExaminer = restful_factory.make('/administrator/restfulsimplifiedexaminer/') #################################################################### # The actual program #################################################################### def find_period(): """ Find the requested period. """ periodsearch = SimplifiedPeriod.search(logincookie, filters=[{'field':'short_name', 'comp':'exact', 'value':period_short_name}, {'field':'parentnode__short_name', 'comp':'exact', 'value':subject_short_name}],
from devilrycliscriptslib.argparsewrapper import ArgumentParser from devilrycliscriptslib.login import login_using_args from devilrycliscriptslib.commonargs import add_common_args from devilrycliscriptslib.queries import find_groups_in_assignment from devilrycliscriptslib.queries import find_assignment_id_by_shortnames from devilrycliscriptslib.utils import split_path argparser = ArgumentParser(description='List groups on an assignment as json encoded data.') add_common_args(argparser) argparser.add_argument('--assignment', required=True, help='Path to assignment. E.g: "duck1010.spring2010.assignment1"') args = argparser.parse_args() logincookie = login_using_args(args, getpass()) restful_factory = RestfulFactory(args.url) AssignmentGroupApi = restful_factory.make('/administrator/restfulsimplifiedassignmentgroup/') AssignmentApi = restful_factory.make('/administrator/restfulsimplifiedassignment/') DeadlineApi = restful_factory.make('/administrator/restfulsimplifieddeadline/') try: path = split_path(args.assignment, '--assignment', 3) source_assignment_id = find_assignment_id_by_shortnames(AssignmentApi, logincookie, *path) except LookupError: raise SystemExit('Assignment {0} not found.'.format(args.assignment)) groups = find_groups_in_assignment(AssignmentGroupApi, logincookie, source_assignment_id, result_fieldgroups=['feedback', 'users', 'tags']) print json.dumps(groups, indent=2)
from devilrycliscriptslib.login import login_using_args from devilrycliscriptslib.commonargs import add_common_args from devilrycliscriptslib.queries import find_period_id_by_shortnames from devilrycliscriptslib.queries import find_all_examiners_in_period from devilrycliscriptslib.queries import find_all_assignmentgroups_in_period from devilrycliscriptslib.utils import split_path argparser = ArgumentParser(description='Show a table with the number of groups corrected by each examiner.') add_common_args(argparser) argparser.add_argument('--period', required=True, help='Path to the period. E.g: "duck1010.spring2010"') args = argparser.parse_args() logincookie = login_using_args(args, getpass()) restful_factory = RestfulFactory(args.url) AssignmentGroupApi = restful_factory.make('/administrator/restfulsimplifiedassignmentgroup/') PeriodApi = restful_factory.make('/administrator/restfulsimplifiedperiod/') ExaminerApi = restful_factory.make('/administrator/restfulsimplifiedexaminer/') StaticFeedbackApi = restful_factory.make('/administrator/restfulsimplifiedstaticfeedback/') def list_number_of_assignments_corrected_by_examiners(period): print 'Reading information about all examiners. This takes a lot of time for large courses...' examiners_by_group = find_all_examiners_in_period(ExaminerApi, logincookie, period) examinerusers = {} for groupid, examiners in examiners_by_group.iteritems(): # NOTE: Exceptionally inefficient method of getting the username->name map for all examiners for examiner in examiners: examinerusers[examiner['user']] = examiner['user__devilryuserprofile__full_name'] or examiner['user__username'] groups = find_all_assignmentgroups_in_period(AssignmentGroupApi, logincookie, period,
add_common_args(argparser) argparser.add_argument('--assignment', required=True, help='Path to assignment. E.g: "duck1010.spring2010.assignment1"') argparser.add_argument('--role', required=True, help='Your role. Valid values: "examiner", "administrator".') argparser.add_argument('--outdir', required=True, help='Local filesystem directory to put the result in. Will create a directory named what you put in ``--assignment`` within this directory.') args = argparser.parse_args() logincookie = login_using_args(args, getpass()) outdir = args.outdir role = args.role if not role in ('examiner', 'administrator'): raise SystemExit('Invalid role: {}. See --help.'.format(role)) restful_factory = RestfulFactory(args.url) AssignmentApi = restful_factory.make('/{}/restfulsimplifiedassignment/'.format(role)) AssignmentGroupApi = restful_factory.make('/{}/restfulsimplifiedassignmentgroup/'.format(role)) DeadlineApi = restful_factory.make('/{}/restfulsimplifieddeadline/'.format(role)) DeliveryApi = restful_factory.make('/{}/restfulsimplifieddelivery/'.format(role)) FileMetaApi = restful_factory.make('/{}/restfulsimplifiedfilemeta/'.format(role)) FileMetaDownloadApi = restful_factory.make('/student/show-delivery/filedownload/') try: path = split_path(args.assignment, '--assignment', 3) source_assignment_id = find_assignment_id_by_shortnames(AssignmentApi, logincookie, *path) except LookupError: raise SystemExit('Assignment {0} not found.'.format(args.assignment)) groups = find_groups_in_assignment(AssignmentGroupApi,