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)
    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)
	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)
	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)
    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)
	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)
Exemple #7
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)
    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)
    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)
Exemple #10
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)
Exemple #11
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)
    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)
Exemple #13
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)
	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)
    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)
Exemple #16
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)
    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)
    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)
Exemple #19
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)
Exemple #20
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)
	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)
    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)
	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)
Exemple #24
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)
    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)
Exemple #26
0
	def generate_invite(self, owner_userid, recipients, sender_name, subj, msg, sender_email):
		"""
		Generates an invite request to a particular user.

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

		@param recipients: List of Zoto usernames
		@type recipients: List/tuple

		@param sender_name: Plaintext name of the sender (for personal greeting in the email)
		@type sender_name: String

		@param subj: Subject of the email
		@type subj: String

		@param msg: Body of the message (to be inserted into Zoto canned text)
		@type msg: String

		@param sender_email: Email address of the sender
		@type sender_email: String
		"""	
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
			rec = []
			for email_addr in recipients:
				rec.append(validation.email(email_addr))
			recipients = rec
			sender_name = validation.string(sender_name)
			subj = validation.string(subj)
			msg = validation.string(msg)
			sender_email = validation.email(sender_email)
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
    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)
	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)
Exemple #29
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)
Exemple #30
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)
Exemple #31
0
	def binary_exists(self, media_id):
		"""
		Checks to see if a media binary already exists on the system.
		"""
		try:
			media_id = validation.media_id(media_id)
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
    def binary_exists(self, media_id):
        """
		Checks to see if a media binary already exists on the system.
		"""
        try:
            media_id = validation.media_id(media_id)
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
	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)
Exemple #34
0
	def is_modified(self, image_id):
		"""
		Determines whether a particular user has modified a binary image.

		@param image_id: ID of the image to check
		@type image_id: Integer
		"""
		try:
			image_id = validation.cast_integer(image_id, 'image_id')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
Exemple #35
0
	def _delete_binary(self, filename):
		"""
		Safely deletes a file.

		@param filename: Name of the file to be deleted.
		@type filename: String
		"""
		try:
			validation.required(filename, 'filename')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
Exemple #36
0
	def _read_binary(self, filename):
		"""
		Reads a binary file from the disk.

		@param filename: File to be read
		@type filename: String
		"""
		try:
			validation.required(filename, 'filename')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
	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)
Exemple #38
0
	def get_media_owner_id(self, image_id):
		"""
		Gets a hash media_id based on the supplied image_id.

		@param image_id: Numeric identifier for the image. 
		@type image_id: Integer
		"""
		try:
			image_id = validation.cast_integer(image_id, 'image_id')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
	def get_templates(self, owner_userid):
		"""
		Gets a list of templates for a user, some of which will be system generated.

		@param owner_userid: Particular user, or NULL for only system.
		@type owner_userid: Integer
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
	def get_account_album_permissions(self, owner_userid):
		"""
		Gets the permissions on a user's account for albums.

		@param owner_userdi: user id for Username
		@type owner_username: Int
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
Exemple #41
0
	def _get_raw_data(self, image_id):
		"""
		Gets the raw binary data for an image.

		@param image_id: ID of the image to get data for
		@type image_id: Integer
		"""
		try:
			image_id = validation.cast_integer(image_id, 'image_id')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
    def _read_binary(self, filename):
        """
		Reads a binary file from the disk.

		@param filename: File to be read
		@type filename: String
		"""
        try:
            validation.required(filename, "filename")
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
    def _delete_binary(self, filename):
        """
		Safely deletes a file.

		@param filename: Name of the file to be deleted.
		@type filename: String
		"""
        try:
            validation.required(filename, "filename")
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
    def is_modified(self, image_id):
        """
		Determines whether a particular user has modified a binary image.

		@param image_id: ID of the image to check
		@type image_id: Integer
		"""
        try:
            image_id = validation.cast_integer(image_id, "image_id")
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
Exemple #45
0
	def get_stats(self, owner_userid):
		"""
		Get message stats for a particular user.

		@param owner_username: User to get stats for
		@type owner_username: String
		"""
		try:
			owner_userid = validation.cast_integer(owner_userid, 'owner_userid')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
    def get_list_info(self, group_id):
        """
		Gets the contact group record for a particular group id
		
		@param group_id: The group id.
		@type group_id: Integer
		
		"""
        try:
            group_id = validation.cast_integer(group_id, 'group_id')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
Exemple #47
0
    def get_account_album_permissions(self, owner_userid):
        """
		Gets the permissions on a user's account for albums.

		@param owner_userdi: user id for Username
		@type owner_username: Int
		"""
        try:
            owner_userid = validation.cast_integer(owner_userid,
                                                   'owner_userid')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
	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)
	def clear_queue(self, auth_userid):
		"""
		Clears a user's print queue.

		@param auth_username: User doing the clearing.
		@type auth_username: String
		"""
		try:
			if auth_userid:
				auth_userid = validation.cast_integer(auth_userid, 'auth_userid')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex)
Exemple #50
0
	def get_list_info(self, group_id):
		"""
		Gets the contact group record for a particular group id
		
		@param group_id: The group id.
		@type group_id: Integer
		
		"""
		try:
			group_id = validation.cast_integer(group_id, 'group_id')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
Exemple #51
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)
Exemple #52
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)
    def clear_queue(self, auth_userid):
        """
		Clears a user's print queue.

		@param auth_username: User doing the clearing.
		@type auth_username: String
		"""
        try:
            if auth_userid:
                auth_userid = validation.cast_integer(auth_userid,
                                                      'auth_userid')
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex)
    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)
    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)
    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)
    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)