Пример #1
0
    def test_require_login_not_admin(self):
        self.mox.StubOutWithMock(util, 'check_active_requirement')
        util.check_active_requirement().AndReturn(True)

        self.mox.StubOutWithMock(util, 'check_admin_requirement')
        util.check_admin_requirement(True).AndReturn(False)

        self.mox.StubOutWithMock(util, 'redirect_inactive_user')
        util.redirect_inactive_user().AndReturn('redirect_302')

        self.mox.ReplayAll()

        result = function_require_admin()
        self.assertEqual('redirect_302', result)
Пример #2
0
def index_listings_by_slug_programmatic(slug, parent_template, temp_vals, home):
    listings = services.listing_service.list_by_slug(slug)

    slug_split = slug.split("/")
    category = slug_split[0]

    config = tiny_classified.get_config()

    if listings.count() == 0:
        return None

    listing = listings[0]
    is_qualified = services.listing_service.check_is_qualified(listing, slug)

    about = listing.get("about", None)
    if about:
        about = markdown.markdown(about)

    if listings.count() == 1 and is_qualified:
        return flask.render_template(
            "public/listing_chrome.html",
            base_url=config["BASE_URL"],
            parent_template=parent_template,
            listing=listing,
            category=category,
            about=about,
            listing_url_base=tiny_classified.get_config()["LISTING_URL_BASE"],
            admin=util.check_admin_requirement(True),
            **temp_vals
        )
    else:
        tags = listings.distinct("tags")
        tags = services.listing_service.collect_index_dict(tags, home_only=home)

        if len(slug_split) > 1:
            subcategories = []
            selected_subcategory = {"name": slug_split[1]}
        else:
            subcategories = tags[category]
            selected_subcategory = None

        url_base = config["LISTING_URL_BASE"]

        listings = list(listings)
        featured_listings = sorted(filter(lambda x: x.get("featured", False), listings), key=lambda x: x["name"])

        prep = util.prepare_subcategory
        return flask.render_template(
            "public/category_chrome.html",
            base_url=config["BASE_URL"],
            parent_template=parent_template,
            category=category,
            listings=listings,
            featured_listings=featured_listings,
            subcategories=[prep(url_base, category, x) for x in subcategories],
            selected_subcategory=selected_subcategory,
            listing_url_base=url_base,
            **temp_vals
        )
Пример #3
0
def is_admin():
    return util.check_admin_requirement(True)