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


Python models.Image类代码示例

本文整理汇总了Python中app.models.Image的典型用法代码示例。如果您正苦于以下问题:Python Image类的具体用法?Python Image怎么用?Python Image使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: import_from_directory

def import_from_directory(path_to_images):

    connect("eventum")
    creator = User.objects().get(gplus_id="super")

    filenames = os.listdir(path_to_images)
    filenames = [fn for fn in filenames if not fn.startswith(".")]
    failures = []

    for filename in filenames:

        if Image.objects(filename=filename).count() > 0:
            img = Image.objects().get(filename=filename)
            img.delete()

        old_path = os.path.join(path_to_images, filename)
        shutil.copy(old_path, config["UPLOAD_FOLDER"])

        default_path = config["RELATIVE_UPLOAD_FOLDER"] + filename
        image = Image(filename=filename, default_path=default_path, creator=creator)
        try:
            image.save()
        except ValidationError as e:
            failures.append(filename)
            print "FAIL: %s" % filename
            print e

    print "Processed %s images." % len(filenames)
    print "%s success." % (len(filenames) - len(failures))
    print "%s failures." % len(failures)
开发者ID:benlowkh,项目名称:adi-website,代码行数:30,代码来源:import_images.py

示例2: upload

def upload():
    """Upload an image to Eventum

    **Route:** ``/admin/media/upload``

    **Methods:** ``POST``
    """
    form = UploadImageForm(request.form)
    uploaded_from = form.uploaded_from.data
    if form.validate_on_submit():
        f = request.files['image']
        if f and allowed_file(f.filename.lower()):
            filename = create_filename(f, request.form['filename'])
            f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            image = Image(filename=filename,
                          default_path=app.config['RELATIVE_UPLOAD_FOLDER']+filename,
                          creator=g.user)
            image.save()
            return redirect(url_for('.index'))
        flash("Filename {} is invalid".format(f.filename))
    if form.errors:
        flash(form.errors)
    if uploaded_from:
        return redirect(uploaded_from)
    return render_template('admin/media/upload.html', form=form)
开发者ID:Howon,项目名称:eventum,代码行数:25,代码来源:media.py

示例3: new

def new():
    """Create a new blog post.

    **Route:** ``/admin/posts/new``

    **Methods:** ``POST``
    """
    form = CreateBlogPostForm(request.form)
    form.author.choices = [
            (str(u.id), u.name + " (You)" if u == g.user else u.name)
            for u in User.objects()]
    form.author.data = str(g.user.id)
    upload_form = UploadImageForm()
    if form.validate_on_submit():
        author = User.objects().get(id=ObjectId(form.author.data))
        post = BlogPost(title=form.title.data,
                        slug=form.slug.data,
                        images=[Image.objects().get(filename=fn) for fn in form.images.data],
                        markdown_content=form.body.data,
                        author=author,
                        posted_by=g.user)
        post.save()

        if form.published.data:
            post.publish()
        else:
            post.unpublish()

        return redirect(url_for('.index'))
    images = Image.objects()
    return render_template('admin/posts/edit.html', user=g.user, form=form,
                           images=images, upload_form=upload_form)
开发者ID:Howon,项目名称:eventum,代码行数:32,代码来源:posts.py

示例4: delete

def delete(filename):
    if Image.objects(filename=filename).count() == 1:
        image = Image.objects().get(filename=filename)
        image.delete()
    else:
        flash('Invalid filename')
        pass
    return redirect(url_for('.index'))
开发者ID:lifeismotley,项目名称:eventum,代码行数:8,代码来源:media.py

示例5: save

    def save(self):
        super(ImageFile, self).save()
        img = Image()
        img.file_id = self.id
        img.image   = self.base + '.' + self.ext

        img.save()
        return self.base
开发者ID:Paaskehare,项目名称:upl.so,代码行数:8,代码来源:files.py

示例6: test_create_image

    def test_create_image(self):
        image = Image()
        image.height = 640
        image.width = 640
        image.url = 'http://scontent-b.cdninstagram.com/hphotos-xpa1/t51.2885-15/10522310_677385995673625_267718762_n.jpg'
        image.type = 'standard_resolution'

        db.session.add(image)
        db.session.commit()

        self.assertIn(image, db.session)
开发者ID:johncadengo,项目名称:willchoi.me,代码行数:11,代码来源:test_models.py

示例7: edit

def edit(post_id):
    try:
        object_id = ObjectId(post_id)
    except InvalidId:
        return abort(404)
    try:
        post = BlogPost.objects().with_id(object_id)
    except (DoesNotExist, ValidationError):
        flash('Cannot find blog post with id %s.' % post_id)
        return redirect(url_for('.index'))

    if request.method == 'POST':
        form = CreateBlogPostForm(request.form)
        form.author.choices = [
            (str(u.id), u.name + " (You)" if u == g.user else u.name)
            for u in User.objects()]
        form.author.default = str(g.user.id)
        if form.validate_on_submit():
            was_published = post.published
            should_be_published = form.published.data
            post.title = form.title.data
            post.author = User.objects.get(id=ObjectId(form.author.data))
            post.slug = form.slug.data
            post.markdown_content = form.body.data
            post.images = [Image.objects().get(filename=fn) for fn in form.images.data]
            if form.featured_image.data:
                post.featured_image = Image.objects().get(filename=form.featured_image.data)
            else:
                post.featured_image = None
            post.save()
            if was_published != should_be_published:
                if was_published:
                    set_published_status(post.id, False)
                else:
                    set_published_status(post.id, True)
            return redirect(url_for('.index'))
    upload_form = UploadImageForm()
    featured_image = post.featured_image.filename if post.featured_image else None
    form = CreateBlogPostForm(request.form,
                              title=post.title,
                              slug=post.slug,
                              published=post.published,
                              body=post.markdown_content,
                              images=[image.filename for image in post.images],
                              author=str(post.author.id),
                              featured_image=featured_image)
    form.author.choices = [
            (str(u.id), u.name + " (You)" if u == g.user else u.name)
            for u in User.objects()]
    form.author.default = str(g.user.id)
    images = [image for image in Image.objects() if image not in post.images]
    return render_template('admin/posts/edit.html', user=g.user, form=form,
                           post=post, images=images, upload_form=upload_form)
开发者ID:lifeismotley,项目名称:eventum,代码行数:53,代码来源:posts.py

示例8: delete

def delete(filename):
    """View all of the uploaded images.

    **Route:** ``/admin/media/delete/<filename>``

    **Methods:** ``POST``
    """
    if Image.objects(filename=filename).count() == 1:
        image = Image.objects().get(filename=filename)
        image.delete()
    else:
        flash('Invalid filename', ERROR_FLASH)
    return redirect(url_for('.index'))
开发者ID:benlowkh,项目名称:adi-website,代码行数:13,代码来源:media.py

示例9: create_images

def create_images(num_images, superuser, printer):
    """Creates ``num_images`` image objects in the database.  It will download
    sample images from http://lorempixel.com, and add database entries.

    :param int num_images: The number of images to create
    :param superuser: The superuser object to associate with the images.
    :type superuser: :class:`~app.models.User`
    :param printer: The object to manage progress printing.
    :type printer: :class:`~script.cli.ProgressPrinter`

    :returns: A list of images that now exist.
    :rtype: list(:class:`~app.models.Image`)
    """
    print "Generating images..."
    printer.line()

    successes = []
    failures = []
    skips = []
    for width in range(400, 1600, (1600 - 400) / num_images):
        height = width / 2
        filename = BASE_FILENAME.format(width, height)
        path = config['UPLOAD_FOLDER'] + filename
        url = BASE_URL.format(width, height)

        printer.begin_status_line(filename)

        # Download image if it doesn't exist already
        if not exists(path):
            try:
                urllib.urlretrieve(url, path)
            except IOError:
                failures.append((filename, ''))
                printer.status_fail()
                continue  # Failed to download, move on to the next image.

        # Insert or fetch image from database
        if Image.objects(filename=filename).count() == 0:
            image = Image(filename=filename,
                          default_path=path,
                          creator=superuser)
            image.save()
            successes.append((filename, path))
            printer.status_success()
        else:
            skips.append((filename, path))
            printer.status_skip()

    printer.line()
    printer.results(len(successes), len(skips), len(failures))
    return successes + skips
开发者ID:benlowkh,项目名称:adi-website,代码行数:51,代码来源:images.py

示例10: _image

    def _image(self):
        """Gets an image to associate with the event, from the database.

        :returns: The image.
        :rtype: :class:'~app.models.Image'
        """
        return random.choice(Image.objects())
开发者ID:parthibanloganathan,项目名称:adi-website,代码行数:7,代码来源:events.py

示例11: remove_images

def remove_images(app):
  from datetime import datetime

  while True:
    time.sleep(1800)
    conf = app.config['IMAGE_DELETE']
    with app.app_context():
      if ( datetime.utcnow().hour in conf['TIME_OF_DAY'] and
           datetime.utcnow().weekday() in conf['WEEKDAY'] ):
        images = Img.get_all_imgs()
        db_imgs = [img.location + img.filename for img in images]

        posts = Post.get_all()
        post_imgs = get_all_imgs((post.body_html for post in posts))

        diff_imgs = set(db_imgs) - set(post_imgs)

        if diff_imgs:
          app.logger.debug('Images to delete: {}'.format(db_imgs))

        for i in images:
          if i.location + i.filename in diff_imgs:
            if os.path.isfile(imgs.path(i.filename)):
              os.remove(imgs.path(i.filename))
              f, e = os.path.splitext(i.filename)

              if os.path.isfile(imgs.path(f + '_crop' + e)):
                os.remove(imgs.path(f + '_crop' + e))
            db.session.delete(i)
            db.session.commit()
开发者ID:finnurtorfa,项目名称:aflafrettir.is,代码行数:30,代码来源:image.py

示例12: create

def create():
    """Create a new event.

    **Route:** ``/admin/events/create``

    **Methods:** ``GET, POST``
    """

    form = CreateEventForm(request.form)
    if form.validate_on_submit():
        try:
            EventsHelper.create_event(form, g.user)
        except EventumError.GCalAPI as e:
            flash(e.message, ERROR_FLASH)

        return redirect(url_for('.index'))
    if form.errors:
        for error in form.errors:
            for message in form.errors[error]:
                flash(message, ERROR_FLASH)

    upload_form = UploadImageForm()
    delete_form = DeleteEventForm()
    images = Image.objects()
    return render_template('admin/events/create.html', form=form,
                           delete_form=delete_form, upload_form=upload_form,
                           images=images)
开发者ID:parthibanloganathan,项目名称:adi-website,代码行数:27,代码来源:events.py

示例13: edit

def edit(event_id):
    """"""
    try:
        event = Event.objects().get(id=event_id)
    except (DoesNotExist, ValidationError):
        flash('Cannont find event with id "%s"' % event_id)
        return redirect(url_for('.index'))

    form = EditEventForm(request.form) if request.method == 'POST' else \
        EventsHelper.create_form(event, request)

    if form.validate_on_submit():
        try:
            EventsHelper.update_event(event, form)
        except GoogleCalendarAPIError as e:
            flash(e.message)

        return redirect(url_for('.index'))
    if form.errors:
        for error in form.errors:
            for message in form.errors[error]:
                flash(message)

    delete_form = DeleteEventForm()
    upload_form = UploadImageForm()
    images = Image.objects()

    return render_template('admin/events/edit.html', form=form, event=event,
                           delete_form=delete_form, upload_form=upload_form,
                           images=images)
开发者ID:lifeismotley,项目名称:eventum,代码行数:30,代码来源:events.py

示例14: view

def view():
    """Displays all uploaded images.

    **Route:** ``/admin/media/view``

    **Methods:** ``GET``
    """
    images = Image.objects()
    return render_template('admin/media/view.html', images=images)
开发者ID:benlowkh,项目名称:adi-website,代码行数:9,代码来源:media.py

示例15: index

def index():
    """View all of the uploaded images.

    **Route:** ``/admin/media``

    **Methods:** ``GET``
    """
    images = Image.objects()
    form = UploadImageForm()
    return render_template('admin/media/media.html', images=images, form=form)
开发者ID:benlowkh,项目名称:adi-website,代码行数:10,代码来源:media.py


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