Esempio n. 1
0
def _externalize(listing):
    """Returns a safe JSON blob representing the given listing."""

    return {
        "jsonURL": url_for(
            "api_one_listing", permalink=listing.permalink, _external=True),
        "htmlURL": url_for(
            "show_listing", permalink=listing.permalink, _external=True),
        "title": listing.title,
        "body": listing.body,
        "postingTime": listing.posting_time,
        "categories": [
            {
                "name": category,
                "URL": url_for("api_all_listings", q=category, _external=True)
            } for category in listing.categories
        ],
        "price": (listing.price / 100.0),
        "inquiries": len(listing.buyers),
        "photos": [
            {
                "small": photos.public_url(photo, "small"),
                "large": photos.public_url(photo, "large"),
            }
        for photo in listing.photos]
    }
Esempio n. 2
0
def _externalize(listing):
    """Returns a safe JSON blob representing the given listing."""

    return {
        "jsonURL":
        url_for("api_one_listing", permalink=listing.permalink,
                _external=True),
        "htmlURL":
        url_for("show_listing", permalink=listing.permalink, _external=True),
        "title":
        listing.title,
        "body":
        listing.body,
        "postingTime":
        listing.posting_time,
        "categories": [{
            "name":
            category,
            "URL":
            url_for("api_all_listings", q=category, _external=True)
        } for category in listing.categories],
        "price": (listing.price / 100.0),
        "inquiries":
        len(listing.buyers),
        "photos": [{
            "small": photos.public_url(photo, "small"),
            "large": photos.public_url(photo, "large"),
        } for photo in listing.photos]
    }
Esempio n. 3
0
def place_inquiry(listing, buyer, message):
    """
    Control the creation of inquiries for each listing.
    """

    # Block addresses commonly used for posting spam.
    block(is_from_tor())

    # Block users that are banned from Marketplace.
    block(is_banned(buyer))

    # Make sure the user only submits a fixed count at given time.
    principal = [buyer, listing.permalink, request.remote_addr]
    block(is_too_frequent(principal, [(4, 60), (100, 24 * 3600)]))

    # Send a message to the user with a link to edit the listing.
    is_signed_in = signed_in(listing)
    email.send_mail(
        to=listing.seller,
        reply_to=buyer,
        subject=u"Re: Marketplace Listing \"{}\"".format(listing.title),
        html=render_template("email/inquiry.html", **locals()),
        text=render_template("email/inquiry.txt", **locals()),
    )

    # Post to Slack about this listing.
    slack.send_chat(text="Inquiry by {}".format(buyer),
                    username=listing.title,
                    icon_url=(photos.public_url(listing.photos[0], "small")
                              if listing.photos else None))
Esempio n. 4
0
def place_inquiry(listing, buyer, message):
    """
    Control the creation of inquiries for each listing.
    """

    # Block addresses commonly used for posting spam.
    block(is_from_tor())

    # Block users that are banned from Marketplace.
    block(is_banned(buyer))

    # Make sure the user only submits a fixed count at given time.
    principal = [buyer, listing.permalink, request.remote_addr]
    block(is_too_frequent(principal, [(4, 60), (100, 24 * 3600)]))

    # Send a message to the user with a link to edit the listing.
    is_signed_in = signed_in(listing)
    email.send_mail(
        to=listing.seller,
        reply_to=buyer,
        subject=u"Re: Marketplace Listing \"{}\"".format(listing.title),
        html=render_template("email/inquiry.html", **locals()),
        text=render_template("email/inquiry.txt", **locals()),
    )

    # Post to Slack about this listing.
    slack.send_chat(
        text="Inquiry by {}".format(buyer),
        username=listing.title,
        icon_url=(photos.public_url(listing.photos[0], "small")
                    if listing.photos else None)
    )
Esempio n. 5
0
def claim_listing(listing):
    """
    Control the creation of new listings.
    """

    # Block inquiries from non-UChicago email addresses.
    block(not is_campus_address(listing.seller),
        error="Please only post listings with a UChicago email address.")

    # Block addresses commonly used for posting spam.
    block(is_from_tor())

    # Make sure the user only submits a fixed count at given time.
    block(is_too_frequent([listing.permalink], [(1, 24 * 3600)]))
    block(is_too_frequent([request.remote_addr], [(4, 60)]))

    # Send a message to the user with a link to edit the listing.
    is_signed_in = signed_in(listing)
    email.send_mail(
        to=listing.seller,
        subject=u"Marketplace Listing \"{}\"".format(listing.title),
        html=render_template("email/welcome.html", **locals()),
        text=render_template("email/welcome.txt", **locals()),
    )

    # Inform the moderators about the new listing.
    link = url_for("show_listing", permalink=listing.permalink,
                                   key=listing.admin_key, _external=True)
    slack.send_chat(
        text="Posted by {listing.seller} (<{link}|approve>)".format(**locals()),
        username=listing.title,
        icon_url=(photos.public_url(listing.photos[0], "small")
                    if listing.photos else None)
    )
Esempio n. 6
0
    def widget(self, field, **kwargs):
        try:
            kwargs.update(id=field.name, name=field.name)

            if field.data:
                # Display a preview of what's already present, plus a link to
                # reset the input type with JavaScript.
                kwargs.update(type='hidden', value=field.data)
                return HTMLString(self.FILLED_IN.format(
                    attributes=html_params(**kwargs),
                    preview_url=photos.public_url(field.data),
                    id=str(kwargs['id'])
                ))

            else:
                # Display just a file input.
                kwargs.update(type='file')
                return HTMLString(self.UNFILLED.format(
                    attributes=html_params(**kwargs)))
        
        except Exception, e:
            logging.exception(e)
Esempio n. 7
0
    def widget(self, field, **kwargs):
        try:
            kwargs.update(id=field.name, name=field.name)

            if field.data:
                # Display a preview of what's already present, plus a link to
                # reset the input type with JavaScript.
                kwargs.update(type='hidden', value=field.data)
                return HTMLString(self.FILLED_IN.format(
                    attributes=html_params(**kwargs),
                    preview_url=photos.public_url(field.data),
                    id=str(kwargs['id'])
                ))

            else:
                # Display just a file input.
                kwargs.update(type='file')
                return HTMLString(self.UNFILLED.format(
                    attributes=html_params(**kwargs)))
        
        except Exception, e:
            logging.exception(e)
Esempio n. 8
0
def claim_listing(listing):
    """
    Control the creation of new listings.
    """

    # Block inquiries from non-UChicago email addresses.
    block(not is_campus_address(listing.seller),
          error="Please only post listings with a UChicago email address.")

    # Block addresses commonly used for posting spam.
    block(is_from_tor())

    # Make sure the user only submits a fixed count at given time.
    block(is_too_frequent([listing.permalink], [(1, 24 * 3600)]))
    block(is_too_frequent([request.remote_addr], [(4, 60)]))

    # Send a message to the user with a link to edit the listing.
    is_signed_in = signed_in(listing)
    email.send_mail(
        to=listing.seller,
        subject=u"Marketplace Listing \"{}\"".format(listing.title),
        html=render_template("email/welcome.html", **locals()),
        text=render_template("email/welcome.txt", **locals()),
    )

    # Inform the moderators about the new listing.
    link = url_for("show_listing",
                   permalink=listing.permalink,
                   key=listing.admin_key,
                   _external=True)
    slack.send_chat(
        text="Posted by {listing.seller} (<{link}|approve>)".format(
            **locals()),
        username=listing.title,
        icon_url=(photos.public_url(listing.photos[0], "small")
                  if listing.photos else None))