Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse all useful information from dataporten #14

Open
JakobGM opened this issue Jun 11, 2017 · 14 comments
Open

Parse all useful information from dataporten #14

JakobGM opened this issue Jun 11, 2017 · 14 comments

Comments

@JakobGM
Copy link
Owner

JakobGM commented Jun 11, 2017

API: from dataporten.groups import active_courses

@JakobGM
Copy link
Owner Author

JakobGM commented Jun 11, 2017

Should use a json dump for test driving

@JakobGM
Copy link
Owner Author

JakobGM commented Jun 11, 2017

Use proxy model?
https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models

Probably not, as we would want access to user.dataporten.active_courses in the templates.
Middleware?

EDIT: Actually both, see below!

@JakobGM
Copy link
Owner Author

JakobGM commented Jun 11, 2017

Solution:
dataporten.middleware.DataportenGroupsMiddleware should use a proxy model in order to replace request.user. It is very important that the middleware is placed after any authentication backend middleware, but before any app middleware.

Here is how to replace the class type of request.user with the proxy class: stack overflow. This is the way to go!

Use class based middleware.

The monkey patch needs to be applied before the view is called, i.e. before self.get_repsonse(request) is invoked.

@JakobGM
Copy link
Owner Author

JakobGM commented Jun 14, 2017

So the middleware uses a proxy model which expands request.user with a dataporten property.
The dataporten property is class based (or something else that establishes a namespace), with a cached group-api request in __init__.
Further json parsing should be lazely evaluated and saved to a dict.
The proper models in semesterpage should implement __in__ for membership evaluation.

@JakobGM
Copy link
Owner Author

JakobGM commented Jun 15, 2017

This api will often be used in order to retrieve a set of course codes of particular interest. Such a course code will then be used like this: semesterpage.models.Course.objects.get(course_code=course_code). We should therefore consider setting db_index=True on the Course model. See chapter 7.6 in Two Scoops of Django.

@JakobGM
Copy link
Owner Author

JakobGM commented Jun 19, 2017

If a large chunk of the dataporten groups data ends up only being used in templates, rather than in view logic, it might be worth considering pulling this logic into a custom context processor.

@JakobGM
Copy link
Owner Author

JakobGM commented Jul 12, 2017

Should create a class which receives the JSON from the groups API, and delegates the respective groups to their respective parsers. For instance Course, StudyProgram, and University. This class is also responsible for splitting the courses based on if they are active or not.

@JakobGM JakobGM changed the title Dataporten app needs an active_courses util Parse all useful information from dataporten Jul 12, 2017
@JakobGM
Copy link
Owner Author

JakobGM commented Jul 12, 2017

Should be easy to add an extra predicate to semesterpage.rules which grants contribution access if the student is enrolled in the course. Add it as an OR predicate, and all the legacy logic can be left alone (and continually offer more detailed access control).

@JakobGM
Copy link
Owner Author

JakobGM commented Jul 12, 2017

A Semester class can be written which handles:

  • Year, i.e. 2017
  • Spring / Autumn, i.e. V / H
  • School year, i.e. 2016-2017
  • Subtraction: H2017 - V2016 = 3

It should be initialized with a Datetime object, and will allow us to grant access to courses which are taken in the same school year, within the last x semesters, etc.

@hambro
Copy link
Collaborator

hambro commented Jul 12, 2017

Maybe look at Django REST framework to parse the JSON objects. A lot of built-in functionality, maybe overkill tho.

@hambro
Copy link
Collaborator

hambro commented Jul 12, 2017

@JakobGM
Copy link
Owner Author

JakobGM commented Jul 26, 2017

For caching we can use:
from django.utils.functional imported cached_property.

@JakobGM
Copy link
Owner Author

JakobGM commented Jul 31, 2017

Now we are only missing:

  • Parsing of org and orgunit types, i.e. university and faculty, respectively.
  • DataportenGroupManager should be able to return Course-instances from the last n semesters.

And then we are done!

@JakobGM JakobGM removed the Next task label Aug 2, 2017
@JakobGM
Copy link
Owner Author

JakobGM commented Aug 6, 2017

Parents should also be linked by the GroupManager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants