Esempio n. 1
0
    def delete_screenshot(self, screenshot):
        this_screenshot = model.Screenshot.q().get(screenshot)
        if not this_screenshot:
            abort(404)

        package = this_screenshot.package

        # Make sure the user is allowed to delete the screenshot!
        if not my.authorized_for_screenshot(this_screenshot):
            abort(403, "I'm afraid I can't do that, Dave.")

        # Admins or the one who uploaded the screenshot is allowed to delete
        elif ('username' in session) or (my.client_cookie_hash() is not None and my.client_cookie_hash() == this_screenshot.uploaderhash):
            db.delete(this_screenshot)
            for image_path in this_screenshot.image_paths:
                if os.path.isfile(image_path):
                    os.unlink(image_path)
            my.message('Screenshot for package <em>%s</em> deleted.' % package.name)
        # If the screenshot is 'approved' and the current user is not an admin
        # then it's only possible to mark the screenshot for deletion by an admin.
        else:
            this_screenshot.markedfordelete=True
            this_screenshot.delete_reason=request.params.get('reason','?')[:100]
            my.message('Admins will be asked to delete this screenshot.')

        db.commit()

        # TODO: The approved screenshots have changes. Remove the cached start page.

        # Try to redirect to the backlink (if provided)
        my.redirect_back()

        # Otherwise redirect to the package overview
        redirect(url('package', package=package.name))
Esempio n. 2
0
    def my_screenshots(self):
        """Return a list of screenshots uploaded by the current user.

        As users do not need to login before they can upload screenshots
        they are only identified by their client cookie. So this method
        returns all screenshots that have the same cookie hash value
        stored as the current cookie sent by the browser."""
        client_cookie_hash = my.client_cookie_hash()
        return [ss for ss in self.screenshots
                if client_cookie_hash is not None
                and ss.uploaderhash==client_cookie_hash]
Esempio n. 3
0
def _filter(packages, search=None, debtags_search=None):
    """Filter a query of packages by given criteria"""
    # Only show packages with approved screenshots or the user's own screenshots
    # (JOINing reduces the packages to those which have corresponding screenshots)
    cookie_hash = my.client_cookie_hash()
    packages = packages.options(model.orm.eagerload('screenshots'))

    # Search for word
    if search:
        packages = packages.filter(
            (model.Package.name.like('%'+search+'%'))
            |
            (model.Package.description.ilike('%'+search+'%'))
        )

    # Search for debtag
    if debtags_search:
        db_debtag = model.Debtag.q().filter_by(tag=unicode(debtags_search)).first()
        if not db_debtag:
            abort(404, 'Sorry, no packages with this debtag could be found.')
        packages = packages.join('debtags').filter(model.Debtag.tag==unicode(debtags_search))

    return packages
Esempio n. 4
0
 def my_or_approved_screenshots(self):
     """Return a list of the user's own or any approved screenshots"""
     client_cookie_hash = my.client_cookie_hash()
     return [ss for ss in self.screenshots
             if client_cookie_hash is not None
             and (ss.approved or ss.uploaderhash==client_cookie_hash)]
Esempio n. 5
0
    image_types = model.image_types
    to_save = []
    try:
        for image_type in image_types:
            image_copy = image.copy()
            image_copy.thumbnail(image_type['size'], Image.ANTIALIAS)
            #imgc.convert('RGB')
            to_save.append((image_copy, image_type))
    except IOError, e:
        return "There seems to be a problem with your image: %s" % e

    # Create screenshot entry
    db_screenshot = model.Screenshot(
        uploaderip=my.client_ip(),
        uploaderhash=my.client_cookie_hash(),
        version=version,
        description=description,
    )

    # Screenshots uploaded by admins are automatically approved
    if 'username' in session:
        db_screenshot.approved = True

    db_pkg.screenshots.append(db_screenshot)

    db.commit()

    # Create the package's screenshots path if it does not exist yet
    if not os.path.isdir(db_screenshot.directory):
        log.debug("Create destination directory: %s", db_screenshot.directory)