def from_region(request): region_id = request.matchdict['region_id'] lga = LGA.get_by_id(region_id) listings=DBSession.query(Listings).filter(Listings.approved==True)\ .filter(Listings.declined==False).filter(Listings.lga==lga).order_by(Listings.modified.desc()).all() page_url = PageURL_WebOb(request) page = int(request.params.get("page", 1)) paginator = Page(listings, page=page, items_per_page=5, url=page_url) title = "Properties in %s,%s" % (lga.name, lga.state.name) form = Form(request) return dict(title=title, paginator=paginator, lga=lga, form=FormRenderer(form), type='', min_price='', max_price='', state_id=lga.state.id, lga_id=lga.id, lgas=[(a.id, a.name) for a in lga.state.lga.all()], ptype='', beds='', baths='', area_size='', covered_area='', transaction_type='')
def viewlga(request): lga_id = request.matchdict['lga_id'] lga = LGA.get_by_id(lga_id) title="Viewing %s" %(lga.name) return dict( title=title, lga=lga, state = lga.state )
def adddistrict(request): title="Add district to LGA" lga_id = request.matchdict['lga_id'] lga = LGA.get_by_id(lga_id) form = Form(request, schema=StateSchema) if 'form_submitted' in request.POST and form.validate(): district_string = form.data['name'] district=District.create_district(lga_id,district_string) request.session.flash("success; District(s) added") return HTTPFound(location=request.route_url('view_lga', lga_id=lga_id)) action_url = request.route_url('add_district',lga_id=lga_id) return dict( title=title, lga=lga, form=FormRenderer(form), action_url=action_url)
def delete_lga(request): dbsession=DBSession() lga_id = request.matchdict['lga_id'] state_id = request.matchdict['state_id'] lga = LGA.get_by_id(lga_id) if lga is None: request.session.flash('info; No such LGA') return HTTPFound(location = request.route_url("view_state",state_id=state_id)) try: dbsession.delete(lga) request.session.flash('success; LGA deleted') return HTTPFound(location = request.route_url("view_state",state_id=state_id)) except IntegrityError: transaction.abort() request.session.flash('info; operation failed') return HTTPFound(location = request.route_url("view_state",state_id=state_id))
def addlga(request): title="Add Local Government Areas" state_id = request.matchdict['state_id'] state = State.get_by_id(state_id) form = Form(request, schema=StateSchema) if 'form_submitted' in request.POST and form.validate(): lga_string = form.data['name'] lga=LGA.create_lga(state_id,lga_string) request.session.flash("success; Lga added") return HTTPFound(location=request.route_url('view_state', state_id=state_id)) action_url = request.route_url('add_lga', state_id=state_id) return dict( title=title, state=state, form=FormRenderer(form), action_url=action_url)
def editlga(request): lga_id = request.matchdict['lga_id'] state_id = request.matchdict['state_id'] state=State.get_by_id(state_id) lga =LGA.get_by_id(lga_id) title = "Editing %s" %(lga.name) form = Form(request, schema=StateSchema) if 'form_submitted' in request.POST and form.validate(): s_string = form.data['name'] lga.name = s_string lga.state_id = state_id DBSession.flush() request.session.flash("success; LGA updated") return HTTPFound(location=request.route_url('view_state', state_id=state_id)) action_url = request.route_url('edit_lga',lga_id=lga_id, state_id=state_id) return dict( title=title, state=state, form=FormRenderer(form), lga=lga, action_url=action_url)
def editdistrict(request): district_id = request.matchdict['district_id'] lga_id = request.matchdict['lga_id'] lga = LGA.get_by_id(lga_id) district =District.get_by_id(district_id) title = "Editing %s" %(district.name) form = Form(request, schema=StateSchema) if 'form_submitted' in request.POST and form.validate(): s_string = form.data['name'] district.name = s_string district.lga_id = lga_id DBSession.flush() request.session.flash("success; District updated") return HTTPFound(location=request.route_url('view_lga',lga_id=lga_id)) action_url = request.route_url('edit_district',district_id=district_id,lga_id=lga_id) return dict( form=FormRenderer(form), district=district, lga=lga, title=title, action_url=action_url)
def search_prop(self): form = Form(self.request) params = self.request.params type = params.get('type') no = params.get('listing_no') state_id = params.get('state_id') lga_id = params.get('lga_id') ptype = params.get('property_type') min_price = params.get('min_price') max_price = params.get('max_price') beds = params.get('beds') baths = params.get('baths') area_size = params.get('area_size') covered_area = params.get('covered_area') transaction_type = params.get('transaction_type') listings = DBSession.query(Listings).join(Property_extras).filter(Listings.approved==True)\ .filter(Listings.declined==False).filter(Listings.status==True) if no: listing = DBSession.query(Listings).filter_by(serial=no).filter(Listings.approved==True)\ .filter(Listings.declined==False).first() if listing: return HTTPFound(location=self.request.route_url( 'property_view', name=listing.name)) title = "Search for listing no: %s" % no return dict(paginator=None, title=title, total=0, form=FormRenderer(form)) if type.lower() == 'for sale': title = 'Find properties for sale in Nigeria' listings = listings.filter(Listings.listing_type == "For sale") elif type.lower() == 'for rent': for_rent = "For rent" title = 'Find properties for rent in Nigeria' listings = listings.filter(Listings.listing_type == for_rent) elif type.lower() == 'short let': short_let = "Short let" title = 'Find properties for short let in Nigeria' listings = listings.filter(Listings.listing_type == short_let) else: title = "Properties in Nigeria" lgas = [] if state_id: state = State.get_by_id(state_id) lgas = [(a.id, a.name) for a in state.lga.all()] listings = listings.filter(Listings.state_id == state_id) if type.lower() == 'for sale': title = "Properties for sale in %s" % state.name elif type.lower() == 'for rent': title = "Properties for rent in %s" % state.name elif type.lower() == 'short let': title = "Properties for short let in %s" % state.name else: title = "Properties in %s" % state.name if lga_id: lga = LGA.get_by_id(lga_id) listings = listings.filter(Listings.lga_id == lga_id) if type.lower() == 'for sale': title = "Properties for sale in %s,%s" % (lga.name, lga.state.name) elif type.lower() == 'for rent': title = "Properties for rent in %s,%s" % (lga.name, lga.state.name) elif type.lower() == 'short let': title = "Properties for short let in %s,%s" % (lga.name, lga.state.name) else: title = "Properties in %s,%s" % (lga.name, lga.state.name) if ptype: category = PropertyCategory.get_by_id(ptype) listings = listings.filter(Listings.category_id == ptype) if lga_id: lga = LGA.get_by_id(lga_id) if type.lower() == 'for sale': title = "%s for sale in %s,%s" % (category.name, lga.name, lga.state.name) elif type.lower() == 'for rent': title = "%s for rent in %s,%s" % (category.name, lga.name, lga.state.name) elif type.lower() == 'short let': title = "%s for short let in %s,%s" % ( category.name, lga.name, lga.state.name) else: title = "%s in %s,%s" % (category.name, lga.name, lga.state.name) elif state_id: state = State.get_by_id(state_id) if type.lower() == 'for sale': title = "%s for sale in %s" % (category.name, state.name) elif type.lower() == 'for rent': title = "%s for rent in %s" % (category.name, state.name) elif type.lower() == 'short let': title = "%s for short let in %s" % (category.name, state.name) else: title = "%s in %s" % (category.name, state.name) if min_price: value = str(min_price[2:]) value = ''.join([i for i in value if i.isdigit()]) listings = listings.filter(Listings.price >= int(value)) if max_price: value = str(max_price[2:]) value = ''.join([i for i in value if i.isdigit()]) listings = listings.filter(Listings.price <= int(value)) if beds: listings = listings.filter(Property_extras.bedroom >= beds) if baths: listings = listings.filter(Property_extras.bathroom >= baths) if area_size: listings = listings.filter(Property_extras.area_size >= area_size) if covered_area: listings = listings.filter( Property_extras.covered_area >= covered_area) if transaction_type: listings = listings.filter( Listings.transaction_type == transaction_type) premium = listings.filter(Listings.featured).all() if not premium: premium = [] listings = listings.order_by(Listings.modified.desc()).all() listings = [i for i in listings if i not in premium] listings = premium + listings page = int(self.request.params.get("page", 1)) page_url = PageURL_WebOb(self.request) paginator = Page(listings, page=page, item_count=len(listings), items_per_page=10, url=page_url) return dict(paginator=paginator, form=FormRenderer(form), title=title, total=len(listings), type=type, min_price=min_price, max_price=max_price, state_id=state_id, lga_id=lga_id, lgas=lgas, ptype=ptype, beds=beds, baths=baths, area_size=area_size, covered_area=covered_area, transaction_type=transaction_type)