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


Python Image.objects方法代码示例

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


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

示例1: import_from_directory

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:32,代码来源:import_images.py

示例2: new

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:34,代码来源:posts.py

示例3: delete

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:10,代码来源:media.py

示例4: edit

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:55,代码来源:posts.py

示例5: delete

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:15,代码来源:media.py

示例6: create

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:29,代码来源:events.py

示例7: _image

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
    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,代码行数:9,代码来源:events.py

示例8: edit

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:32,代码来源:events.py

示例9: view

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:11,代码来源:media.py

示例10: _images

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
    def _images(self):
        """Gets a list of images from the database if any exist.

        :returns: The images.
        :rtype: list(:class:`~app.models.Image`)
        """
        # Fetch self.images if it hasn't been fetched
        if self.images is None:
            self.images = list(Image.objects().limit(5))
        return self.images
开发者ID:benlowkh,项目名称:adi-website,代码行数:12,代码来源:posts.py

示例11: index

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:12,代码来源:media.py

示例12: image_with_same_name

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
def image_with_same_name(form, field):
    """A validator that ensures that there is an image in the database with the
    filename that is the same as the field's data.

    :param form: The parent form
    :type form: :class:`Form`
    :param field: The field to validate
    :type field: :class:`Field`
    """
    if Image.objects(filename=field.data).count() != 1:
        return ValidationError(
            message="Can't find image '{}' in the database".format(field.data))
开发者ID:Howon,项目名称:eventum,代码行数:14,代码来源:validators.py

示例13: create_images

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
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,代码行数:53,代码来源:images.py

示例14: __call__

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
    def __call__(self, form, field):
        """Called internally by :mod:`wtforms` on validation of the field.

        :param form: The parent form
        :type form: :class:`Form`
        :param field: The field to validate
        :type field: :class:`Field`

        :raises: :class:`wtforms.validators.ValidationError`
        """

        filename = '{}.'.format(field.data)
        if Image.objects(filename__startswith=filename).count():
            raise ValidationError(self.message)
开发者ID:Howon,项目名称:eventum,代码行数:16,代码来源:validators.py

示例15: index

# 需要导入模块: from app.models import Image [as 别名]
# 或者: from app.models.Image import objects [as 别名]
def index():
    """View and manage users

    Whitelisted users are the only ones allowed to make user accounts.
    """
    upload_form = UploadImageForm()
    whitelist_form = AddToWhitelistForm()
    return render_template('admin/users/users.html',
                           whitelist_form=whitelist_form,
                           upload_form=upload_form,
                           whitelist=Whitelist.objects(redeemed=False),
                           users=User.objects(),
                           images=Image.objects(),
                           current_user=g.user)
开发者ID:lifeismotley,项目名称:eventum,代码行数:16,代码来源:users.py


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