Exemplo n.º 1
0
def list_product(category_id):
    """Shows listing forms for various categories."""

    # Get all brands in the database to show in the brand drop down.
    all_brands = Brand.query.all()
    # Pre-populate available dates.
    dates = calc_default_dates(30)

    templates = {
        1: 'list-tent.html',
        2: 'list-sleeping-bag.html',
        3: 'list-sleeping-pad.html',
    }

    # If the user wants to list a tent, gets tent-specific spec requests.
    if category_id == 1:
        all_best_uses = BestUse.query.all()
        season_categories = {
            2: "2-season",
            3: "3-season",
            4: "4-season",
            5: "5-season"
        }

        return render_template(templates[category_id],
                               brands=all_brands,
                               submit_route='/handle-listing/%d' % category_id,
                               p_today=dates['today_string'],
                               p_month=dates['future_string'],
                               best_uses=all_best_uses,
                               seasons=season_categories)
    # Similarly, if user wants to list a sleeping bag, get info needed to request
    # sleeping bag-specific specs.
    elif category_id == 2:
        all_fill_types = FillType.query.all()
        all_gender_types = Gender.query.all()

        return render_template(templates[category_id],
                               brands=all_brands,
                               submit_route='/handle-listing/%d' % category_id,
                               p_today=dates['today_string'],
                               p_month=dates['future_string'],
                               fill_types=all_fill_types,
                               genders=all_gender_types)

    # And same thing for sleeping pads. Get specific stuff like pad types to
    # show in the template's drop down.
    elif category_id == 3:
        all_pad_types = PadType.query.all()
        all_best_uses = BestUse.query.all()

        return render_template(templates[category_id],
                               brands=all_brands,
                               submit_route='/handle-listing/%d' % category_id,
                               p_today=dates['today_string'],
                               p_month=dates['future_string'],
                               pad_types=all_pad_types,
                               best_uses=all_best_uses)
    else:
        return "Not yet implemented"
Exemplo n.º 2
0
    def test_calc_default_dates(self, mock_dt):
        expected = {'future': datetime(2015, 12, 18),
                    'today_string': '2015-11-18',
                    'today': datetime(2015, 11, 18),
                    'future_string': '2015-12-18'}

        mock_dt.today.return_value = datetime(2015, 11, 18)
        self.assertEqual(calc_default_dates(30), expected)
Exemplo n.º 3
0
def list_product(category_id):
    """Shows listing forms for various categories."""

    # Get all brands in the database to show in the brand drop down.
    all_brands = Brand.query.all()
    # Pre-populate available dates.
    dates = calc_default_dates(30)

    templates = {1: 'list-tent.html',
                 2: 'list-sleeping-bag.html',
                 3: 'list-sleeping-pad.html',
                 }

    # If the user wants to list a tent, gets tent-specific spec requests.
    if category_id == 1:
        all_best_uses = BestUse.query.all()
        season_categories = {2: "2-season",
                             3: "3-season",
                             4: "4-season",
                             5: "5-season"}

        return render_template(templates[category_id],
                               brands=all_brands,
                               submit_route='/handle-listing/%d' % category_id,
                               p_today=dates['today_string'],
                               p_month=dates['future_string'],
                               best_uses=all_best_uses,
                               seasons=season_categories)
    # Similarly, if user wants to list a sleeping bag, get info needed to request
    # sleeping bag-specific specs.
    elif category_id == 2:
        all_fill_types = FillType.query.all()
        all_gender_types = Gender.query.all()

        return render_template(templates[category_id],
                               brands=all_brands,
                               submit_route='/handle-listing/%d' % category_id,
                               p_today=dates['today_string'],
                               p_month=dates['future_string'],
                               fill_types=all_fill_types,
                               genders=all_gender_types)

     # And same thing for sleeping pads. Get specific stuff like pad types to
     # show in the template's drop down.
    elif category_id == 3:
        all_pad_types = PadType.query.all()
        all_best_uses = BestUse.query.all()

        return render_template(templates[category_id],
                               brands=all_brands,
                               submit_route='/handle-listing/%d' % category_id,
                               p_today=dates['today_string'],
                               p_month=dates['future_string'],
                               pad_types=all_pad_types,
                               best_uses=all_best_uses)
    else:
        return "Not yet implemented"
Exemplo n.º 4
0
def enter_site():
    """Page shown when user successfully logs in or creates an account."""

    customer = User.query.filter(User.email == session['user']).one()
    dates = calc_default_dates(7)

    categories = Category.query.all()
    brands = Brand.query.all()

    return render_template("success.html", user=customer,
                           today=dates['today_string'],
                           future=dates['future_string'],
                           product_categories=categories,
                           product_brands=brands)
Exemplo n.º 5
0
def enter_site():
    """Page shown when user successfully logs in or creates an account."""

    customer = User.query.filter(User.email == session['user']).one()
    dates = calc_default_dates(7)

    categories = Category.query.all()
    brands = Brand.query.all()

    return render_template("success.html",
                           user=customer,
                           today=dates['today_string'],
                           future=dates['future_string'],
                           product_categories=categories,
                           product_brands=brands)