def approve(self): params = self.request.params id = params['id'] listing = Listings.get_by_id(id) if listing: listing.approved = True listing.declined = False DBSession.flush() body = """<html><head></head><body> <p>Dear %s,<p><br> <p>Your Listing <a href="%s">%s</a> at Nairabricks has just been approved.</p> <p>Yours sincerely,</p> <p>The Happy Nairabricks Info Robot</p> </body> </html> """ % (listing.user.fullname, self.request.route_url( 'property_view', name=listing.name), listing.serial) html_email_sender(self.request, subject="Listing %s Approved" % listing.serial, recipients=listing.user.email, body=body) return dict(isOk=1, message="Listing approved") return dict(isOk=0, message="No such listing")
def all_listing(self): form = Form(self.request) usertypes = userTypes() title = 'Properties for sale and rent in Nigeria' page = int(self.request.params.get('page', 1)) paginator = Listings.get_paginator(self.request, page) pastsales = DBSession.query(Listings).filter(Listings.approved==True).\ filter(Listings.declined==False).filter(Listings.status==False).all() page_url = PageURL_WebOb(self.request) pastsales_paginator = Page(pastsales, page=int(self.request.params.get("page", 1)), items_per_page=5, url=page_url) self.request.response.cache_control.prevent_auto = True return dict(paginator=paginator, find='all', form=FormRenderer(form), usertypes=usertypes, title=title, pastsales_paginator=pastsales_paginator, type='', min_price='', max_price='', state_id='', lga_id='', lgas=[], ptype='', beds='', baths='', area_size='', covered_area='', transaction_type='')
def delete(self): id = self.request.matchdict['id'] listing = Listings.get_by_id(id) if listing: DBSession.delete(listing) DBSession.flush() return HTTPFound(location=self.request.route_url('home')) else: self.request.session.flash("warning; Listing not found") return HTTPFound(location='/')
def markassold(self): params = self.request.params token = params['token'] id = params['id'] price = params['price'] price = str(price[2:]) price = ''.join([i for i in price if i.isdigit()]) if len(price) < 3: return dict(isOk=0, message="Enter price value") listing = Listings.get_by_id(id) if listing and (token == self.request.session.get_csrf_token()): listing.sold_price = price listing.status = False DBSession.flush() return dict(isOk=1, message="Success") return dict(isOk=0, message="No such listing")
def make_premium(self): for r in self.request.params: opts = r params = json.loads(opts) id = params['id'] user_id = params['user_id'] user = Users.get_by_id(user_id) positive = params['positive'] listing = Listings.get_by_id(id) if listing: if int(positive) == 1: #we already have it as premium, remove premium = DBSession.query(Featured_Content).filter( Featured_Content.name == 'Premium').first() premium.featured_properties.remove(listing) DBSession.flush() return dict(isOk=1, message="listing removed from premium") else: active_sub = user.active_subscription if not active_sub: return dict( isOk=0, message="Upgrade your account to feature this listing") premium = DBSession.query(Featured_Content).filter( Featured_Content.name == 'Premium').first() if premium.featured_properties: user_total_premium = 0 for item in premium.featured_properties: if item.user == user: user_total_premium += 1 if user_total_premium < active_sub[ 0].plan.max_premium_listings: premium.featured_properties.append(listing) DBSession.flush() return dict(isOk=1, message="listing given a premium identity") return dict( isOk=0, message= "You have exceeded your allocation. Upgrade for more") premium.featured_properties.append(listing) DBSession.flush() return dict(isOk=1, message="listing given a premium identity") return dict(isOk=0, message="No such listing")
def makefavourites(self): for r in self.request.params: opts = r params = json.loads(opts) listing = Listings.get_by_id(params['id']) positive = params['positive'] if listing: user = self.request.user if int(positive) == 1: user.favourites.remove(listing) DBSession.flush() return dict(isOk=1, message='Property removed from favourite') else: user.favourites.append(listing) DBSession.flush() return dict(isOk=1, message='Property saved') return dict(isOk=0, message="Please try again")
def emailage(request): camefrom = request.params.get('camefrom') listing = Listings.get_by_name(camefrom) form = Form(request, schema=MailAgentSchema) if 'submit' in request.POST and form.validate(): receiver = listing.user.email name = form.data['fullname'] phone = form.data['mobile'] email = form.data['email'] sender = "%s via nairabricks.com <*****@*****.**>" % name subject = "Contact Request from %s via nairabricks.com" % name content = "<p>I am Interested in your listing at nairabricks.com. I will like to know more about %s in %s. Please get in touch with me</p>" % ( listing.title, listing.address) footer = "<small>Phone: %s</small>" % phone + "<br/>" msg_body = "<html><head><title>"+subject+"</title></head><body>"+\ "Concerning listing Number %s"%listing.serial +\ "<br/>%s <br/>%s"%(content,footer)+\ "</body></html>" extra_headers = {"Reply-To": '%s <%s>' % (name, email)} html_email_sender(request, recipients=receiver, subject=subject, body=msg_body, sender=sender, extra_headers=extra_headers) if request.is_xhr: html = """<div class="alert alert-success alert-dismissable col-xs-12"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> Email Sent </div>""" return Response(html) request.session.flash("success; Email sent") return HTTPFound( location=request.route_url('property_view', name=camefrom)) if request.is_xhr: html = """<div class="alert alert-success alert-dismissable col-xs-12"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> Email not sent </div>""" return Response(html) request.session.flash("danger; Email not sent") return HTTPFound( location=request.route_url('property_view', name=camefrom))
def view_p(self): name = self.request.matchdict['name'] listing = Listings.get_by_name(name) if not listing: self.request.session.flash('warning; Listing not found') return HTTPFound(location=self.request.route_url('home')) form = Form(self.request) files = listing.pictures.all() #city = DBSession.query(Locality).filter(Locality.state_id==listing.state_id).\ # filter(Locality.city_name==listing.city).first() category = listing.property_extra ''' receiver = listing.user.email body = """ <html><head></head><body> <p>Dear %s,<p><br> <p>A user at Nairabricks viewed your property <a href="%s">%s</a> just now.</p> <p>Yours sincerely,</p> <p>The Happy Nairabricks Info Robot</p> </body> </html> """%(listing.user.fullname,self.request.route_url('property_view',name=name),listing.serial) if not self.request.user==listing.user: html_email_sender(self.request, subject = "Property Clicks", recipients=receiver, body = body ) ''' view_log = Content_Stat(content_id=listing.id, views=1) DBSession.add(view_log) DBSession.flush() return dict(files=files, title=listing.title, form=FormRenderer(form), category=category, listing=listing #, locality=city )
def decline(self): params = self.request.params id = params['id'] listing = Listings.get_by_id(id) if listing: listing.declined = True listing.approved = False DBSession.flush() body = """<html><head></head><body> <p>Dear %s,<p><br> <p>Your Listing <a href="%s">%s</a> at Nairabricks has just been declined.</p> <p>This might be because of any of the following:</p> <ul> <li>Inaccurate Price</li> <li>Incomplete Address</li> <li>Property Description</li> <li>Duplicate Property</li> <li>Lack of basic user profile details e.g profile picture, address etc</li> <li>it has a logo watermark from another website.</li> </ul> <p>Update your listing so that it can be approved</p> <p>Yours sincerely,</p> <p>The Happy Nairabricks Info Robot</p> </body> </html> """ % (listing.user.fullname, self.request.route_url( 'property_view', name=listing.name), listing.serial) html_email_sender(self.request, subject="Listing %s Declined" % listing.serial, recipients=listing.user.email, body=body) return dict(isOk=1, message="Declined") return dict(isOk=0, message="No such listing")