For convenient reference in development, here are the LORE API docs.
Helper functions for using the models, so external apps don’t tie functionality to internal implementation.
learningresources.api.
LearningResourceException
[source]¶Bases: exceptions.Exception
Base class for our custom exceptions.
learningresources.api.
MissingTitle
[source]¶Bases: object
Class to describe the missing title for importer and for the description path
for_desc_path_field
= u'...'¶for_title_field
= u'Missing Title'¶learningresources.api.
NotFound
[source]¶Bases: learningresources.api.LearningResourceException
Raised by the API when the item requested does not exist.
learningresources.api.
PermissionDenied
[source]¶Bases: learningresources.api.LearningResourceException
Raised by the API when the requested item exists, but the user is not allowed to access it.
learningresources.api.
create_course
(org, repo_id, course_number, run, user_id)[source]¶Add a course to the database.
Parameters: |
|
---|---|
Raises: |
|
Returns: | course – The created course |
Return type: | learningresources.models.Course |
learningresources.api.
create_repo
(name, description, user_id)[source]¶Create a new repository.
Parameters: |
|
---|---|
Returns: | repo – Newly-created repository |
Return type: | learningresources.Repository |
learningresources.api.
create_resource
(course, parent, resource_type, title, content_xml, mpath, url_name, dpath)[source]¶Create a learning resource.
Parameters: |
|
---|---|
Returns: | resource – New LearningResource |
Return type: | learningresources.models.LearningResource |
learningresources.api.
create_static_asset
(course_id, handle)[source]¶Create a static asset. :param course_id: learningresources.models.Course pk :type course_id: int :param handle: file handle :type handle: django.core.files.File
Returns: | learningresources.models.StaticAsset |
---|
learningresources.api.
get_repo
(repo_slug, user_id)[source]¶Get repository for a user if s/he can access it. Returns a repository object if it exists or * raises a 404 if the object does not exist * raises a 403 if the object exists but the user doesn’t have permission
Parameters: |
|
---|---|
Returns: | repo – Repository |
Return type: | learningresource.Repository |
learningresources.api.
get_repos
(user_id)[source]¶Get all repositories a user may access.
Parameters: | user_id (int) – Primary key of user |
---|---|
Returns: | repos – Repositories |
Return type: | query set of learningresource.Repository |
learningresources.api.
get_resource
(resource_id, user_id)[source]¶Get single resource.
Parameters: |
|
---|---|
Returns: | resource – Resource May be None if the resource does not exist or the user does not have permissions. |
Return type: | learningresources.LearningResource |
learningresources.api.
get_resources
(repo_id)[source]¶Get resources from a repository ordered by title.
Parameters: | repo_id (int) – Primary key of the repository |
---|---|
Returns: | list – List of resources |
Return type: | list of learningresources.LearningResource |
learningresources.api.
get_video_sub
(xml)[source]¶Get subtitle IDs from <video> XML.
Parameters: | xml (lxml.etree) – xml for a LearningResource |
---|---|
Returns: | subtitle string |
Return type: | sub string |
learningresources.api.
import_static_assets
(course, path)[source]¶Upload all assets and create model records of them for a given course and path.
Parameters: |
|
---|---|
Returns: | None |
learningresources.api.
join_description_paths
(*args)[source]¶Helper function to format the description path. :param args: description path :type args: unicode
Returns: | Formatted dpath |
---|---|
Return type: | unicode |
learningresources.api.
type_id_by_name
(name)[source]¶Get or create a LearningResourceType by name.
This would do fewer queries if it did all the lookups up front, but this is simpler to read and understand and still prevents most lookups. Also, it can’t prevent inserts, so it’s never guaranteed to be just a single query.
Parameters: | name (unicode) – LearningResourceType.name |
---|---|
Returns: | type_id – Primary key of learningresources.LearningResourceType |
Return type: | int |
learningresources.api.
update_description_path
(resource, force_parent_update=False)[source]¶Updates the specified learning resource description path based on the current title and the parent’s description path :param resource: LearningResource :type resource: learningresources.models.LearningResource :param force_parent_update: force parent update :type force_parent_update: boolean
Returns: | None |
---|
Import OLX data into LORE.
importer.api.
import_children
(course, element, parent, parent_dpath)[source]¶Create LearningResource instances for each element of an XML tree.
Parameters: |
|
---|---|
Returns: | None |
importer.api.
import_course
(bundle, repo_id, user_id, static_dir)[source]¶Import a course from an XBundle object.
Parameters: |
|
---|---|
Returns: | learningresources.models.Course |
importer.api.
import_course_from_file
(filename, repo_id, user_id)[source]¶Import OLX archive from .zip or tar.gz.
Imports from a file and then deletes that file. A valid OLX archive has a single occurrence of the file course.xml in its root directory, or no course.xml in its root and a single occurrence of course.xml in one or more of the root directory’s children.
Parameters: |
|
---|---|
Returns: | None |
Raises: |
|
importer.api.
import_course_from_path
(path, repo_id, user_id)[source]¶Import course from an OLX directory.
Parameters: |
|
---|---|
Returns: | course (learningresources.Course) |
APIs for lore taxonomy application
taxonomy.api.
get_term
(repo_slug, user_id, vocab_slug, term_slug)[source]¶Get Term with existing slug, validating ownership for repo_slug and vocab_slug.
Parameters: | term_id (int) – Term slug |
---|---|
Returns: | Term – The Term with the id |
Return type: | Term |
taxonomy.api.
get_vocabulary
(repo_slug, user_id, vocab_slug)[source]¶Lookup vocabulary given its slug, using repo_slug to validate ownership.
Parameters: |
|
---|---|
Returns: | Vocabulary – The vocabulary from the database |
Return type: | Vocabulary |
Functions for handling roles.
roles.api.
assign_user_to_repo_group
(user, repo, group_type)[source]¶Assign an user to a repo specific group type.
Parameters: |
|
---|---|
Returns: | None |
roles.api.
is_last_admin_in_repo
(user, repo)[source]¶Check if user is the last administrator in the repository. It does not check if the user is an actual administrator and in that case it will simply return False
Parameters: |
|
---|---|
Returns: | bool |
roles.api.
list_users_in_repo
(repo, base_group_type=None)[source]¶List all the users in the repository groups. If the group type is specified, the list is limited to that group.
Parameters: |
|
---|---|
Returns: | list – list of users in one or all the repository groups |
Return type: | list of roles.user_models.UserGroup |
roles.api.
remove_user_from_repo_group
(user, repo, group_type)[source]¶Remove an user from a repository specific group type.
Parameters: |
|
---|---|
Returns: | None |
roles.api.
roles_clear_repo_permissions
(repo)[source]¶Remove all the permissions a group has on a repository. :param repo: repository :type repo: learningresources.models.Repository
Returns: | None |
---|
roles.api.
roles_init_new_repo
(repo)[source]¶Create new groups for the repository.
Parameters: | repo (learningresources.models.Repository) – repository used to create groups and assign permissions to them |
---|---|
Returns: | None |
roles.api.
roles_update_repo
(repo, old_slug)[source]¶Update the groups names for the repository.
Parameters: |
|
---|---|
Returns: | None |