Exemplo n.º 1
0
def home():
    form = SearchForm(status=0, tag='allCat', radius=10)
    choices = [("allCat", "All Categories")]
    for c in categoryEnum:
        choices.append((c.name, c.name))
    form.category.choices = choices
    if form.validate_on_submit():
        posts = []
        searchString = form.searchString.data
        if len(searchString) > 0:
            searchString = "%{}%".format(
                searchString)  # Post.author.username.like(searchString)
            posts = db.session.query(Post).join(
                User, User.id == Post.user_id).filter(
                    or_(Post.title.ilike(searchString),
                        Post.description.ilike(searchString),
                        User.username.ilike(searchString)))
        else:
            posts = db.session.query(Post).join(User, User.id == Post.user_id)
        # filter based on status
        if (form.status.data != 'all'):
            posts = posts.filter(
                Post.status == statusEnum._member_map_[form.status.data])
        # filter based on category
        if (form.category.data != 'allCat'):
            posts = posts.filter(
                Post.category == categoryEnum._member_map_[form.category.data])
        # filter based on close by posts

        if form.postalCode.data:
            pcm = postalCodeManager()
            searchUtil = SearchUtil()
            searchRes = searchUtil.get_adv_pc_from_location(form)
            if len(searchRes[1]) > 0:
                flash(searchRes[1], 'warning')
                if searchRes[0] < 0:
                    return render_template('home.html', posts=[], form=form)
            pc = searchRes[0]
            pcm.getNearybyPassCodes(pc, form.radius.data)
            nearby_postal_codes = pcm.getNearybyPassCodes(pc, form.radius.data)
            try:
                posts = posts.filter(
                    or_(*[
                        User.postal_code.ilike(x) for x in nearby_postal_codes
                    ]))
            except:
                pc = searchUtil.DefPostal
        flash("Search Updated!", "success")
        posts = posts.order_by(desc(Post.date_posted)).all()
        return render_template('home.html', posts=posts, form=form)
    else:
        posts = Post.query.order_by(Post.date_posted.desc()).all()
        return render_template('home.html', posts=posts, form=form)
Exemplo n.º 2
0
def NearybyStations():
    if current_user.is_authenticated:
        pcm = postalCodeManager()
        nearby_postal_codes = pcm.getNearybyPassCodes(current_user.postal_code,
                                                      15)
        stations = db.session.query(Dplstations).filter(
            or_(*[
                Dplstations.postal_code.ilike(x) for x in nearby_postal_codes
            ])).all()
        return render_template('PickDPLStation.html',
                               title='Stations',
                               stations=stations)
    else:
        flash('You need to Login first!', 'warning')
        return redirect(url_for('login'))
Exemplo n.º 3
0
 def validate_postal_code(self, postal_code):
     pcm = postalCodeManager()
     pc = postal_code.data.replace(" ", "").upper()
     if not pcm.verifyPostalCode(pc):
         raise ValidationError('That is not a valid Postal Code.')
Exemplo n.º 4
0
 def validate_postal_code(self, postal_code):
     pcm = postalCodeManager()
     if not pcm.verifyPostalCode(postal_code.data):
         raise ValidationError('That is not a valid Postal Code.')