Pastebin
Paste #3156: No description
< previous paste - next paste>
Pasted by Anonymous Coward
------------ matching function: if footwear_type: query.options(joinedload('vendor')) query = query.filter_by(Footwear.product_type==footwear_type) return query ----------- view: return render_template("searchresult.html", result=result, query=query) ------------- model product: class Footwear(Base): __tablename__ = "footwear" id = db.Column(db.Integer, db.Sequence('footwear_id_seq'), primary_key=True) vendor_product_id = db.Column(db.String) vendor_product_id_hash = db.Column(db.String) vendor = db.Column(db.String, db.ForeignKey('vendor.id')) product_name = db.Column(db.String) size_eu = db.Column(db.Numeric(3, 1)) mm_forefoot_height = db.Column(db.Integer, nullable=True) mm_instep_height = db.Column(db.Integer, nullable=True) mm_foot_length = db.Column(db.Integer, nullable=True) mm_forefoot_width = db.Column(db.Integer, nullable=True) mm_heel_width = db.Column(db.Integer, nullable=True) product_image_url = db.Column(db.String) description_en = db.Column(db.Text, nullable=False) description_de = db.Column(db.Text, nullable=True) description_da = db.Column(db.Text, nullable=True) footwear_type = db.Column(db.String, db.ForeignKey('footwear_type.id')) # Valid values are: M=male, F=Female, U=Unisex sex_enums = ('M','F','U') sex = db.Column(db.Enum(*sex_enums, name="sex_enum"), nullable=False) # Valid values are: A=Adult, C=Children age_group_enums = ('A','C') age_group = db.Column(db.Enum(*age_group_enums, name="age_group_enum"), nullable=False) product_url = db.Column(db.String) date_created = db.Column(db.DateTime, default=datetime.datetime.utcnow) def __repr__(self): return "<Footwear(id='%s', vendor='%s', product_name='%s', vendor_product_id='%s', size_eu='%s', mm_forefoot_height='%s', mm_instep_height='%s', mm_foot_length='%s', mm_forefoot_width='%s', mm_heel_width='%s')>" % ( self.id, self.vendor, self.product_name, self.vendor_product_id, self.size_eu, self.mm_forefoot_height, self.mm_instep_height, self.mm_foot_length, self.mm_forefoot_width, self.mm_heel_width ) ------------- model vendor: #!/usr/bin/env python #encoding=utf8 """Vendor model""" from flask_sqlalchemy import SQLAlchemy from model.meta import Base, db class Vendor(Base): __tablename__ = "vendor" id = db.Column(db.String, primary_key=True) name = db.Column(db.String) data_url = db.Column(db.String) data_format = db.Column(db.String) website_url = db.Column(db.String) contact_email = db.Column(db.String) active = db.Column(db.Boolean, default=True) footwear = db.relationship('Footwear', backref=db.backref('footwearvendor')) def __repr__(self): return "<Vendor(id='%s', name='%s', active='%s')>" % (self.id, self.name, self.active) ------------ template: {% extends "base.html" %} {% block content %} <h2>{{ gettext("Matchende fodtøj") }}</h2> <div class="searchquery"> {{ gettext("Nedenfor vises det fodtøj som matcher dine indtastning") }} <div class="debug"> Query: <br /> {% for q in query %} {{ q }}={{ query[q] }} <br /> {% endfor %} </div> </div> <div class="results"> {% if not result.count %} {{ gettext("Vi kunne desværre ikke finde noget fodtøj der matcher din indtastning. Prøv evt. igen senere.") }} {% endif %} {% for footwear in result %} <div class="product_list"> <a href="/product/{{footwear.id}}"><img src="/static/product_images/{{footwear.id}}.jpg" alt="{{footwear.product_name}}" class="thumbnail" /></a> <a href="/product/{{footwear.id}}"> {{footwear.vendor.name}}: {{footwear.product_name}} </a> </div> {% endfor %} </div> {% endblock %}
New Paste
Go to most recent paste.