예제 #1
0
	def untag_image(self, owner_userid, tag_userid, image_id, tag_name):
		"""
		Removes assication with tag and image

		@param owner_username: Image owner username
		@type owner_username: String

		@param tag_username: username
		@type tag_username: String

		@param media_id: Id of image assciated with tag
		@type media_id: String

		@param tag_name: tag names to be associated with images (media_ids)
		@type tag_name: String
		
		@return: Nothing
		@rtype: Nothing
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			tag_userid = validation.cast_integer(tag_userid, 'owner_userid')
			media_id = validation.cast_integer(image_id, 'image_id')
			validation.required(tag_name, 'tag_name')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #2
0
    def get_render(self, image_id, width, height, crop):
        """
		Gets a render for an image.

		@param owner_username: User who owns the image
		@type owner_username: String

		@param media_id: ID of the image
		@type media_id: String

		@param width: Width of the render
		@type width: Integer

		@param height: Height of the render
		@type height: Integer

		@param crop: Whether or not the render is cropped
		@type crop: Boolean
		"""
        try:
            image_id = validation.cast_integer(image_id, "image_id")
            width = validation.cast_integer(width, "width")
            height = validation.cast_integer(height, "height")
            crop = validation.cast_boolean(crop, "crop")
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #3
0
    def get_contact_groups(self, member_userid, glob, limit, offset):
        """
		Get a list of contact groups

		@param member_username: User account to get info for.
		@type member_username: String

		@param glob: A dictionary of settings
		@type glob : Dict

		@param limit: Number of contact groups to return.
		@type limit: Integer

		@param offset: Offset with the group list.
		@type offset: Integer

		@return: List of contact groups
		@rtype: (Deferred) List
		"""
        try:
            member_userid = validation.cast_integer(member_userid,
                                                    'member_userid')
            limit = validation.cast_integer(limit, 'limit')
            offset = validation.cast_integer(offset, 'offset')
            validation.instanceof(glob, dict, 'glob')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #4
0
	def add_rendered(self, image_id, data, width, height, crop):
		"""
		Adds a rendered image to the filesystem.

		@param media_id: ID of the image being rendered.
		@type media_id: String

		@param owner_username: User who's account the image is being rendered for.
		@type owner_username: String

		@param data: Actual binary data of the render
		@type data: String

		@param width: Requested width
		@type width: Integer

		@param height: Requested height
		@type height: Integer

		@param crop: Whether or not the image was cropped
		@type crop: Boolean
		"""
		try:
			image_id = validation.cast_integer(image_id, 'image_id')
			validation.required(data, 'data')
			if width:
				width = validation.cast_integer(width, 'width')
				height = validation.cast_integer(height, 'height')
				crop = validation.cast_boolean(crop, 'crop')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #5
0
	def get_complete_list_with_relations_owner(self, owner_userid, glob, limit, sort):
		"""
		Get *all* tags for owner_username's images and mark any that
		match the glob.

		@param owner_username: Owner of the account
		@type owner_username: String

		@param glob: A complex dictionary of limits for the user_images table
			see Glober.py for more details.
		@type glob: Dictionary
		"""
		valid_sorts = {
			'title-asc': ("t1.tag_name", "asc"),
			'title-desc': ("t1.tag_name", "desc"),
			'date_asc': ("date_added", "asc"),
			'date_desc': ("date_added", "desc"),
			'count-asc': ("cnt_images", "asc"),
			'count-desc': ("cnt_images", "desc"),
			'recent':("last_used", "desc")
		}
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			validation.required(glob, 'glob')
			limit = validation.cast_integer(limit, 'limit')
			validation.oneof(sort, valid_sorts.keys(), 'sort')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #6
0
	def render_exists(self, image_id, width, height, crop):
		"""
		Determines whether a render exists for the specified user.

		@param owner_username: User who owns the image
		@type owner_username: String

		@param media_id: ID of the image
		@type media_id: String

		@param width: Width of the render
		@type width: Integer

		@param height: Height of the render
		@type height: Integer

		@param crop: Whether or not the render is cropped
		@type crop: Boolean
		"""
		try:
			image_id = validation.cast_integer(image_id, 'image_id')
			width = validation.cast_integer(width, 'width')
			height = validation.cast_integer(height, 'height')
			crop = validation.cast_boolean(crop, 'crop')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #7
0
	def share(self, owner_userid, recipients, sender_name, subject, message, album_ids):
		"""
		Sends an invite to the list of recipients, asking them to view the
		specified albums.

		@param owner_username: Owner of the albums
		@type owner_username: String

		@param recipients: List of recipients...each entry can be a contact list name, 
					a username, or an email address.
		@type recipients: List/Tuple

		@param subject: Subject of the invite email
		@type subject: String

		@param message: Actual text of the email
		@type message: String

		@param album_ids: List of album id's
		@type album_ids: List/Tuple
		"""
		try:
			if not isinstance(recipients, (list, tuple)):
				recipients = [recipients]
			if not isinstance(album_ids, (list, tuple)):
				album_ids = [album_ids]
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			subject = validation.string(subject)
			message = validation.string(message)
			temp_ids = []
			for album_id in album_ids:
				temp_ids.append(validation.cast_integer(album_id, 'album_id'))
			album_ids = temp_ids
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #8
0
	def get_images(self, album_id, auth_userid, glob, limit, offset):
		"""
		Gets a list of the images in an album, with optional limit/offset.

		@param album_id: Album to get images for.
		@type album_id: Integer

		@param auth_username: Logged in user
		@type auth_username: String

		@param limit: Number of images to get
		@type limit: Integer

		@param offset: Offset within the album to start getting images
		@type offset: Integer
		"""
		try:
			album_id = validation.cast_integer(album_id, 'album_id')
			if auth_userid:
				auth_userid = validation.cast_integer(auth_userid, 'auth_userid')
			limit = validation.cast_integer(limit, 'limit')
			offset = validation.cast_integer(offset, 'offset')
			validation.instanceof(glob, dict, 'glob')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #9
0
	def update_image_comment(self, comment_owner, comment_id, subject, body, ip_address):
		"""
		Adds a comment to an image.

		@param commenting_username: Username making the comment.
		@type commenting_username: String

		@param comment_id: Comment being edited on.
		@type comment_id: Integer

		@param subject: Subject of the comment.
		@type subject: String

		@param body: Body of the comment.
		@type body: String

		@param ip_address: IP Address the comment is originating from
		@type ip_address: String

		@return: 0 on successful comment insertion, raises an exception otherwise.
		@rtype: Integer
		"""
		try:
			comment_owner = validation.cast_integer(comment_owner, 'comment_owner')
			comment_id = validation.cast_integer(comment_id, 'comment_id')
			validation.required(body, 'body')
			validation.required(ip_address, 'ip_address')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #10
0
    def get_complete_list_with_relations_owner(self, owner_userid, glob, limit,
                                               sort):
        """
		Get *all* tags for owner_username's images and mark any that
		match the glob.

		@param owner_username: Owner of the account
		@type owner_username: String

		@param glob: A complex dictionary of limits for the user_images table
			see Glober.py for more details.
		@type glob: Dictionary
		"""
        valid_sorts = {
            'title-asc': ("t1.tag_name", "asc"),
            'title-desc': ("t1.tag_name", "desc"),
            'date_asc': ("date_added", "asc"),
            'date_desc': ("date_added", "desc"),
            'count-asc': ("cnt_images", "asc"),
            'count-desc': ("cnt_images", "desc"),
            'recent': ("last_used", "desc")
        }
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            validation.required(glob, 'glob')
            limit = validation.cast_integer(limit, 'limit')
            validation.oneof(sort, valid_sorts.keys(), 'sort')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #11
0
    def multi_tag_image(self, owner_userid, tag_userid, image_ids, tag_names):
        """
		Associates a tag to an image

		@param owner_username: Image owner username
		@type owner_username: String

		@param tag_username: username
		@type tag_username: String

		@param media_ids: Ids of image assciated with tag
		@type media_ids: List

		@param tag_names: tag names to be associated with images (media_ids)
		@type tag_names: List
		
		@return: Nothing
		@rtype: Nothing
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            tag_username = validation.cast_integer(tag_userid, 'userid')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #12
0
	def send_message(self, from_userid, to_userids, subject, body, reply_to_id):
		"""
		Sends a message to 1 or more recipients.

		@param from_username: User sending the message.
		@type from_username: String

		@param to_usernames: List of recipients
		@type to_usernames: List

		@param subject: Subject/heading of the message
		@type subject: String

		@param body: Body of the message
		@type body: String

		@param reply_to_id: Message being replied to, if applicable
		@type reply_to_id: Integer
		"""
		try:
			from_userid = validation.cast_integer(from_userid, 'from_userid')
			subject = validation.string(subject)
			validation.required(subject, 'subject')
			body = validation.string(body)
			validation.required(body, 'body')
			reply_to_id = validation.cast_integer(reply_to_id, 'reply_to_id')
			recipients = []
			if not isinstance(to_userids, (list, tuple)):
				to_userids = [to_userids]
			for user in to_userids:
				recipients.append(validation.cast_integer(user, 'to_userid'))
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #13
0
	def set_image_permission(self, owner_userid, image_id, perm_type, flag, groups):
		"""
		Sets the flag and groups for a specific perm type (view, tag, etc)

		@param owner_userid: Userid of the user who owns the image
		@type owner_userid: Integer

		@param image_id: ID of the image
		@type media_id: Int

		@param perm_type: Permission being set
		@type perm_type: String

		@param flag: Permission value
		@type flag: Integer

		@param groups: (optional) groups to be added if flag = 2
		@type groups: List
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, "owner_userid")
			image_id = validation.cast_integer(image_id, 'image_id')
			validation.oneof(perm_type, ('view', 'tag', 'comment', 'print', 'download', 'geotag', 'vote', 'blog'), 'perm_type')
			flag = validation.cast_integer(flag, 'flag')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #14
0
    def _make_media_path(self, media_id, host, username=None, width=None, height=None, crop=None):
        """
		Makes a path to an image.

		@param media_id: ID of the image
		@type media_id: String

		@param host: Host that holds the image
		@type host: String

		@param username: User who modified the image (if applicable)
		@type username: String

		@param width: Width of the render
		@type width: Integer

		@param height: Height of the render
		@type height: Integer

		@param crop: Whether or not the render is cropped
		@type crop: Integer
		"""
        try:
            media_id = validation.media_id(media_id)
            validation.required(host, "host")
            if username:
                username = validation.username(username, "username")
            if width:
                width = validation.cast_integer(width, "width")
                height = validation.cast_integer(height, "height")
                crop = validation.cast_boolean(crop, "crop")
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #15
0
    def untag_image(self, owner_userid, tag_userid, image_id, tag_name):
        """
		Removes assication with tag and image

		@param owner_username: Image owner username
		@type owner_username: String

		@param tag_username: username
		@type tag_username: String

		@param media_id: Id of image assciated with tag
		@type media_id: String

		@param tag_name: tag names to be associated with images (media_ids)
		@type tag_name: String
		
		@return: Nothing
		@rtype: Nothing
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            tag_userid = validation.cast_integer(tag_userid, 'owner_userid')
            media_id = validation.cast_integer(image_id, 'image_id')
            validation.required(tag_name, 'tag_name')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #16
0
    def add_rendered(self, image_id, data, width, height, crop):
        """
		Adds a rendered image to the filesystem.

		@param media_id: ID of the image being rendered.
		@type media_id: String

		@param owner_username: User who's account the image is being rendered for.
		@type owner_username: String

		@param data: Actual binary data of the render
		@type data: String

		@param width: Requested width
		@type width: Integer

		@param height: Requested height
		@type height: Integer

		@param crop: Whether or not the image was cropped
		@type crop: Boolean
		"""
        try:
            image_id = validation.cast_integer(image_id, "image_id")
            validation.required(data, "data")
            if width:
                width = validation.cast_integer(width, "width")
                height = validation.cast_integer(height, "height")
                crop = validation.cast_boolean(crop, "crop")
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #17
0
	def get_list(self, owner_userid, auth_userid, include_public_tags=0, order_by="tag_name", order_dir="asc"):
                """
                Returns a flat list of tags. Each item in the list is a dictionary. Each
                dictionary having the following elements:

                        - tag_name
                        - cnt_images

                @param browse_userid: browse_userid (the user to find tags for)
                @type browse_userid: Int

                @param auth_userid: auth_userid (the logged in user making the request)
                @type browse_userid: String

                @param include_public_tags: Whether to show only tags used by this user, or everyone's tags on his photos
                @type include_public_tags: Boolean

                @param order_by: One of ('tag_name', 'cnt_images')
                @type order_by: String

                @param order_dir: One of ('asc', 'desc')
                @type order_dir: String

                @return: List of tags
                @rtype: List
                """
                try:
                        owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
                        if auth_userid:
                                auth_userid = validation.cast_integer(auth_userid, 'auth_userid')
                        validation.oneof(order_by, ('tag_name', 'cnt_images'), 'order_by')
                        validation.oneof(order_dir, ('asc', 'desc'), 'order_dir')
                except errors.ValidationError, ex:
                        return utils.return_deferred_error(ex.value)
예제 #18
0
	def _make_media_path(self, media_id, host, username=None, width=None, height=None, crop=None):
		"""
		Makes a path to an image.

		@param media_id: ID of the image
		@type media_id: String

		@param host: Host that holds the image
		@type host: String

		@param username: User who modified the image (if applicable)
		@type username: String

		@param width: Width of the render
		@type width: Integer

		@param height: Height of the render
		@type height: Integer

		@param crop: Whether or not the render is cropped
		@type crop: Integer
		"""
		try:
			media_id = validation.media_id(media_id)
			validation.required(host, 'host')
			if username:
				username = validation.username(username, 'username')
			if width:
				width = validation.cast_integer(width, 'width')
				height = validation.cast_integer(height, 'height')
				crop = validation.cast_boolean(crop, 'crop')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #19
0
	def get_outbox(self, owner_userid, glob, limit, offset):
		"""
		Gets a list of a user's sent messages.

		@param owner_username: User to get messages for.
		@type owner_username: String

		@param glob: Dictionary of options (count_only, order_by, order_dir)
		@type glob: Dictionary

		@param limit: Maximum number of messages to return
		@type limit: Integer

		@param offset: Position to start returning messages
		@type offset: Integer
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			if glob.has_key('order_by'):
				validation.oneof(glob['order_by'], ('message_id', 'to_username', 'subject', 'body', 'status', 'date_updated'), 'order_by')
			if glob.has_key('order_dir'):
				validation.oneof(glob['order_dir'], ('asc', 'desc'), 'order_dir')
			limit = validation.cast_integer(limit, 'limit')
			offset = validation.cast_integer(offset, 'offset')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #20
0
	def add_image_comment(self, owner_userid, commenting_userid, image_id, subject, body, ip_address):
		"""
		Adds a comment to an image.

		@param owner_username: Username who owns the image being commented on.
		@type owner_username: String

		@param commenting_username: Username making the comment.
		@type commenting_username: String

		@param media_id: Image being commented on.
		@type media_id: String

		@param subject: Subject of the comment.
		@type subject: String

		@param body: Body of the comment.
		@type body: String

		@param ip_address: IP Address the comment is originating from
		@type ip_address: String

		@return: 0 on successful comment insertion, raises an exception otherwise.
		@rtype: Integer
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			commenting_userid = validation.cast_integer(commenting_userid, 'commenting_userid')
			image_id = validation.cast_integer(image_id, "iamge_id")
			validation.required(body, 'body')
			validation.required(ip_address, 'ip_address')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #21
0
    def get_albums(self, owner_userid, auth_userid, glob, limit, offset):
        """
		Gets a list of a user's albums within a set.

		@param owner_username: User to get list for
		@type owner_username: String

		@param glob: dict to hold options
		@type glob: Dictionary

		@param limit: Number of albums to get
		@type limit: Integer

		@param offset: Offset within the user's albums to start at
		@type offset: Integer
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            if auth_userid:
                auth_userid = validation.cast_integer(auth_userid,
                                                      'auth_userid')
            limit = validation.cast_integer(limit, 'limit')
            offset = validation.cast_integer(offset, 'offset')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #22
0
	def delete(self, owner_userid, image_ids):
		"""
		Deletes an image->user association (removes it from their account).  The
		binary image data still exists, however, as it may be owned by other users.

		@param owner_username: Username who owns the image.
		@type owner_username: String

		@param media_ids: Single media_id or a list of media_ids to be deleted.
		@type media_ids: String, or List/Tuple of strings.

		@return: deleted media IDs
		@rtype: List
		"""
		owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
		if not isinstance(image_ids, (list, tuple)):
			image_ids = [image_ids]

		real_ids = []
		for id in image_ids:
			real_ids.append(validation.cast_integer(id, 'id'))

		def img_delete_txn(txn, userid, ids):
			for id in ids:
				txn.execute("""
					select zoto_delete_user_image(%s, %s)
					""", (userid, id))
			return ids

		d = self.app.db.runInteraction(img_delete_txn, owner_userid, real_ids)
		d.addCallback(self.app.api.mediahost.delete_user_images)
		d.addCallback(lambda _: (0, '%d images deleted' % len(real_ids)))
		d.addErrback(lambda _: (-1, _.getErrorMessage()))
		return d
예제 #23
0
    def update_image_comment(self, comment_owner, comment_id, subject, body,
                             ip_address):
        """
		Adds a comment to an image.

		@param commenting_username: Username making the comment.
		@type commenting_username: String

		@param comment_id: Comment being edited on.
		@type comment_id: Integer

		@param subject: Subject of the comment.
		@type subject: String

		@param body: Body of the comment.
		@type body: String

		@param ip_address: IP Address the comment is originating from
		@type ip_address: String

		@return: 0 on successful comment insertion, raises an exception otherwise.
		@rtype: Integer
		"""
        try:
            comment_owner = validation.cast_integer(comment_owner,
                                                    'comment_owner')
            comment_id = validation.cast_integer(comment_id, 'comment_id')
            validation.required(body, 'body')
            validation.required(ip_address, 'ip_address')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #24
0
	def _generate_rendered(self, data, image_id, width, height, crop, quality):
		"""
		Generates and stores a rendered copy of an image for a given user.

		@param media_id: ID of the image being rendered.
		@type media_id: String

		@param data: Raw binary data for the image.
		@type data: String

		@param owner_username: User the image is being rendered for.
		@type owner_username: String

		@param width: Requested width of the image.
		@type width: Integer

		@param height: Requested height of the image.
		@type height: Integer

		@param crop: Whether or not the image should be cropped to exact size.
		@type crop: Boolean

		@param quality: Quality to use for the render.
		@type quality: Integer

		@return: Rendered binary data.
		@rtype: String
		"""
		try:
			validation.required(data, 'data')
			image_id = validation.cast_integer(image_id, 'image_id')
			width = validation.cast_integer(width, 'width')
			height = validation.cast_integer(height, 'height')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #25
0
    def set_image_permission(self, owner_userid, image_id, perm_type, flag,
                             groups):
        """
		Sets the flag and groups for a specific perm type (view, tag, etc)

		@param owner_userid: Userid of the user who owns the image
		@type owner_userid: Integer

		@param image_id: ID of the image
		@type media_id: Int

		@param perm_type: Permission being set
		@type perm_type: String

		@param flag: Permission value
		@type flag: Integer

		@param groups: (optional) groups to be added if flag = 2
		@type groups: List
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   "owner_userid")
            image_id = validation.cast_integer(image_id, 'image_id')
            validation.oneof(perm_type, ('view', 'tag', 'comment', 'print',
                                         'download', 'geotag', 'vote', 'blog'),
                             'perm_type')
            flag = validation.cast_integer(flag, 'flag')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #26
0
	def get_contact_groups(self, member_userid, glob, limit, offset):
		"""
		Get a list of contact groups

		@param member_username: User account to get info for.
		@type member_username: String

		@param glob: A dictionary of settings
		@type glob : Dict

		@param limit: Number of contact groups to return.
		@type limit: Integer

		@param offset: Offset with the group list.
		@type offset: Integer

		@return: List of contact groups
		@rtype: (Deferred) List
		"""
		try:
			member_userid = validation.cast_integer(member_userid, 'member_userid')
			limit = validation.cast_integer(limit, 'limit')
			offset = validation.cast_integer(offset, 'offset')
			validation.instanceof(glob, dict, 'glob')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #27
0
    def set_account_album_permission(self, owner_userid, perm_type, flag,
                                     groups):
        """
		Sets the permissions on a user's account for albums.

		@param owner_userid: userid of the Owner username
		@type owner_username: Int

		@param perm_type: Type of permission being set (view/comment)
		@type perm_type: String

		@param flag: Permission state - one of (0, 1, 2, 3)
		@type flag: Integer

		@param groups: New group access list, if appropriate
		@type groups: List/tuple
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            validation.oneof(perm_type, ('view', 'comment'), 'perm_type')
            flag = validation.cast_integer(flag, 'flag')
            groups = validation.sequence(groups, 'groups')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #28
0
    def get_not_contacts(self, member_userid, glob, limit, offset):
        """
		Gets a list of user contacts, optionally from a specific group.
		
		@param owner_username: The account owner.
		@type owner_username: String

		@param glob: A dictionary of settings
		@type glob : Dict

		@param limit: The max results to return.
		@type limit: Integer
		
		@param offset: Offset of the result set
		@type offset: Integer

		"""
        try:
            member_userid = validation.cast_integer(member_userid,
                                                    "member_userid")
            limit = validation.cast_integer(limit, 'limit')
            offset = validation.cast_integer(offset, 'offset')
            validation.instanceof(glob, dict, 'glob')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #29
0
    def multi_get_image_tags(self, owner_userid, image_ids, tag_type='owner'):
        """
		Gets list of tags for multiple images

		@param owner_username: Image onwer username
		@type owner_username: String

		@param media_ids: image id
		@type media_ids: List

		@param tag_type: oneof("owner", "public", "all") filters private tags
			- "owner" show all tags the owner assigned
			- "public" show tags others assigned
			- "all" show all tags ("owner" + "public")
		@type tag_type: String

		@return: List of Tags
		@rtype: Dictionary of Lists
		"""
        if owner_userid:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
        for id in image_ids:
            id = validation.cast_integer(id, 'image_id')
        if tag_type == 'owner':
            include_clause = "AND tag_userid = t2.owner_userid"
        elif tag_type == 'public':
            include_clause = "AND tag_userid != t2.owner_userid"
        elif tag_type == 'all':
            include_clause = ""

        image_list = []
        for id in image_ids:
            image_list.append("%s" % id)

        owner_clause = ""
        if owner_userid:
            owner_clause = "AND t2.owner_userid = %(owner_userid)s"
        query_args = {'owner_userid': owner_userid}

        return self.app.db.query(
            """
				SELECT
					tag_name,
					count(*) AS cnt_images
				FROM
					user_image_tags t1
					JOIN user_images t2 USING (image_id)
				WHERE
					t1.image_id in (%s)
					%s
					%s
				GROUP BY
					tag_name
				ORDER BY
					tag_name asc
				""" % (','.join(image_list), owner_clause, include_clause), query_args)
예제 #30
0
	def multi_get_image_tags(self, owner_userid, image_ids, tag_type='owner'):
		"""
		Gets list of tags for multiple images

		@param owner_username: Image onwer username
		@type owner_username: String

		@param media_ids: image id
		@type media_ids: List

		@param tag_type: oneof("owner", "public", "all") filters private tags
			- "owner" show all tags the owner assigned
			- "public" show tags others assigned
			- "all" show all tags ("owner" + "public")
		@type tag_type: String

		@return: List of Tags
		@rtype: Dictionary of Lists
		"""
		if owner_userid:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
		for id in image_ids:
			id = validation.cast_integer(id, 'image_id')
		if tag_type == 'owner':
			include_clause = "AND tag_userid = t2.owner_userid"
		elif tag_type == 'public':
			include_clause = "AND tag_userid != t2.owner_userid"
		elif tag_type == 'all':
			include_clause = ""
			
		image_list = []
		for id in image_ids:
			image_list.append("%s" % id)

		owner_clause = ""
		if owner_userid:
			owner_clause = "AND t2.owner_userid = %(owner_userid)s"
		query_args = {'owner_userid': owner_userid}
			
		return self.app.db.query("""
				SELECT
					tag_name,
					count(*) AS cnt_images
				FROM
					user_image_tags t1
					JOIN user_images t2 USING (image_id)
				WHERE
					t1.image_id in (%s)
					%s
					%s
				GROUP BY
					tag_name
				ORDER BY
					tag_name asc
				""" % (','.join(image_list), owner_clause, include_clause), query_args)
예제 #31
0
	def get_comments_to_user(self, owner_userid, auth_userid, limit):
		"""
		get tags made on owner_username's photos ordered by most recent first
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			if auth_userid:
				auth_userid = validation.cast_integer(auth_userid, 'auth_userid')
			limit = validation.cast_integer(limit, 'limit')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #32
0
	def get_comments_from_user(self, commenting_userid, auth_userid, limit):
		"""
		get tags made on anyone's photos by commenting_username ordered by most recent first
		"""
		try:
			commenting_userid = validation.cast_integer(commenting_userid, 'commenting_userid')
			if auth_userid:
				auth_userid = validation.cast_integer(auth_userid, 'auth_userid')
			limit = validation.cast_integer(limit, 'limit')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #33
0
	def get_user_comments(self, userid, auth_userid, limit):
		"""
		Gets a list of comments containing both comments the user has made, and 
		comments that have been made on the user.
		"""
		try:
			userid = validation.cast_integer(userid, 'userid')
			if auth_userid:
				auth_userid = validation.cast_integer(auth_userid, 'auth_userid')
			limit = validation.cast_integer(limit, 'limit')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #34
0
    def get_featured_media(self,
                           owner_userid,
                           auth_userid,
                           order_by="date_added",
                           order_dir="desc",
                           offset=0,
                           limit=10):
        """
		Get the list of featured media for a user, ordered by date added desc

		@param owner_username: the user to fetch the list for
		@type owner_username: String

		@param order_by: The database ordering. one of 'owner_username', 'media_id', 'date_added', or 'random'
		@type order_by: String

		@param order_dir: The database ordering direction. one of 'asc' or 'desc'
		@type order_dir: String

		@param offset: The starting row of the return set
		@type offset: Integer

		@param limit: The max number of rows to retreive
		@type limit: Integer

		@return: [
				{
					media_id: MEDIA_ID,
					date_added: TIMESTAMP,
					owner_username: OWNER_USERNAME
					title: TITLE,
					description: DESCRIPTION 
				}...
			]
		@rtype: List of dictionaries
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            if auth_userid:
                auth_userid = validation.cast_integer(auth_userid,
                                                      'auth_userid')
            validation.oneof(
                order_by,
                ('owner_username', 'media_id', 'date_added', 'random'),
                'order_by')
            if order_dir:
                validation.oneof(order_dir, ('asc', 'desc'), 'order_dir')
            offset = validation.cast_integer(offset, 'offset')
            limit = validation.cast_integer(limit, 'limit')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #35
0
	def get_list(self, owner_userid, limit, offset):
		"""
		Gets the list of a user's featured albums.

		@param owner_username: User to get albums for
		@type owner_username: String
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			limit = validation.cast_integer(limit, 'limit')
			offset = validation.cast_integer(limit, 'limit')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #36
0
    def get_comments_to_user(self, owner_userid, auth_userid, limit):
        """
		get tags made on owner_username's photos ordered by most recent first
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            if auth_userid:
                auth_userid = validation.cast_integer(auth_userid,
                                                      'auth_userid')
            limit = validation.cast_integer(limit, 'limit')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #37
0
    def get_comments_from_user(self, commenting_userid, auth_userid, limit):
        """
		get tags made on anyone's photos by commenting_username ordered by most recent first
		"""
        try:
            commenting_userid = validation.cast_integer(
                commenting_userid, 'commenting_userid')
            if auth_userid:
                auth_userid = validation.cast_integer(auth_userid,
                                                      'auth_userid')
            limit = validation.cast_integer(limit, 'limit')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #38
0
    def get_user_comments(self, userid, auth_userid, limit):
        """
		Gets a list of comments containing both comments the user has made, and 
		comments that have been made on the user.
		"""
        try:
            userid = validation.cast_integer(userid, 'userid')
            if auth_userid:
                auth_userid = validation.cast_integer(auth_userid,
                                                      'auth_userid')
            limit = validation.cast_integer(limit, 'limit')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #39
0
    def get_tag_list(self, auth_userid, owner_userid, limit, offset, sort,
                     count_flag):
        """
		Returns a flat list of tags. Each item in the list is a dictionary. Each
		dictionary having the following elements:
			
			- tag_name
			- cnt_images

		@param browse_username: browse_username (the user to find tags for)
		@type browse_username: String
		
		@param auth_username: auth_username (the logged in user making the request)
		@type browse_username: String

		@param limit: Max number of tags to return
		@type limit: Integer

		@param sort: Tag sort order
		@type order_by: Integer
		
		@param offset: Offset of tags to start at
		@type offset: Integer
		
		@param count_flag: Flag to return only a count
		@type count_flag: Boolean
		
		@return: List of tags
		@rtype: List
		"""
        valid_sorts = {
            'title-asc': ("t1.tag_name", "asc"),
            'title-desc': ("t1.tag_name", "desc"),
            'date_asc': ("date_added", "asc"),
            'date_desc': ("date_added", "desc"),
            'count-asc': ("cnt_images", "asc"),
            'count-desc': ("cnt_images", "desc")
        }

        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            if auth_userid:
                auth_userid = validation.cast_integer(auth_userid,
                                                      'auth_userid')
            limit = validation.cast_integer(limit, 'limit')
            offset = validation.cast_integer(offset, 'offset')
            validation.oneof(sort, valid_sorts.keys(), 'sort')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #40
0
	def delete_contact(self, owner_userid, contact_userid):
		"""
		Deletes a members contact 

		@param owner_username: User who has the contact to be deleted
		@type owner_username: String

		@param contact_username: User contact who is being deleted
		@type contact_username: String
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			contact_userid = validation.cast_integer(contact_userid, 'contact_userid')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #41
0
	def add_contact(self, owner_userid, contact_userid):
		"""
		Add a contact to the user's account.

		@param owner_username: Owner of the account
		@type owner_username: String

		@param contact_username: User being added as a contact
		@type owner_username: String
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			contact_userid = validation.cast_integer(contact_userid, 'contact_userid')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #42
0
	def delete_contact_list(self, owner_userid, group_id):
		"""
		Deletes the specified user group.
		
		@param owner_username: The groups owner
		@type owner_username: String
		
		@param group_id: The group to be deleted.
		@type group_id: Integer
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, "owner_userid")
			group_id = validation.cast_integer(group_id, "group_id")
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #43
0
	def get_is_contact(self, owner_userid, member_userid):
		"""
		Determines whether the given user is another user's contact.

		@param owner_username: Account to check for membership
		@type owner_username: String

		@param member_username: User to check for membership in one of owner's groups.
		@type member_username: String
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			member_userid = validation.cast_integer(member_userid, 'member_userid')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #44
0
	def user_owns_album(self, userid, album_id):
		"""
		Checks to see if a particular user owns an album

		@param username: User to check for ownership.
		@type username: String

		@param album_id: Album to check.
		@type album_id: Integer
		"""
		try:
			userid = validation.cast_integer(userid, 'userid')
			album_id = validation.cast_integer(album_id, 'album_id')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #45
0
	def delete_album(self, owner_userid, album_id):
		"""
		Deletes an album.  Should also delete all associated image/set xrefs.

		@param owner_userid: Owner of the album
		@type owner_userid: Integer

		@param album_id: Album to be deleted
		@type album_id: Integer
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			album_id = validation.cast_integer(album_id, 'album_id')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #46
0
	def delete_received_message(self, to_userid, message_id):
		"""
		Deletes a message from the system

		@param to_username: User who received the message
		@type to_username: String

		@param message_id: Message to delete
		@type message_id: Integer
		"""
		try:
			to_userid = validation.cast_integer(to_userid, 'to_userid')
			message_id = validation.cast_integer(message_id, 'message_id')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #47
0
	def get_random_album(self, owner_userid, auth_userid):
		"""
		Gets an album at random from a user's list of featured albums.

		@param owner_username: User's account to get the album from
		@type owner_username: String

		@param browse_username: User viewing
		@type browse_username: String
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			if auth_userid:
				auth_userid = validation.cast_integer(auth_userid, 'auth_userid')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
예제 #48
0
    def add_user_export(self, owner_userid, export_options):
        """
		Adds a new export/publish target for a user.

		@param owner_username: User the export is for
		@type owner_username:

		@param export_options: Dictionary of options for this export service.
			Valid values:
				export_name:	User defined name for this export
				service_id:	Type of service being created
				username:	Export specific username
				password:	Export specific password
				service_url:	Export specific url
				service_extra:	Anything that doesn't fit into the above categories
		@type export_options: Dictionary
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   "owner_userid")
            export_options = validation.dict_keys(
                export_options, ('export_name', 'service_id', 'username',
                                 'password', 'service_url', 'service_extra'),
                'export_options')
            validation.required_key(export_options, 'export_name',
                                    'export_options')
            validation.required_key(export_options, 'service_id',
                                    'export_options')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #49
0
    def delete_user_export(self, owner_userid, export_id):
        """
		Removes a user export.

		@param owner_username: Owner of the export
		@type owner_username: String

		@param export_id: Export to be removed.
		@type export_id: Integer
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            export_id = validation.cast_integer(export_id, 'export_id')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #50
0
    def delete_featured_media(self, owner_userid, image_ids):
        """
		Remove media_id(s) from owner_username's featured list

		@param owner_username: The person owning the media
		@type owner_username: String

		@param media_ids: A list of media_ids to remove
		@type media_ids: Iterable

		@return: result tuple (0, "OK") for success (-1, "error message") on fail
		@rtype: Tuple
		"""
        owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
        if not isinstance(image_ids, (tuple, list)):
            return (-1, 'media_ids must be a tuple, list, or other iterable')

        # do all inserts in a single transaction
        def featured_txn(txn, owner, ids):
            for id in ids:
                image_id = validation.cast_integer(id, 'id')
                txn.execute(
                    """
					DELETE FROM
						featured_media 
					WHERE
						image_id = %s
				""", (id, ))

        d = self.app.db.runInteraction(featured_txn, owner_userid, image_ids)
        d.addCallback(lambda _: (0, '%s media removed' % len(image_ids)))
        d.addErrback(lambda _: (-1, _.getErrorMessage()))
        return d
예제 #51
0
    def get_export_info(self, owner_userid, export_id):
        """
		Gets info about a user export.

		@param owner_username: Owner of the export
		@type owner_username: String

		@param export_id: Export to get info for
		@type export_id: Integer
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            export_id = validation.cast_integer(export_id, 'export_id')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #52
0
    def publish_beta_blogger(self, owner_userid, export_info, image_ids, title,
                             description, options):
        """
		Publishes to beta-blogger.

		@param owner_username: User making the post
		@type owner_username: String

		@param export_id: User's export service they are wanting to publish with
		@type export_id: Integer

		@param media_ids: List of media id's to be published
		@type media_ids: List

		@param title: Title of the post
		@type title: String

		@param description: Body of the post
		@type description: String

		@param options: Options to be used for the post (alignment, etc)
		@type options: Dictionary
		"""
        self.log.debug("publish_blogger_beta: %s" % pformat(options))
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            validation.sequence(image_ids, 'image_ids')
            title = validation.string(title)
            validation.string(description)
            options = validation.dict_keys(options,
                                           ('alignment', 'image_size'),
                                           'options')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
예제 #53
0
    def get_unique_years(self, owner_userid):
        """
		Get the number of photos occuring in each year contained in the database.

		@param owner_username: account to select images from
		@type: String

		@return: Unique Years
		@rtype: List
		"""

        owner_clause = ""
        if owner_userid:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
            owner_clause = "AND owner_userid = %s" % owner_userid

        d = self.app.db.query("""
			SELECT
				distinct date_part('year', date) AS year
			FROM
				user_images
			WHERE
				date IS NOT NULL
				%s
			ORDER BY
				year DESC
			""" % owner_clause)
        d.addCallback(lambda _: (0, _))
        d.addErrback(lambda _: (-1, _.getErrorMessage()))
        return d
예제 #54
0
	def rotate(self, image_id, direction):
		"""
		Rotates an image.  The newly rotated image will be stored in media_binaries.
		
		Also see:
			
			- L{crop} for cropping an image.
			- L{normalize} for auto-balancing the contrast of an image.
			- L{remove_filters} for removing filters from an image.
		
		@param owner_username: Username
		@type owner_username: String
		
		@param media_id: Media ID
		@type media_id: String
		
		@param direction: Direction to rotate image. Either ('cw' or 'ccw') for
		clock-wise or counter-clock-wise.
		@type direction: String
		
		@return: New Image ID
		@rtype: (Deferred) String
		"""
		try:
			image_id = validation.cast_integer(image_id, 'image_id')
			validation.oneof(direction, ('ccw', 'cw'), direction)
		except errors.ValidationError, ex:
			self.log.warning("Validation failure: %s" % str(ex))
			raise errors.APIError, str(ex)
예제 #55
0
	def is_active(self, image_id):
		"""
		Determines if a particular user has an active (servable) copy
		of an image.

		@param media_id: Media ID to check.
		@type media_id: String

		@param owner_username: User to check ownership for.
		@type owner_username: String

		@return: Whether or not the specified user owns a copy of the image.
		@rtype: Boolean
		"""
		image_id = validation.cast_integer(image_id, 'image_id')

		@stack
		def check_result(result):
			if result['active']:
				return True
			return False

		d = self.app.db.query("""
			SELECT
				count(*) as active
			FROM
				user_images
			WHERE
				image_id = %s and
				status = 1
			""", (image_id, ), single_row=True)
		d.addCallback(check_result)
		return d
		stack
예제 #56
0
    def completely_edit_tag(self, owner_userid, tag_name, new_name):
        """
		Updates tag on all users pics

		@param owner_username: Image owner username
		@type owner_username: String

		@param tag_name: tag name to be removed
		@type tag_name: String
		
		@param new_name: new name for the tag
		@type new_name: String
		
		@return: Nothing
		@rtype: Nothing
		"""
        owner_userid = validation.cast_integer(owner_userid, 'owner_userid')

        validation.required(tag_name, 'tag_name')
        tag_name = tag_name.strip()
        tag_name = tag_name.lower()

        validation.required(new_name, 'new_name')
        new_name = new_name.strip()
        new_name = new_name.lower()

        d = self.app.db.runOperation(
            """
				select zoto_update_tag_for_all_user_images(%s, %s, %s)
				""", (owner_userid, tag_name, new_name))
        return d