Data Manager#
- class emhub.data.DataManager(dataPath, dbName='emhub.sqlite', user=None, cleanDb=False, create=True, redis=None)#
Main class that will manage the sessions and their information.
- class WorkerStream(worker, dm)#
Helper class to centralize functions related to a Redis stream for a worker machine.
- check_resource_access(resource, permissionKey)#
Check if the user has permission to access bookings for this resource based on the resource tags and user’s roles.
- check_user_access(permissionKey)#
Return True if the current logged user has any of the roles defined in the config for ‘permissionKey’.
- count_booking_resources(applications, resource_ids=None, resource_tags=None)#
Count how many days has been used by applications from the current bookings. The count can be done by resources or by tags.
- create_admin(password='admin')#
Create special user ‘admin’.
- create_invoice_period(**attrs)#
Add a new session row.
- create_session(**attrs)#
Add a new session row.
- create_transaction(**attrs)#
Add a new session row.
- create_user(**attrs)#
Create a new user in the DB.
- delete_booking(**attrs)#
Delete one or many bookings (in case of repeating events).
- Keyword Arguments:
id – the of the booking to be deleted
modify_all – Boolean flag in case the booking is a repeating event. If True, all bookings from this one, will be also deleted.
- delete_entry(**attrs)#
Remove a session row.
- delete_invoice_period(**attrs)#
Remove a session row.
- delete_project(**attrs)#
Remove a project.
- delete_session(**attrs)#
Remove a session row.
- delete_transaction(**attrs)#
Remove a session row.
- delete_user(**attrs)#
Delete a given user.
- get_application_by(**kwargs)#
Return a single Application or None.
- get_booking_by(**kwargs)#
Return a single Application or None.
- get_bookings_range(start, end, resource=None)#
Shortcut function to retrieve a range of bookings.
- get_config(configName, default={}, cache=True)#
Find a form named config:configName and return the associated JSON definition.
- Parameters:
configName – name of the entry to load.
default – default value if the entry does not exist.
cache – If true, will use Redis cache
- get_entry_by(**kwargs)#
This should return a single Resource or None.
- get_entry_file(entry, file_key)#
Return the fn associated with a given entry.
- get_entry_files(entry)#
Return all values from the extra dict that are files.
- get_form_by(**kwargs)#
This should return a single Form or None.
- get_form_by_name(formName)#
Shortcut method to load a form from db given its name. If the form does not exist, an Exception is thrown.
- get_form_definition(formName, default={})#
Find a form named entry_form:formName and return the associated JSON definition.
- get_hosts()#
Use Redis to cache hosts information, avoiding reading it from the config all the time.
- get_invoice_period_by(**kwargs)#
This should return a single user or None.
- get_invoice_periods(condition=None, orderBy=None, asJson=False)#
Returns a list. condition example: text(“id<:value and name=:name”)
- get_new_session_info(booking_id)#
Return the name for the new session, base on the booking and the previous sessions counter (stored in Form ‘counters’).
- get_next_bookings(user)#
Retrieve upcoming (from now) bookings for this user.
- get_processing_project(**kwargs)#
Create a Processing Project instance from a path. If entry_id is provided, we retrieve the path from there.
- get_project_by(**kwargs)#
This should return a single Resource or None.
- get_resource_by(**kwargs)#
This should return a single Resource or None.
- get_session_by(**kwargs)#
This should return a single Session or None.
- get_sessions(condition=None, orderBy=None, asJson=False)#
Returns a list. condition example: text(“id<:value and name=:name”)
- get_template_by(**kwargs)#
Return a single Template or None.
- get_transaction_by(**kwargs)#
This should return a single user or None.
- get_transactions(condition=None, orderBy=None, asJson=False)#
Returns a list. condition example: text(“id<:value and name=:name”)
- get_user_bookings(uid)#
Return bookings related to this user. User might be creator, owner or operator of the booking.
- get_user_by(**kwargs)#
This should return a single user or None.
- set_rconfig(configName, configData)#
Update configuration entry in Redis.
- update_application(**attrs)#
Update a given Application with new attributes.
- Keyword Arguments:
pi_to_add – ids of PI users to add to the Application.
pi_to_remove – ids of PI users to remove from the Application
- update_booking(**attrs)#
Update one or many bookings (in case of repeating events)
- Keyword Arguments:
id – the of the booking to be updated
modify_all – Boolean flag in case the booking is a repeating event. If True, all bookings from this one, will be also updated.
- update_invoice_period(**attrs)#
Update session attrs.
- update_session(**attrs)#
Update session attrs.
- update_transaction(**attrs)#
Update session attrs.
- update_user(**attrs)#
Update an existing user.