Beispiel #1
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)
    )
Beispiel #2
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)
    )