class MappedTasksByUser(Model): """ Describes number of tasks user has mapped on a project""" username = StringType(required=True) mapped_task_count = IntType(required=True, serialized_name="mappedTaskCount") tasks_mapped = ListType(IntType, required=True, serialized_name="tasksMapped") last_seen = UTCDateTimeType(required=True, serialized_name="lastSeen") mapping_level = StringType(required=True, serialized_name="mappingLevel") date_registered = UTCDateTimeType(serialized_name="dateRegistered") last_validation_date = UTCDateTimeType(serialized_name="lastValidationDate")
def test_utc_type(): field = UTCDateTimeType() dt = field.to_native('2015-11-08T12:34:56.0369-0730') assert dt == datetime(2015, 11, 8, 20, 4, 56, 36900) dt = field.to_native('2015-11-08 12:34:56.00Z') assert dt == datetime(2015, 11, 8, 12, 34, 56, 0) dt = field.to_native('2015-11-08 12:34:56.00') assert dt == datetime(2015, 11, 8, 12, 34, 56, 0) UTCDateTimeType(default=datetime.utcnow)
class TaskStatusDTO(Model): """Describes a DTO for the current status of the task""" task_id = IntType(serialized_name="taskId") task_status = StringType(serialized_name="taskStatus") action_date = UTCDateTimeType(serialized_name="actionDate") action_by = StringType(serialized_name="actionBy")
class ApplicationDTO(Model): """ Describes JSON model used for creating grids """ id = IntType(required=True, serialized_name="keyId") user = IntType(required=True, serialized_name="userId") app_key = StringType(required=True, serialized_name="applicationkey") created = UTCDateTimeType(required=True, serialized_name="createdDate")
class ProjectComment(Model): """ Describes an individual user comment on a project task """ comment = StringType() comment_date = UTCDateTimeType(serialized_name="commentDate") user_name = StringType(serialized_name="userName") task_id = IntType(serialized_name="taskId")
class ChatMessageDTO(Model): """ DTO describing an individual project chat message """ message = StringType(required=True) user_id = IntType(required=True, serialize_when_none=False) project_id = IntType(required=True, serialize_when_none=False) picture_url = StringType(default=None, serialized_name="pictureUrl") timestamp = UTCDateTimeType() username = StringType()
class InvalidatedTask(Model): """ Describes invalidated tasks with which user is involved """ task_id = IntType(required=True, serialized_name="taskId") project_id = IntType(required=True, serialized_name="projectId") project_name = StringType(serialized_name="projectName") history_id = IntType(serialized_name="historyId") closed = BooleanType() updated_date = UTCDateTimeType(serialized_name="updatedDate")
class TaskHistoryDTO(Model): """ Describes an individual action that was performed on a mapping task""" history_id = IntType(serialized_name="historyId") task_id = StringType(serialized_name="taskId") action = StringType() action_text = StringType(serialized_name="actionText") action_date = UTCDateTimeType(serialized_name="actionDate") action_by = StringType(serialized_name="actionBy") picture_url = StringType(serialized_name="pictureUrl") issues = ListType(ModelType(TaskMappingIssueDTO))
class ListSearchResultDTO(Model): """ Describes one search result""" project_id = IntType(required=True, serialized_name="projectId") locale = StringType(required=True) name = StringType(default="") short_description = StringType(serialized_name="shortDescription", default="") mapper_level = StringType(required=True, serialized_name="mapperLevel") priority = StringType(required=True) organisation_name = StringType(serialized_name="organisationName") organisation_logo = StringType(serialized_name="organisationLogo") campaigns = ListType(ModelType(CampaignDTO), default=[]) percent_mapped = IntType(serialized_name="percentMapped") percent_validated = IntType(serialized_name="percentValidated") status = StringType(serialized_name="status") active_mappers = IntType(serialized_name="activeMappers") last_updated = UTCDateTimeType(serialized_name="lastUpdated") due_date = UTCDateTimeType(serialized_name="dueDate") total_contributors = IntType(serialized_name="totalContributors") country = StringType(serialize_when_none=False)
class DocumentImageResource(Model): document_category = DocumentCategory(default=None) document_type = DocumentType(default=None) id = UUIDType(default=None) image_type = DocumentImageType(default=None) upload_date = UTCDateTimeType(formats=['%Y-%m-%d %H:%M:%S'], serialized_format='%Y-%m-%d %H:%M:%S', default=None) provider_reference = StringType(default=None) class Options: export_level = NOT_NONE
class UserDTO(Model): """ DTO for User """ validation_message = BooleanType(default=True) id = LongType() username = StringType() role = StringType() mapping_level = StringType( serialized_name="mappingLevel", validators=[is_known_mapping_level] ) date_registered = UTCDateTimeType(serialized_name="dateRegistered") tasks_mapped = IntType(serialized_name="tasksMapped") tasks_validated = IntType(serialized_name="tasksValidated") tasks_invalidated = IntType(serialized_name="tasksInvalidated") email_address = EmailType(serialized_name="emailAddress") is_email_verified = EmailType( serialized_name="isEmailVerified", serialize_when_none=False ) is_expert = BooleanType(serialized_name="isExpert", serialize_when_none=False) twitter_id = StringType(serialized_name="twitterId") facebook_id = StringType(serialized_name="facebookId") linkedin_id = StringType(serialized_name="linkedinId") slack_id = StringType(serialized_name="slackId") irc_id = StringType(serialized_name="ircId") skype_id = StringType(serialized_name="skypeId") city = StringType(serialized_name="city") country = StringType(serialized_name="country") name = StringType(serialized_name="name") picture_url = StringType(serialized_name="pictureUrl") default_editor = StringType(serialized_name="defaultEditor") mentions_notifications = BooleanType(serialized_name="mentionsNotifications") comments_notifications = BooleanType(serialized_name="commentsNotifications") projects_notifications = BooleanType(serialized_name="projectsNotifications") # these are read only missing_maps_profile = StringType(serialized_name="missingMapsProfile") osm_profile = StringType(serialized_name="osmProfile") gender = StringType( serialized_name="gender", choices=("MALE", "FEMALE", "SELF_DESCRIBE", "PREFER_NOT"), ) self_description_gender = StringType( serialized_name="selfDescriptionGender", default=None ) def validate_self_description(self, data, value): if ( data["gender"] == "SELF_DESCRIBE" and data["self_description_gender"] is None ): raise ValueError("selfDescription field is not defined") return value
class MessageDTO(Model): """ DTO used to define a message that will be sent to a user """ message_id = IntType(serialized_name="messageId") subject = StringType(required=True) message = StringType(required=True, serialize_when_none=False) from_user_id = IntType(required=True, serialize_when_none=False) from_username = StringType(serialized_name="fromUsername", default="") project_id = IntType(serialized_name="projectId") project_title = StringType(serialized_name="projectTitle") task_id = IntType(serialized_name="taskId") message_type = StringType(serialized_name="messageType") sent_date = UTCDateTimeType(serialized_name="sentDate") read = BooleanType()
class TransactionData(Model): class OperationData(Model): id = StringType() source_account = StringType() type = StringType() created_at = UTCDateTimeType() transaction_hash = StringType() asset_type = StringType() # TODO: enums? asset_code = StringType() # TODO: min, max length? asset_issuer = StringType() limit = DecimalType() trustor = StringType() trustee = StringType() from_address = StringType() to_address = StringType() amount = DecimalType() hash = StringType() # TODO: min, max length? created_at = UTCDateTimeType() source_account = StringType() # TODO: min, max length? source_account_sequence = StringType() operations = ListType(ModelType(OperationData), default=[]) memo_type = StringType() memo = StringType() fee_paid = DecimalType() signatures = ListType(StringType, default=[]) # id # paging_token # envelope_xdr # time_bounds # ledger # _links # result_xdr # result_meta_xdr # operation_count # fee_meta_xdr # TODO: do it properly def __str__(self): sb = [] for key in self.__dict__: if not key.startswith('__'): sb.append("\t{key}='{value}'".format(key=key, value=self.__dict__[key])) return '\n'.join(sb) def __repr__(self): return self.__str__()
class OperationData(PModel): id = StringType() source_account = StringType() type = StringType() created_at = UTCDateTimeType() transaction_hash = StringType() asset_type = StringType() asset_code = StringType() asset_issuer = StringType() limit = DecimalType() trustor = StringType() trustee = StringType() from_address = StringType(serialized_name='from') to_address = StringType(serialized_name='to') amount = DecimalType()
class OperationData(Model): id = StringType() source_account = StringType() type = StringType() created_at = UTCDateTimeType() transaction_hash = StringType() asset_type = StringType() # TODO: enums? asset_code = StringType() # TODO: min, max length? asset_issuer = StringType() limit = DecimalType() trustor = StringType() trustee = StringType() from_address = StringType() to_address = StringType() amount = DecimalType()
class TaskDTO(Model): """ Describes a Task DTO """ task_id = IntType(serialized_name="taskId") project_id = IntType(serialized_name="projectId") task_status = StringType(serialized_name="taskStatus") lock_holder = StringType(serialized_name="lockHolder", serialize_when_none=False) task_history = ListType(ModelType(TaskHistoryDTO), serialized_name="taskHistory") task_annotations = ListType(ModelType(TaskAnnotationDTO), serialized_name="taskAnnotation") per_task_instructions = StringType(serialized_name="perTaskInstructions", serialize_when_none=False) auto_unlock_seconds = IntType(serialized_name="autoUnlockSeconds") last_updated = UTCDateTimeType(serialized_name="lastUpdated", serialize_when_none=False)
class TransactionData(PModel): id = StringType() hash = StringType() created_at = UTCDateTimeType() source_account = StringType() source_account_sequence = StringType() operations = ListType(ModelType(OperationData), default=[]) operation_count = IntType() ledger = StringType() memo_type = StringType() memo = StringType() fee_paid = DecimalType() signatures = ListType(StringType, default=[]) paging_token = StringType() envelope_xdr = StringType() result_xdr = StringType() result_meta_xdr = StringType() fee_meta_xdr = StringType() time_bounds = ListType(IntType, default=[])
class ProjectSummary(Model): """ Model used for PM dashboard """ project_id = IntType(required=True, serialized_name="projectId") default_locale = StringType(serialized_name="defaultLocale") author = StringType() created = UTCDateTimeType() due_date = UTCDateTimeType(serialized_name="dueDate") last_updated = UTCDateTimeType(serialized_name="lastUpdated") priority = StringType(serialized_name="projectPriority") campaigns = ListType(ModelType(CampaignDTO), default=[]) organisation = IntType() organisation_name = StringType(serialized_name="organisationName") organisation_logo = StringType(serialized_name="organisationLogo") country_tag = ListType(StringType, serialized_name="countryTag") osmcha_filter_id = StringType(serialized_name="osmchaFilterId") mapping_types = ListType( StringType, serialized_name="mappingTypes", validators=[is_known_mapping_type] ) changeset_comment = StringType(serialized_name="changesetComment") percent_mapped = IntType(serialized_name="percentMapped") percent_validated = IntType(serialized_name="percentValidated") percent_bad_imagery = IntType(serialized_name="percentBadImagery") aoi_centroid = BaseType(serialized_name="aoiCentroid") mapper_level = StringType(serialized_name="mapperLevel") mapping_permission = IntType( serialized_name="mappingPermission", validators=[is_known_mapping_permission] ) validation_permission = IntType( serialized_name="validationPermission", validators=[is_known_validation_permission], ) allowed_usernames = ListType( StringType(), serialized_name="allowedUsernames", default=[] ) random_task_selection_enforced = BooleanType( required=False, default=False, serialized_name="enforceRandomTaskSelection" ) private = BooleanType(serialized_name="private") allowed_users = ListType(StringType, serialized_name="allowedUsernames", default=[]) project_teams = ListType(ModelType(ProjectTeamDTO), serialized_name="teams") project_info = ModelType( ProjectInfoDTO, serialized_name="projectInfo", serialize_when_none=False ) short_description = StringType(serialized_name="shortDescription") status = StringType() imagery = StringType() license_id = IntType(serialized_name="licenseId") id_presets = ListType(StringType, serialized_name="idPresets", default=[]) mapping_editors = ListType( StringType, min_size=1, required=True, serialized_name="mappingEditors", validators=[is_known_editor], ) validation_editors = ListType( StringType, min_size=1, required=True, serialized_name="validationEditors", validators=[is_known_editor], ) custom_editor = ModelType( CustomEditorDTO, serialized_name="customEditor", serialize_when_none=False )
class ProjectDTO(Model): """ Describes JSON model for a tasking manager project """ project_id = IntType(serialized_name="projectId") project_status = StringType( required=True, serialized_name="status", validators=[is_known_project_status], serialize_when_none=False, ) project_priority = StringType( required=True, serialized_name="projectPriority", validators=[is_known_project_priority], serialize_when_none=False, ) area_of_interest = BaseType(serialized_name="areaOfInterest") aoi_bbox = ListType(FloatType, serialized_name="aoiBBOX") tasks = BaseType(serialize_when_none=False) default_locale = StringType( required=True, serialized_name="defaultLocale", serialize_when_none=False ) project_info = ModelType( ProjectInfoDTO, serialized_name="projectInfo", serialize_when_none=False ) project_info_locales = ListType( ModelType(ProjectInfoDTO), serialized_name="projectInfoLocales", serialize_when_none=False, ) mapper_level = StringType( required=True, serialized_name="mapperLevel", validators=[is_known_mapping_level], ) mapping_permission = StringType( required=True, serialized_name="mappingPermission", validators=[is_known_mapping_permission], ) validation_permission = StringType( required=True, serialized_name="validationPermission", validators=[is_known_validation_permission], ) enforce_random_task_selection = BooleanType( required=False, default=False, serialized_name="enforceRandomTaskSelection" ) private = BooleanType(required=True) changeset_comment = StringType(serialized_name="changesetComment") osmcha_filter_id = StringType(serialized_name="osmchaFilterId") due_date = UTCDateTimeType(serialized_name="dueDate") imagery = StringType() josm_preset = StringType(serialized_name="josmPreset", serialize_when_none=False) id_presets = ListType(StringType, serialized_name="idPresets", default=[]) mapping_types = ListType( StringType, serialized_name="mappingTypes", default=[], validators=[is_known_mapping_type], ) campaigns = ListType(ModelType(CampaignDTO), default=[]) organisation = IntType() organisation_name = StringType(serialized_name="organisationName") organisation_logo = StringType(serialized_name="organisationLogo") country_tag = ListType(StringType, serialized_name="countryTag") license_id = IntType(serialized_name="licenseId") allowed_usernames = ListType( StringType(), serialized_name="allowedUsernames", default=[] ) priority_areas = BaseType(serialized_name="priorityAreas") created = UTCDateTimeType() last_updated = UTCDateTimeType(serialized_name="lastUpdated") author = StringType() active_mappers = IntType(serialized_name="activeMappers") percent_mapped = IntType(serialized_name="percentMapped") percent_validated = IntType(serialized_name="percentValidated") percent_bad_imagery = IntType(serialized_name="percentBadImagery") task_creation_mode = StringType( required=True, serialized_name="taskCreationMode", validators=[is_known_task_creation_mode], serialize_when_none=False, ) project_teams = ListType(ModelType(ProjectTeamDTO), serialized_name="teams") mapping_editors = ListType( StringType, min_size=1, required=True, serialized_name="mappingEditors", validators=[is_known_editor], ) validation_editors = ListType( StringType, min_size=1, required=True, serialized_name="validationEditors", validators=[is_known_editor], ) custom_editor = ModelType( CustomEditorDTO, serialized_name="customEditor", serialize_when_none=False ) interests = ListType(ModelType(InterestDTO))
class NotificationDTO(Model): """ DTO used to define a notification count that will be sent to a user """ user_id = IntType(serialized_name="userId") date = UTCDateTimeType(serialized_name="date") unread_count = IntType(serialized_name="unreadCount")
class User(XMLModel): created = UTCDateTimeType()
end_date, (extract(epoch from (end_date - start_date)) / 86400) as days, ( SELECT COUNT(*) FROM play WHERE date >= start_date AND date < end_date + '1 day'::interval ) as plays FROM current_interval; """) return await result.fetchone() @validate.params(artist=StringType(min_length=1, max_length=50), album=StringType(min_length=1, max_length=50), track=StringType(min_length=1, max_length=50), date_lt=UTCDateTimeType(), date_gt=UTCDateTimeType(), order=OrderType('artist', 'album', 'track', 'date'), limit=IntType(required=True, min_value=1, max_value=100), offset=IntType(required=True, min_value=0)) async def find_many(conn, params): artist_name = artist.c.name.label('artist') album_name = album.c.name.label('album') track_name = track.c.name.label('track') filters = [] if 'artist' in params: filters.append(artist_name.ilike('%{}%'.format(params['artist']))) if 'album' in params: filters.append(album_name.ilike('%{}%'.format(params['album']))) if 'track' in params:
)) async def find_one(conn, **kwargs): query = select([artist.c.name.label('artist_name'), album]) for key, value in kwargs.items(): query = query.where(getattr(album.c, key) == value) query = query.select_from(album.join(artist)) result = await conn.execute(query) return await result.fetchone() @validate.params( artist=StringType(min_length=1, max_length=50), name=StringType(min_length=1, max_length=50), first_play_lt=UTCDateTimeType(), first_play_gt=UTCDateTimeType(), last_play_lt=UTCDateTimeType(), last_play_gt=UTCDateTimeType(), order=OrderType('artist', 'name', 'first_play', 'last_play', 'plays'), limit=IntType(required=True, min_value=1, max_value=100), offset=IntType(required=True, min_value=0) ) async def find_many(conn, params): artist_name = artist.c.name.label('artist') filters = [] if 'artist' in params: filters.append(artist_name.ilike('%{}%'.format(params['artist']))) if 'name' in params: filters.append(album.c.name.ilike('%{}%'.format(params['name'])))