onadata.libs package¶
Subpackages¶
- onadata.libs.data package
- onadata.libs.mixins package
- Submodules
- onadata.libs.mixins.anonymous_user_mixin module
- onadata.libs.mixins.anonymous_user_public_forms_mixin module
- onadata.libs.mixins.authenticate_header_mixin module
- onadata.libs.mixins.cache_control_mixin module
- onadata.libs.mixins.etags_mixin module
- onadata.libs.mixins.labels_mixin module
- onadata.libs.mixins.last_modified_mixin module
- onadata.libs.mixins.multi_lookup_mixin module
- onadata.libs.mixins.object_lookup_mixin module
- onadata.libs.mixins.openrosa_headers_mixin module
- onadata.libs.mixins.profiler_mixin module
- onadata.libs.mixins.total_header_mixin module
- onadata.libs.mixins.xform_id_string_lookup module
- Module contents
- onadata.libs.models package
- Submodules
- onadata.libs.models.base_model module
- onadata.libs.models.clone_xform module
- onadata.libs.models.share_project module
- onadata.libs.models.share_team_project module
- onadata.libs.models.share_xform module
- onadata.libs.models.signals module
- onadata.libs.models.sorting module
- onadata.libs.models.textit_service module
- Module contents
- onadata.libs.profiling package
- onadata.libs.renderers package
- Submodules
- onadata.libs.renderers.renderers module
CSVRenderer
CSVZIPRenderer
DebugToolbarRenderer
DecimalEncoder
DecimalJSONRenderer
FLOIPRenderer
GeoJsonRenderer
GoogleSheetsRenderer
InstanceXMLRenderer
KMLRenderer
MediaFileContentNegotiation
MediaFileRenderer
OSMExportRenderer
OSMRenderer
SAVZIPRenderer
StaticXMLRenderer
StreamRendererMixin
SurveyRenderer
TemplateXMLRenderer
XFormListRenderer
XFormManifestRenderer
XLSRenderer
XLSXRenderer
ZipRenderer
floip_list()
floip_rows_list()
pairing()
- Module contents
- onadata.libs.serializers package
- Subpackages
- onadata.libs.serializers.fields package
- Submodules
- onadata.libs.serializers.fields.hyperlinked_multi_identity_field module
- onadata.libs.serializers.fields.hyperlinked_multi_related_field module
- onadata.libs.serializers.fields.instance_related_field module
- onadata.libs.serializers.fields.json_field module
- onadata.libs.serializers.fields.organization_field module
- onadata.libs.serializers.fields.project_field module
- onadata.libs.serializers.fields.project_related_field module
- onadata.libs.serializers.fields.team_field module
- onadata.libs.serializers.fields.xform_field module
- onadata.libs.serializers.fields.xform_related_field module
- Module contents
- onadata.libs.serializers.fields package
- Submodules
- onadata.libs.serializers.attachment_serializer module
- onadata.libs.serializers.chart_serializer module
- onadata.libs.serializers.clone_xform_serializer module
- onadata.libs.serializers.data_serializer module
BaseRapidProSubmissionSerializer
DataInstanceSerializer
DataInstanceXMLSerializer
DataSerializer
FLOIPListSerializer
FLOIPSubmissionSerializer
InstanceHistorySerializer
JSONSubmissionSerializer
JsonDataSerializer
OSMSerializer
OSMSiteMapSerializer
RapidProJSONSubmissionSerializer
RapidProSubmissionSerializer
SubmissionSerializer
SubmissionSuccessMixin
TableauDataSerializer
create_submission()
get_request_and_username()
- onadata.libs.serializers.dataview_serializer module
DataViewMinimalSerializer
DataViewSerializer
DataViewSerializer.Meta
DataViewSerializer.create()
DataViewSerializer.get_count()
DataViewSerializer.get_has_hxl_support()
DataViewSerializer.get_instances_with_geopoints()
DataViewSerializer.get_last_submission_time()
DataViewSerializer.update()
DataViewSerializer.validate()
DataViewSerializer.validate_columns()
DataViewSerializer.validate_query()
match_columns()
validate_date()
validate_datetime()
- onadata.libs.serializers.export_serializer module
- onadata.libs.serializers.geojson_serializer module
- onadata.libs.serializers.metadata_serializer module
- onadata.libs.serializers.note_serializer module
- onadata.libs.serializers.organization_member_serializer module
- onadata.libs.serializers.organization_serializer module
- onadata.libs.serializers.password_reset_serializer module
- onadata.libs.serializers.project_serializer module
BaseProjectSerializer
BaseProjectXFormSerializer
ProjectSerializer
ProjectSerializer.Meta
ProjectSerializer.create()
ProjectSerializer.get_data_views()
ProjectSerializer.get_forms()
ProjectSerializer.get_last_submission_date()
ProjectSerializer.get_num_datasets()
ProjectSerializer.get_starred()
ProjectSerializer.get_teams()
ProjectSerializer.get_users()
ProjectSerializer.update()
ProjectSerializer.validate()
ProjectSerializer.validate_metadata()
ProjectSerializer.validate_public()
ProjectXFormSerializer
can_add_project_to_profile()
get_last_submission_date()
get_num_datasets()
get_project_xforms()
get_team_permissions()
get_teams()
get_users()
is_starred()
set_owners_permission()
- onadata.libs.serializers.restservices_serializer module
- onadata.libs.serializers.share_project_serializer module
- onadata.libs.serializers.share_team_project_serializer module
- onadata.libs.serializers.share_xform_serializer module
- onadata.libs.serializers.stats_serializer module
- onadata.libs.serializers.tag_list_serializer module
- onadata.libs.serializers.team_serializer module
- onadata.libs.serializers.textit_serializer module
- onadata.libs.serializers.user_profile_serializer module
UserProfileSerializer
UserProfileSerializer.Meta
UserProfileSerializer.create()
UserProfileSerializer.get_is_org()
UserProfileSerializer.to_representation()
UserProfileSerializer.update()
UserProfileSerializer.validate()
UserProfileSerializer.validate_email()
UserProfileSerializer.validate_twitter()
UserProfileSerializer.validate_username()
UserProfileWithTokenSerializer
- onadata.libs.serializers.user_serializer module
- onadata.libs.serializers.widget_serializer module
- onadata.libs.serializers.xform_serializer module
- Module contents
- Subpackages
- onadata.libs.tests package
- Subpackages
- onadata.libs.tests.serializers package
- Submodules
- onadata.libs.tests.serializers.test_attachment_serializer module
- onadata.libs.tests.serializers.test_dataview_serializer module
- onadata.libs.tests.serializers.test_organization_serializer module
- onadata.libs.tests.serializers.test_password_reset_serializer module
- onadata.libs.tests.serializers.test_project_serializer module
- onadata.libs.tests.serializers.test_user_profile_serializer module
- Module contents
- onadata.libs.tests.utils package
- Submodules
- onadata.libs.tests.utils.test_api_export_tools module
- onadata.libs.tests.utils.test_async_status module
- onadata.libs.tests.utils.test_backup_tools module
- onadata.libs.tests.utils.test_chart_tools module
- onadata.libs.tests.utils.test_csv_builder module
- onadata.libs.tests.utils.test_csv_import module
- onadata.libs.tests.utils.test_dict_tools module
- onadata.libs.tests.utils.test_export_tools module
- onadata.libs.tests.utils.test_image_tools module
- onadata.libs.tests.utils.test_logger_tools module
- onadata.libs.tests.utils.test_osm module
- onadata.libs.tests.utils.test_qrcode module
- Module contents
- onadata.libs.tests.serializers package
- Submodules
- onadata.libs.tests.test_authentication module
- onadata.libs.tests.test_permissions module
- Module contents
- Subpackages
- onadata.libs.utils package
- Submodules
- onadata.libs.utils.api_export_tools module
- onadata.libs.utils.async_status module
- onadata.libs.utils.audit module
- onadata.libs.utils.backup_tools module
- onadata.libs.utils.briefcase_client module
- onadata.libs.utils.cache_tools module
- onadata.libs.utils.chart_tools module
- onadata.libs.utils.common_tags module
- onadata.libs.utils.common_tools module
- onadata.libs.utils.country_field module
- onadata.libs.utils.csv_builder module
- onadata.libs.utils.csv_import module
- onadata.libs.utils.csv_reader module
- onadata.libs.utils.decorators module
- onadata.libs.utils.dict_tools module
- onadata.libs.utils.export_builder module
ExportBuilder
ExportBuilder.BINARY_SELECT_MULTIPLES
ExportBuilder.CONVERT_FUNCS
ExportBuilder.EXTRA_FIELDS
ExportBuilder.GROUP_DELIMITER
ExportBuilder.GROUP_DELIMITERS
ExportBuilder.GROUP_DELIMITER_DOT
ExportBuilder.GROUP_DELIMITER_SLASH
ExportBuilder.IGNORED_COLUMNS
ExportBuilder.INCLUDE_HXL
ExportBuilder.INCLUDE_IMAGES
ExportBuilder.INCLUDE_LABELS
ExportBuilder.INCLUDE_LABELS_ONLY
ExportBuilder.INCLUDE_REVIEWS
ExportBuilder.REPEAT_INDEX_TAGS
ExportBuilder.SHOW_CHOICE_LABELS
ExportBuilder.SPLIT_SELECT_MULTIPLES
ExportBuilder.TRUNCATE_GROUP_TITLE
ExportBuilder.TYPES_TO_CONVERT
ExportBuilder.VALUE_SELECT_MULTIPLES
ExportBuilder.XLS_SHEET_NAME_MAX_CHARS
ExportBuilder.convert_type()
ExportBuilder.decode_mongo_encoded_fields()
ExportBuilder.format_field_title()
ExportBuilder.get_choice_label_from_dict()
ExportBuilder.get_default_language()
ExportBuilder.get_fields()
ExportBuilder.get_valid_sheet_name()
ExportBuilder.language
ExportBuilder.pre_process_row()
ExportBuilder.section_by_name()
ExportBuilder.set_survey()
ExportBuilder.split_gps_components()
ExportBuilder.split_select_multiples()
ExportBuilder.to_flat_csv_export()
ExportBuilder.to_xlsx_export()
ExportBuilder.to_zipped_csv()
ExportBuilder.to_zipped_sav()
ExportBuilder.url
decode_mongo_encoded_section_names()
dict_to_joined_export()
encode_if_str()
get_data_dictionary_from_survey()
is_all_numeric()
string_to_date_with_xls_validation()
- onadata.libs.utils.export_tools module
check_pending_export()
clean_keys_of_slashes()
create_export_object()
generate_attachments_zip_export()
generate_external_export()
generate_geojson_export()
generate_kml_export()
generate_osm_export()
get_export_options()
get_or_create_export()
get_or_create_export_object()
get_osm_data_kwargs()
get_repeat_index_tags()
increment_index_in_filename()
kml_export_data()
md5hash()
newest_export_for()
parse_request_export_options()
should_create_new_export()
upload_template_for_external_export()
write_temp_file_to_path()
- onadata.libs.utils.google module
- onadata.libs.utils.gravatar module
- onadata.libs.utils.image_tools module
- onadata.libs.utils.log module
- onadata.libs.utils.logger_tools module
BaseOpenRosaResponse
OpenRosaNotAuthenticated
OpenRosaResponse
OpenRosaResponseBadRequest
OpenRosaResponseForbidden
OpenRosaResponseNotAllowed
OpenRosaResponseNotFound
PublishXForm
check_edit_submission_permissions()
check_submission_encryption()
check_submission_permissions()
create_instance()
create_xform_version()
dict2xform()
generate_content_disposition_header()
get_filtered_instances()
get_first_record()
get_uuid_from_submission()
get_xform_from_submission()
inject_instanceid()
publish_form()
remove_metadata_fields()
response_with_mimetype_and_name()
safe_create_instance()
save_attachments()
save_submission()
set_default_openrosa_headers()
store_temp_file()
update_attachment_tracking()
- onadata.libs.utils.middleware module
- onadata.libs.utils.model_tools module
- onadata.libs.utils.mongo module
- onadata.libs.utils.numeric module
- onadata.libs.utils.osm module
- onadata.libs.utils.profiler module
- onadata.libs.utils.project_utils module
- onadata.libs.utils.qrcode module
- onadata.libs.utils.quick_converter module
- onadata.libs.utils.string module
- onadata.libs.utils.timing module
- onadata.libs.utils.user_auth module
HttpResponseNotAuthorized
add_cors_headers()
basic_http_auth()
check_and_set_form_by_id()
check_and_set_form_by_id_string()
check_and_set_user()
check_and_set_user_and_form()
get_user_default_project()
get_xform_and_perms()
get_xform_users_with_perms()
has_edit_permission()
has_permission()
helper_auth_helper()
http_auth_string()
invalidate_and_regen_tokens()
set_api_permissions_for_user()
set_profile_data()
- onadata.libs.utils.viewer_tools module
- Module contents
Submodules¶
onadata.libs.authentication module¶
Authentication classes.
- class onadata.libs.authentication.DigestAuthentication¶
Bases:
BaseAuthentication
Digest authentication
- authenticate(request)¶
Authenticate the request and return a two-tuple of (user, token).
- authenticate_header(request)¶
Return a string to be used as the value of the WWW-Authenticate header in a 401 Unauthenticated response, or None if the authentication scheme should return 403 Permission Denied responses.
- class onadata.libs.authentication.EnketoTokenAuthentication¶
Bases:
TokenAuthentication
Enketo Token Authentication via JWT shared domain cookie name.
- authenticate(request)¶
Authenticate the request and return a two-tuple of (user, token).
- model¶
alias of
Token
- class onadata.libs.authentication.MasterReplicaOAuth2Validator¶
Bases:
OAuth2Validator
Custom OAuth2Validator class that takes into account replication lag between Master & Replica databases https://github.com/jazzband/django-oauth-toolkit/blob/ 3bde632d5722f1f85ffcd8277504955321f00fff/oauth2_provider/oauth2_validators.py#L49
- introspect_token(token, token_type_hint, request, *args, **kwargs)¶
See oauthlib.oauth2.rfc6749.request_validator
- validate_bearer_token(token, scopes, request)¶
When users try to access resources, check that provided token is valid
- validate_silent_authorization(request)¶
See oauthlib.oauth2.rfc6749.request_validator
- validate_silent_login(request)¶
See oauthlib.oauth2.rfc6749.request_validator
- class onadata.libs.authentication.SSOHeaderAuthentication¶
Bases:
BaseAuthentication
SSO Cookie authentication. Authenticates a user using the SSO cookie or HTTP_SSO header.
- authenticate(request)¶
Authenticate the request and return a two-tuple of (user, token).
- class onadata.libs.authentication.TempTokenAuthentication¶
Bases:
TokenAuthentication
TempToken authentication using “Authorization: TempToken xxxx” header.
- authenticate(request)¶
Authenticate the request and return a two-tuple of (user, token).
- authenticate_credentials(key)¶
- authenticate_header(request)¶
Return a string to be used as the value of the WWW-Authenticate header in a 401 Unauthenticated response, or None if the authentication scheme should return 403 Permission Denied responses.
- model¶
alias of
TempToken
- class onadata.libs.authentication.TempTokenURLParameterAuthentication¶
Bases:
TempTokenAuthentication
TempToken URL via temp_token request parameter.
- authenticate(request)¶
Authenticate the request and return a two-tuple of (user, token).
- model¶
alias of
TempToken
- onadata.libs.authentication.check_lockout(request) Tuple[str | None, str | None] ¶
Check request user is not locked out on authentication.
Returns the username if not locked out, None if request path is in LOCKOUT_EXCLUDED_PATHS. Raises AuthenticationFailed on lockout.
- onadata.libs.authentication.expired(time_token_created)¶
Checks if the time between when time_token_created and current time is greater than the token expiry time.
- Params time_token_created:
The time the token we are checking was created.
- Returns:
Boolean True if not passed expired time, otherwise False.
- onadata.libs.authentication.get_api_token(cookie_jwt)¶
Get API Token from JSON Web Token
- onadata.libs.authentication.login_attempts(request)¶
Track number of login attempts made by a specific IP within a specified amount of time
- onadata.libs.authentication.retrieve_user_identification(request) Tuple[str | None, str | None] ¶
Retrieve user information from a HTTP request.
- onadata.libs.authentication.send_lockout_email(username, ip_address)¶
Send locked out email
onadata.libs.baseviewset module¶
The DefaultBaseViewset class
onadata.libs.exceptions module¶
Custom Expecting classes.
- exception onadata.libs.exceptions.EnketoError(message=None)¶
Bases:
Exception
Enketo specigic exceptions
- default_message = 'There was a problem with your submission or form. Please contact support.'¶
- exception onadata.libs.exceptions.J2XException¶
Bases:
Exception
Raise for json-to-xls exceptions on external exports.
- exception onadata.libs.exceptions.NoRecordsFoundError¶
Bases:
Exception
Raise for when no records are found.
- exception onadata.libs.exceptions.NoRecordsPermission¶
Bases:
Exception
Raise when no permissions to access records.
Bases:
APIException
Custom service unavailable exception.
onadata.libs.filters module¶
Django rest_framework ViewSet filters.
- class onadata.libs.filters.AnonDjangoObjectPermissionFilter¶
Bases:
ObjectPermissionsFilter
Anonymous user permission filter class.
- filter_queryset(request, queryset, view)¶
Anonymous user has no object permissions, return queryset as it is.
- class onadata.libs.filters.AnonUserProjectFilter¶
Bases:
ObjectPermissionsFilter
Anonymous user project filter.
- filter_queryset(request, queryset, view)¶
Anonymous user has no object permissions, return queryset as it is.
- owner_prefix = 'organization'¶
- class onadata.libs.filters.AttachmentFilter¶
Bases:
XFormPermissionFilterMixin
,ObjectPermissionsFilter
Attachment filter.
- filter_queryset(request, queryset, view)¶
Return a filtered queryset.
- class onadata.libs.filters.AttachmentTypeFilter¶
Bases:
BaseFilterBackend
Attachment type filter using type query parameter.
- filter_queryset(request, queryset, view)¶
Return a filtered queryset.
- class onadata.libs.filters.DataFilter¶
Bases:
ObjectPermissionsFilter
Shared data filter.
- filter_queryset(request, queryset, view)¶
Filter by
XForm.shared_data = True
for anonymous users.
- class onadata.libs.filters.EnketoAnonDjangoObjectPermissionFilter¶
Bases:
AnonDjangoObjectPermissionFilter
Same as AnonDjangoObjectPermissionFilter but checks ‘report_xform’ permission when the view ‘enketo’ is accessed.
- filter_queryset(request, queryset, view)¶
Check report_xform permission when requesting for Enketo URL.
- class onadata.libs.filters.ExportFilter¶
Bases:
XFormPermissionFilterMixin
,ObjectPermissionsFilter
ExportFilter class uses permissions on the related xform to filter Export querysets. Also filters submitted_by a specific user.
- filter_queryset(request, queryset, view)¶
Filter by xform permissions and submitted by user.
- class onadata.libs.filters.FormIDFilter(data=None, queryset=None, *, request=None, prefix=None)¶
Bases:
FilterSet
formID filter using the XForm.id_string.
- base_filters = {'formID': <django_filters.filters.CharFilter object>}¶
- declared_filters = {'formID': <django_filters.filters.CharFilter object>}¶
- class onadata.libs.filters.InstanceFilter(data=None, queryset=None, *, request=None, prefix=None)¶
Bases:
FilterSet
Instance FilterSet implemented using django-filter
- class Meta¶
Bases:
object
- date_field_lookups = ['exact', 'gt', 'lt', 'gte', 'lte', 'year', 'year__gt', 'year__lt', 'year__gte', 'year__lte', 'month', 'month__gt', 'month__lt', 'month__gte', 'month__lte', 'day', 'day__gt', 'day__lt', 'day__gte', 'day__lte']¶
- fields = {'date_created': ['exact', 'gt', 'lt', 'gte', 'lte', 'year', 'year__gt', 'year__lt', 'year__gte', 'year__lte', 'month', 'month__gt', 'month__lt', 'month__gte', 'month__lte', 'day', 'day__gt', 'day__lt', 'day__gte', 'day__lte'], 'date_modified': ['exact', 'gt', 'lt', 'gte', 'lte', 'year', 'year__gt', 'year__lt', 'year__gte', 'year__lte', 'month', 'month__gt', 'month__lt', 'month__gte', 'month__lte', 'day', 'day__gt', 'day__lt', 'day__gte', 'day__lte'], 'last_edited': ['exact', 'gt', 'lt', 'gte', 'lte', 'year', 'year__gt', 'year__lt', 'year__gte', 'year__lte', 'month', 'month__gt', 'month__lt', 'month__gte', 'month__lte', 'day', 'day__gt', 'day__lt', 'day__gte', 'day__lte'], 'media_all_received': ['exact'], 'status': ['exact'], 'survey_type__slug': ['exact'], 'user__id': ['exact'], 'user__username': ['exact'], 'uuid': ['exact'], 'version': ['exact', 'gt', 'lt', 'gte', 'lte']}¶
- generic_field_lookups = ['exact', 'gt', 'lt', 'gte', 'lte']¶
- model¶
alias of
Instance
- base_filters = {'date_created': <django_filters.filters.IsoDateTimeFilter object>, 'date_created__day': <django_filters.filters.NumberFilter object>, 'date_created__day__gt': <django_filters.filters.NumberFilter object>, 'date_created__day__gte': <django_filters.filters.NumberFilter object>, 'date_created__day__lt': <django_filters.filters.NumberFilter object>, 'date_created__day__lte': <django_filters.filters.NumberFilter object>, 'date_created__gt': <django_filters.filters.IsoDateTimeFilter object>, 'date_created__gte': <django_filters.filters.IsoDateTimeFilter object>, 'date_created__lt': <django_filters.filters.IsoDateTimeFilter object>, 'date_created__lte': <django_filters.filters.IsoDateTimeFilter object>, 'date_created__month': <django_filters.filters.NumberFilter object>, 'date_created__month__gt': <django_filters.filters.NumberFilter object>, 'date_created__month__gte': <django_filters.filters.NumberFilter object>, 'date_created__month__lt': <django_filters.filters.NumberFilter object>, 'date_created__month__lte': <django_filters.filters.NumberFilter object>, 'date_created__year': <django_filters.filters.NumberFilter object>, 'date_created__year__gt': <django_filters.filters.NumberFilter object>, 'date_created__year__gte': <django_filters.filters.NumberFilter object>, 'date_created__year__lt': <django_filters.filters.NumberFilter object>, 'date_created__year__lte': <django_filters.filters.NumberFilter object>, 'date_modified': <django_filters.filters.IsoDateTimeFilter object>, 'date_modified__day': <django_filters.filters.NumberFilter object>, 'date_modified__day__gt': <django_filters.filters.NumberFilter object>, 'date_modified__day__gte': <django_filters.filters.NumberFilter object>, 'date_modified__day__lt': <django_filters.filters.NumberFilter object>, 'date_modified__day__lte': <django_filters.filters.NumberFilter object>, 'date_modified__gt': <django_filters.filters.IsoDateTimeFilter object>, 'date_modified__gte': <django_filters.filters.IsoDateTimeFilter object>, 'date_modified__lt': <django_filters.filters.IsoDateTimeFilter object>, 'date_modified__lte': <django_filters.filters.IsoDateTimeFilter object>, 'date_modified__month': <django_filters.filters.NumberFilter object>, 'date_modified__month__gt': <django_filters.filters.NumberFilter object>, 'date_modified__month__gte': <django_filters.filters.NumberFilter object>, 'date_modified__month__lt': <django_filters.filters.NumberFilter object>, 'date_modified__month__lte': <django_filters.filters.NumberFilter object>, 'date_modified__year': <django_filters.filters.NumberFilter object>, 'date_modified__year__gt': <django_filters.filters.NumberFilter object>, 'date_modified__year__gte': <django_filters.filters.NumberFilter object>, 'date_modified__year__lt': <django_filters.filters.NumberFilter object>, 'date_modified__year__lte': <django_filters.filters.NumberFilter object>, 'last_edited': <django_filters.filters.IsoDateTimeFilter object>, 'last_edited__day': <django_filters.filters.NumberFilter object>, 'last_edited__day__gt': <django_filters.filters.NumberFilter object>, 'last_edited__day__gte': <django_filters.filters.NumberFilter object>, 'last_edited__day__lt': <django_filters.filters.NumberFilter object>, 'last_edited__day__lte': <django_filters.filters.NumberFilter object>, 'last_edited__gt': <django_filters.filters.IsoDateTimeFilter object>, 'last_edited__gte': <django_filters.filters.IsoDateTimeFilter object>, 'last_edited__lt': <django_filters.filters.IsoDateTimeFilter object>, 'last_edited__lte': <django_filters.filters.IsoDateTimeFilter object>, 'last_edited__month': <django_filters.filters.NumberFilter object>, 'last_edited__month__gt': <django_filters.filters.NumberFilter object>, 'last_edited__month__gte': <django_filters.filters.NumberFilter object>, 'last_edited__month__lt': <django_filters.filters.NumberFilter object>, 'last_edited__month__lte': <django_filters.filters.NumberFilter object>, 'last_edited__year': <django_filters.filters.NumberFilter object>, 'last_edited__year__gt': <django_filters.filters.NumberFilter object>, 'last_edited__year__gte': <django_filters.filters.NumberFilter object>, 'last_edited__year__lt': <django_filters.filters.NumberFilter object>, 'last_edited__year__lte': <django_filters.filters.NumberFilter object>, 'media_all_received': <django_filters.rest_framework.filters.BooleanFilter object>, 'status': <django_filters.filters.CharFilter object>, 'submitted_by__id': <django_filters.filters.ModelChoiceFilter object>, 'submitted_by__username': <django_filters.filters.ModelChoiceFilter object>, 'survey_type__slug': <django_filters.filters.CharFilter object>, 'user__id': <django_filters.filters.NumberFilter object>, 'user__username': <django_filters.filters.CharFilter object>, 'uuid': <django_filters.filters.CharFilter object>, 'version': <django_filters.filters.CharFilter object>, 'version__gt': <django_filters.filters.CharFilter object>, 'version__gte': <django_filters.filters.CharFilter object>, 'version__lt': <django_filters.filters.CharFilter object>, 'version__lte': <django_filters.filters.CharFilter object>}¶
- declared_filters = {'media_all_received': <django_filters.rest_framework.filters.BooleanFilter object>, 'submitted_by__id': <django_filters.filters.ModelChoiceFilter object>, 'submitted_by__username': <django_filters.filters.ModelChoiceFilter object>}¶
- class onadata.libs.filters.MetaDataFilter¶
Bases:
ProjectPermissionFilterMixin
,InstancePermissionFilterMixin
,XFormPermissionFilterMixin
,ObjectPermissionsFilter
Meta data filter.
- filter_queryset(request, queryset, view)¶
Return a filtered queryset.
- class onadata.libs.filters.NoteFilter¶
Bases:
BaseFilterBackend
Notes filter by the query parameter
instance
.- filter_queryset(request, queryset, view)¶
Notes filter by the query parameter
instance
.
- class onadata.libs.filters.OrganizationPermissionFilter¶
Bases:
ObjectPermissionsFilter
Organization profiles filter
Based on the organization the profile is added to.
- filter_queryset(request, queryset, view)¶
Return a filtered queryset or all profiles if a getting a specific profile.
Bases:
BaseFilterBackend
Filters by
shared_with
query parameter.This returns a queryset containing only organizations to which the passed user belongs.
- class onadata.libs.filters.ProjectOwnerFilter¶
Bases:
BaseFilterBackend
Project owner filter.
- filter_queryset(request, queryset, view)¶
Project owner filter.
- owner_prefix = 'organization'¶
- class onadata.libs.filters.PublicDatasetsFilter¶
Bases:
object
Public data set filter where the share attribute is True
- filter_queryset(request, queryset, view)¶
Return a queryset of shared=True data if the user is anonymous.
- class onadata.libs.filters.RestServiceFilter¶
Bases:
XFormPermissionFilterMixin
,ObjectPermissionsFilter
Rest service filter.
- filter_queryset(request, queryset, view)¶
Return a filtered queryset.
- class onadata.libs.filters.TagFilter¶
Bases:
BaseFilterBackend
Tag filter using the tags query parameter.
- filter_queryset(request, queryset, view)¶
Tag filter using the tags query parameter.
- class onadata.libs.filters.TeamOrgFilter¶
Bases:
BaseFilterBackend
Team organization filter using org query parameter
- filter_queryset(request, queryset, view)¶
Return a filtered queryset.
- class onadata.libs.filters.UserNoOrganizationsFilter¶
Bases:
BaseFilterBackend
Filter by
orgs
query parameter.- filter_queryset(request, queryset, view)¶
Returns all users that are not organizations when orgs=false query parameter
- class onadata.libs.filters.UserProfileFilter¶
Bases:
BaseFilterBackend
Filter by the
users
query parameter.- filter_queryset(request, queryset, view)¶
Filter by the
users
query parameter - returns a queryset of only the users in the users parameter when view.action == “list”
- class onadata.libs.filters.WidgetFilter¶
Bases:
XFormPermissionFilterMixin
,ObjectPermissionsFilter
Filter to return forms shared with user.
- filter_queryset(request, queryset, view)¶
Filter to return forms shared with user when
view.action == "list"
.
- class onadata.libs.filters.XFormListObjectPermissionFilter¶
Bases:
AnonDjangoObjectPermissionFilter
XFormList permission filter with using [app].report_[model] form.
- perm_format = '%(app_label)s.report_%(model_name)s'¶
- class onadata.libs.filters.XFormListXFormPKFilter¶
Bases:
object
Filter forms via ‘xform_pk’ param.
- filter_queryset(request, queryset, view)¶
Returns an XForm queryset filtered by the 1xform_pk’ param.
onadata.libs.pagination module¶
Pagination classes.
- class onadata.libs.pagination.CountOverridablePageNumberPagination¶
Bases:
StandardPageNumberPagination
Count override PageNumberPagination
Allows overriding the count especially in the event it may be expensive request.
- django_paginator_class¶
alias of
CountOverridablePaginator
- paginate_queryset(queryset, request, view, count=None)¶
Paginate a queryset if required, either returning a page object, or None if pagination is not configured for this view.
- class onadata.libs.pagination.CountOverridablePaginator(object_list, per_page, orphans: int = 0, allow_empty_first_page: bool = True, count_override: int | None = None)¶
Bases:
Paginator
Count override Paginator
Allows overriding the count especially in the event it may be expensive request.
- count¶
- class onadata.libs.pagination.RawSQLQueryPageNumberPagination¶
Bases:
CountOverridablePageNumberPagination
PageNumberPagination class for raw SQL queries
- django_paginator_class¶
alias of
RawSQLQueryPaginator
- class onadata.libs.pagination.RawSQLQueryPaginator(object_list, per_page, orphans: int = 0, allow_empty_first_page: bool = True, count_override: int | None = None)¶
Bases:
CountOverridablePaginator
Paginator class for raw SQL queries
- page(number)¶
Return page
self.object_list is NOT sliced because self.object_list should have been paginated via OFFSET and LIMIT before creating a RawPaginator instance
- class onadata.libs.pagination.StandardPageNumberPagination¶
Bases:
PageNumberPagination
The Standard PageNumberPagination class
Set’s the default
page_size
to 1000 with a maximum page_size of 10,000 records per page.- generate_link_header(request: Request, queryset: QuerySet)¶
Generates pagination headers for a HTTP response object
- get_first_page_link()¶
Returns the URL to the first page.
- get_last_page_link()¶
Returns the URL to the last page.
- max_page_size = 10000¶
- page_size = 1000¶
- page_size_query_param = 'page_size'¶
onadata.libs.permissions module¶
Permissions module.
- class onadata.libs.permissions.DataEntryMinorRole¶
Bases:
Role
- Data-Entry minor Role class - user can submit and has readonly access to
data they submitted.
- class_to_permissions = {<class 'onadata.apps.logger.models.merged_xform.MergedXForm'>: ['view_mergedxform'], <class 'onadata.apps.api.models.organization_profile.OrganizationProfile'>: ['view_organizationprofile'], <class 'onadata.apps.logger.models.project.Project'>: ['report_project_xform', 'can_export_project_data', 'view_project', 'view_project_data'], <class 'onadata.apps.logger.models.xform.XForm'>: ['report_xform', 'can_export_xform_data', 'view_xform', 'view_xform_data']}¶
- name = 'dataentry-minor'¶
- class onadata.libs.permissions.DataEntryOnlyRole¶
Bases:
Role
Data-Entry only Role class.
- class_to_permissions = {<class 'onadata.apps.logger.models.merged_xform.MergedXForm'>: ['view_mergedxform'], <class 'onadata.apps.api.models.organization_profile.OrganizationProfile'>: ['view_organizationprofile'], <class 'onadata.apps.logger.models.project.Project'>: ['report_project_xform', 'can_export_project_data', 'view_project'], <class 'onadata.apps.logger.models.xform.XForm'>: ['report_xform']}¶
- name = 'dataentry-only'¶
- class onadata.libs.permissions.DataEntryRole¶
Bases:
Role
- Data-Entry Role class - user can submit data and has readonly permissions
to all the data including data submitted by others.
- class_to_permissions = {<class 'onadata.apps.logger.models.merged_xform.MergedXForm'>: ['view_mergedxform'], <class 'onadata.apps.api.models.organization_profile.OrganizationProfile'>: ['view_organizationprofile'], <class 'onadata.apps.logger.models.project.Project'>: ['report_project_xform', 'can_export_project_data', 'view_project', 'view_project_all', 'view_project_data'], <class 'onadata.apps.logger.models.xform.XForm'>: ['report_xform', 'can_export_xform_data', 'view_xform', 'view_xform_all', 'view_xform_data']}¶
- name = 'dataentry'¶
- class onadata.libs.permissions.EditorMinorRole¶
Bases:
Role
- Editor-Minor Role class - user can submit data, read and edit only the data
they submitted.
- class_to_permissions = {<class 'onadata.apps.logger.models.merged_xform.MergedXForm'>: ['view_mergedxform'], <class 'onadata.apps.api.models.organization_profile.OrganizationProfile'>: ['view_organizationprofile'], <class 'onadata.apps.logger.models.project.Project'>: ['report_project_xform', 'change_project', 'can_export_project_data', 'view_project', 'view_project_data'], <class 'onadata.apps.logger.models.xform.XForm'>: ['report_xform', 'change_xform', 'delete_submission', 'can_export_xform_data', 'view_xform', 'view_xform_data']}¶
- name = 'editor-minor'¶
- class onadata.libs.permissions.EditorRole¶
Bases:
Role
Editor Role class - user can submit, read and edit any submitted data.
- class_to_permissions = {<class 'onadata.apps.logger.models.merged_xform.MergedXForm'>: ['view_mergedxform'], <class 'onadata.apps.api.models.organization_profile.OrganizationProfile'>: ['view_organizationprofile'], <class 'onadata.apps.logger.models.project.Project'>: ['report_project_xform', 'change_project', 'can_export_project_data', 'view_project', 'view_project_all', 'view_project_data'], <class 'onadata.apps.logger.models.xform.XForm'>: ['report_xform', 'change_xform', 'delete_submission', 'can_export_xform_data', 'view_xform', 'view_xform_all', 'view_xform_data']}¶
- name = 'editor'¶
- class onadata.libs.permissions.ManagerRole¶
Bases:
Role
- Manager Role class - user can add,delete,edit forms and data as well as
control access to data, forms and projects.
- class_to_permissions = {<class 'onadata.apps.logger.models.merged_xform.MergedXForm'>: ['view_mergedxform'], <class 'onadata.apps.api.models.organization_profile.OrganizationProfile'>: ['can_add_project', 'can_add_xform', 'view_organizationprofile'], <class 'onadata.apps.logger.models.project.Project'>: ['add_project', 'add_project_xform', 'report_project_xform', 'change_project', 'can_export_project_data', 'view_project', 'view_project_all', 'view_project_data'], <class 'onadata.apps.main.models.user_profile.UserProfile'>: ['can_add_project', 'can_add_xform', 'view_profile'], <class 'onadata.apps.logger.models.xform.XForm'>: ['report_xform', 'add_xform', 'change_xform', 'delete_submission', 'delete_xform', 'can_export_xform_data', 'view_xform', 'view_xform_all', 'view_xform_data']}¶
- name = 'manager'¶
- class onadata.libs.permissions.MemberRole¶
Bases:
Role
This is a role for a member of an organization.
- name = 'member'¶
- class onadata.libs.permissions.OwnerRole¶
Bases:
Role
This is a role for an owner of a dataset, organization, or project.
- class_to_permissions = {<class 'onadata.apps.viewer.models.data_dictionary.DataDictionary'>: ['add_datadictionary', 'change_datadictionary', 'delete_datadictionary'], <class 'onadata.apps.logger.models.merged_xform.MergedXForm'>: ['view_mergedxform'], <class 'onadata.apps.api.models.organization_profile.OrganizationProfile'>: ['can_add_project', 'can_add_xform', 'add_organizationprofile', 'can_add_project', 'can_add_xform', 'change_organizationprofile', 'delete_organizationprofile', 'view_organizationprofile', 'is_org_owner'], <class 'onadata.apps.logger.models.project.Project'>: ['add_project', 'add_project_xform', 'report_project_xform', 'change_project', 'delete_project', 'can_export_project_data', 'transfer_project', 'view_project', 'view_project_all', 'view_project_data'], <class 'onadata.apps.main.models.user_profile.UserProfile'>: ['can_add_project', 'can_add_xform', 'add_userprofile', 'change_userprofile', 'delete_userprofile', 'view_profile'], <class 'onadata.apps.logger.models.xform.XForm'>: ['report_xform', 'add_xform', 'change_xform', 'delete_submission', 'delete_xform', 'can_export_xform_data', 'view_xform', 'view_xform_all', 'view_xform_data', 'move_xform', 'transfer_xform']}¶
- name = 'owner'¶
- class onadata.libs.permissions.ReadOnlyRole¶
Bases:
Role
Read-only Role class.
- class_to_permissions = {<class 'onadata.apps.logger.models.merged_xform.MergedXForm'>: ['view_mergedxform'], <class 'onadata.apps.api.models.organization_profile.OrganizationProfile'>: ['view_organizationprofile'], <class 'onadata.apps.logger.models.project.Project'>: ['can_export_project_data', 'view_project', 'view_project_all'], <class 'onadata.apps.logger.models.xform.XForm'>: ['can_export_xform_data', 'view_xform', 'view_xform_all']}¶
- name = 'readonly'¶
- class onadata.libs.permissions.ReadOnlyRoleNoDownload¶
Bases:
Role
Read-only no download Role class.
- class_to_permissions = {<class 'onadata.apps.logger.models.merged_xform.MergedXForm'>: ['view_mergedxform'], <class 'onadata.apps.logger.models.project.Project'>: ['view_project', 'view_project_all'], <class 'onadata.apps.logger.models.xform.XForm'>: ['view_xform', 'view_xform_all']}¶
- name = 'readonly-no-download'¶
- permissions = (('view_organizationprofile', <class 'onadata.apps.api.models.organization_profile.OrganizationProfile'>), ('view_xform', <class 'onadata.apps.logger.models.xform.XForm'>), ('view_project', <class 'onadata.apps.logger.models.project.Project'>), ('view_xform_all', <class 'onadata.apps.logger.models.xform.XForm'>), ('view_project_all', <class 'onadata.apps.logger.models.project.Project'>), ('view_mergedxform', <class 'onadata.apps.logger.models.merged_xform.MergedXForm'>))¶
- class onadata.libs.permissions.Role¶
Bases:
object
Base Role class.
- classmethod add(user, obj)¶
Add obj permissions to the a user.
- class_to_permissions = {}¶
- classmethod has_role(permissions, obj)¶
Check that permission correspond to this role for this object.
- Parameters:
permissions – A list of permissions.
obj – An object or class to get the permissions of.
- name = None¶
- classmethod remove_obj_permissions(user, obj)¶
Remove all permissions the user has on the obj.
- classmethod user_has_role(user, obj)¶
Check that a user has this role.
- Parameters:
user – A user object.
obj – An object to get the permissions of.
- onadata.libs.permissions.exclude_items_from_queryset_using_xform_meta_perms(xform, user, queryset)¶
Exclude instances from the queryset if meta-perms have been enabled
- onadata.libs.permissions.filter_queryset_xform_meta_perms(xform, user, instance_queryset)¶
Check for the specific perms if meta-perms have been enabled CAN_VIEW_XFORM_ALL ==> User should be able to view all the data CAN_VIEW_XFORM_DATA ===> User should be able to view his/her submitted data. Otherwise should raise forbidden error. :param xform: :param user: :param instance_queryset: :return: data
- onadata.libs.permissions.filter_queryset_xform_meta_perms_sql(xform, user, query)¶
Check for the specific perms if meta-perms have been enabled CAN_VIEW_XFORM_ALL ==> User should be able to view all the data CAN_VIEW_XFORM_DATA ===> User should be able to view his/her submitted
data. Otherwise should raise forbidden error.
- Parameters:
xform –
user –
instance_queryset –
- Returns:
data
- onadata.libs.permissions.get_group_perms(obj)¶
Return XFormGroupObjectPermission or ProjectGroupObjectPermission queryset.
- onadata.libs.permissions.get_object_users_with_permissions(obj, username=False, with_group_users=False)¶
Returns users, roles and permissions for an object.
- Parameters:
obj – object, the object to check permissions on
username – bool, when True set username instead of a User object
- onadata.libs.permissions.get_role(permissions, obj)¶
Return the user role for the given obj permissions.
- onadata.libs.permissions.get_role_in_org(user, organization)¶
Return the user role in the organization.
- onadata.libs.permissions.get_team_project_default_permissions(team, project)¶
Return team role for given project.
- onadata.libs.permissions.get_user_perms(obj)¶
Return XFormUserObjectPermission or ProjectUserObjectPermission queryset.
- onadata.libs.permissions.is_organization(obj)¶
Some OrganizationProfiles have a pointer to the UserProfile, but no UserProfiles do. Check for that first since it avoids a database hit.