当前位置: 首页>>代码示例>>Python>>正文


Python Image.select方法代码示例

本文整理汇总了Python中models.Image.select方法的典型用法代码示例。如果您正苦于以下问题:Python Image.select方法的具体用法?Python Image.select怎么用?Python Image.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Image的用法示例。


在下文中一共展示了Image.select方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_contents

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import select [as 别名]
 def get_contents(self):
     db_id = Directory.get(Directory.key == self.key).id
     directories = Directory.select().where(Directory.parent_directory == db_id)
     has_probes = False
     try:
         has_probes = Directory.get(Directory.key == directories
                             .first().key).images.first()
     except:
         pass
     if has_probes:
         directories = [DirectoryTree(d.name, d.key).get_contents() for d in directories]
         self.directories = [d.serialized for d in directories]
     else:
         self.directories = [DirectoryTree(d.name, d.key).serialized for d in directories]
     self.images = [image.serialized for image in Image.select().where(Image.directory == db_id)]
     if self.images:
         stack_title = self.key[:-1]
         try:
             stack_id = Stack.get(Stack.title == stack_title).id
         except models.DoesNotExist:
             images = Image.select().where(Image.directory == db_id)
             stack = models.Stack.create(title=stack_title)
             for image in images:
                 try:
                     models.StackImage.create(stack=stack, image = image.id)
                 except Exception as ex:
                     print ex
             stack_id = stack.id
         self.stack_id = stack_id
     return self
开发者ID:BlaiseGratton,项目名称:DataAnalysisNgin,代码行数:32,代码来源:directory.py

示例2: gallery

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import select [as 别名]
def gallery(id=None):
    # Get gallery images associated with feed #id
    if id is None:
        images = Image.select()
    else:
        images = Image.select().where(Feed.id == id).paginate(1, 50)

    return render_template("gallery.html",
                           images=images)
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:11,代码来源:views.py

示例3: image_timeline

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import select [as 别名]
def image_timeline():

    """
        function that is called when the url for images
        is being requested
    """
    images = Image.select().order_by(('id', 'asc'))
    return object_list('images.html', images, 'image_list')
开发者ID:annebaui,项目名称:srimato,代码行数:10,代码来源:views.py

示例4: project_stack_images

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import select [as 别名]
def project_stack_images(project_id, stack_id):
    first_image = Image.select().join(StackImage).where(StackImage.stack == stack_id).get().key
    last_underscore = first_image.rfind('_')
    stack_title = first_image[:last_underscore]
    project_stack = ProjectStack.get(ProjectStack.project == project_id, ProjectStack.stack == stack_id)
    project_stack_user_data = project_stack.project_stack_data.where(ProjectStackDatum.user == g.user_id)
    probe_type = project_stack.project.probe_type
    probe_settings = project_stack.probe_setting.get()
    images = (Image.select().join(StackImage).where(StackImage.stack == stack_id)
                .order_by(Image.name))
    project_stacks = Stack.select().join(ProjectStack).where(ProjectStack.project == project_id).order_by(Stack.id)
    marker_options = MarkerOption.select().join(ProjectMarkerOption).where(ProjectMarkerOption.project == project_id)
    return jsonify({ 'images': [image.stack_image_serialized for image in images],
                     'data': [d.serialized for d in project_stack_user_data],
                     'probeSettings': probe_settings.serialized,
                     'stackTitle': stack_title,
                     'probeType': probe_type,
                     'markerOptions': [marker_option.name for marker_option in marker_options],
                     'projectStackIds': [stack.id for stack in project_stacks]
                    })
开发者ID:BlaiseGratton,项目名称:DataAnalysisNgin,代码行数:22,代码来源:image_routes.py

示例5: send_captcha

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import select [as 别名]
def send_captcha():
  """ Picks a random combination of image and sentence. """
  x = Image.select().order_by(fn.Rand()).limit(1) # pick random image
  image_url = IM_DOMAIN + x[0].filename
  
  y = Secondary.select().order_by(fn.Rand()).limit(1) # pick random secondary
  sec_url = SEC_DOMAIN + y[0].filename

  # Wrap both image and sentence URLs using jsonify.
  # Then serve both URLs in JSON format. 
  return jsonify(image_id=x[0].id, image_url=image_url,
                 sec_id=y[0].id, sec_url = sec_url)
开发者ID:zatricion,项目名称:nuCAPTCHA,代码行数:14,代码来源:views.py

示例6: getImages

# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import select [as 别名]
def getImages(post_id, makeThumb=True):

    # Image HTTP content types
    # TODO: Add others -- this should be a standard function
    extensions = {'image/gif': 'gif', 'image/jpeg': 'jpg', 'image/pjpeg': 'jpg', 'image/png': 'png'}

    post = Post.get(Post.id == post_id)
    html = post.content
    feed = post.feed_id

    soup = BS(html)

    img_num = 0

    # Attempt to get images in HTML fragment
    for tag in soup.find_all('img'):
        image_url = tag['src']
        try:
            f = urllib.request.urlopen(image_url) # TODO: Replace with Request
            http = f.info()
            content_type = http.type  # Get HTTP Content-Type to determine file extension
        except urllib.error.HTTPError:
            continue

        # If unrecognised content-type, skip this URL
        if content_type not in extensions:
            continue

        # TODO: Check image size, skip below size limit (avoids saving 1x1 pixel bugs)
        # Reasonable default would be existing thumbnail size

        # Check to see if URL already exists in Image table
        url_num = Image.select().where(Image.url == image_url).count()

        # If not found, add to cache
        if url_num == 0:

            log.info("Found image %s, writing to cache", image_url)

            # Read image data from url
            image_data = f.read()

            # Create feed directory as required
            image_path = '{0}{1}'.format(IMAGE_PATH, str(feed))
            if not os.path.exists(image_path):
                os.makedirs(image_path)

            # Use HTTP content-type to decide extension
            # IMAGE_PATH/[feed_id]/[post_id]_[image_number].[ext]

            image_file = '{0}{1}/img_{2}.{3}'.format(IMAGE_PATH, str(feed), str(img_num), extensions[content_type])

            with open(image_file, 'wb') as img:
                img.write(image_data)
            img.close()

            # Add to Image database table
            Image.create(post_id=post_id, feed_id=feed, url=image_url, path=image_file)

            if makeThumb:

                # Create corresponding thumbnail using Pillow, add to thumbnail cache dir
                thumb_file = '{0}{1}/thumb_{2}.{3}'.format(THUMB_PATH, str(feed), str(img_num), extensions[content_type])

                try:
                    thumb = Im.open(image_file)
                    thumb.thumbnail(THUMB_SIZE)
                    thumb.save(thumb_file, "JPEG")
                except IOError:
                    log.error("Cannot create thumbnail for %s", image_file)

            # increment image counter
            img_num += 1
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:75,代码来源:Imgcache.py


注:本文中的models.Image.select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。