def ratings(self): form = Form(self.request, schema=UserRatingSchema) prefix = self.request.matchdict['prefix'] user = Users.get_by_path(prefix) title = 'Rate ' + user.fullname if 'form_submitted' in self.request.POST and form.validate(): if user.id == self.request.user.id: self.request.session.flash("danger; You can't rate yourself") return HTTPFound( location=self.request.route_url('profile', prefix=prefix)) if user.rating: for rating in user.rating: if rating.rater_id == self.request.user.id: self.request.session.flash( "warning; You have rated %s before" % user.fullname) return HTTPFound(location=self.request.route_url( 'profile', prefix=prefix)) rating = UserRating(rater_id=self.request.user.id, rated_id=user.id, rating=form.data['rating'], review=form.data['review']) DBSession.add(rating) DBSession.flush() self.request.session.flash("success; Success") return HTTPFound( location=self.request.route_url('profile', prefix=prefix)) self.request.session.flash("danger; An Error occured") return HTTPFound( location=self.request.route_url('profile', prefix=prefix))
def userblogfilter(self): path = self.request.matchdict['prefix'] form = Form(self.request) #id = self.request.matchdict['id'] category = self.request.matchdict['category'] user = Users.get_by_path(path) blogs = user.content.filter(Content.type == 'blog').filter( Blogs.categories.any(name=category)).all() bcategor = user.content.filter(Content.type == 'blog').filter( Blogs.user_id == user.id).all() bc = [s.categories for s in bcategor] bc = histogram(bc) title = user.fullname + "'s Blogs on " + category page_url = PageURL_WebOb(self.request) page = int(self.request.params.get('page', 1)) paginator = Page(blogs, page=page, url=page_url) if page > 1: title = title + ' page ' + str(page) return dict(user=user, paginator=paginator, blog_nav_cat=get_navcategories(), form=FormRenderer(form), bl='bl', category=category, title=title, bcategories=bc)
def user_listing(self): form = Form(self.request) path = self.request.matchdict['prefix'] user = Users.get_by_path(path) page = int(self.request.params.get("page", 1)) page_url = PageURL_WebOb(self.request) active_listings = DBSession.query(Listings).filter(Listings.user == user).filter(Listings.approved==True).\ filter(Listings.declined==False).filter(Listings.status==True).all() past_sales = DBSession.query(Listings).filter( Listings.user == user).filter(Listings.status == False).all() active_paginator = Page(active_listings, page=int(self.request.params.get("page", 1)), items_per_page=10, url=page_url) pastsales_paginator = Page(past_sales, page=int(self.request.params.get("page", 1)), items_per_page=10, url=page_url) title = user.fullname + "'s Listings" return dict(user=user, pastsales_paginator=pastsales_paginator, lis="d", form=FormRenderer(form), active_paginator=active_paginator, title=title)
def denyverify(request): prefix = request.matchdict['prefix'] user = Users.get_by_path(prefix) if not user: request.session.flash('danger; user not found') user.is_verified = False request.session.flash('success; user verification denied') return HTTPFound(location=request.route_url('user_list'))
def delete(self): prefix = self.request.matchdict['prefix'] user = Users.get_by_path(prefix) if user: DBSession.delete(user) DBSession.flush() return HTTPFound(location=self.request.route_url('home')) else: self.request.session.flash("warning; User not found") return HTTPFound(location='/')
def verify(request): prefix = request.matchdict['prefix'] user = Users.get_by_path(prefix) if not user: request.session.flash('danger; user not found') user.is_verified = True user_parent = user.parent silver_plan = DBSession.query(Plans).filter(Plans.name == 'Silver').first() if user_parent: if not user_parent.earned_benefit: if user.active_subscription: active_sub = user.active_subscription[0] subscription = Subscription(user=user, plan=silver_plan, amount=0, no_of_months=1, discount=u"100%", status=u"Active") subscription.start_date = active_sub.end_date subscription.end_date = active_sub.end_date + timedelta( days=30) else: subscription = Subscription(user=request.user, plan=silver_plan, amount=0, no_of_months=1, discount=u"100%", start_date=datetime.today(), end_date=datetime.today() + timedelta(days=30), status=u"Active") DBSession.add(subscription) DBSession.flush() body = """<html><head><title>Verified on nairabricks.com</title></head><body> <p>Dear %s,<p><br> <p>You are now verified as a professional in Nairabricks</p> <p>However, please note that we still have the right to decline your listings if they violate our property listing policy</p> <p>Moreso, ensure that your listings are not duplicated. Instead of having duplicate listings, update your listing frequently to keep it at the top</p> <p>Yours sincerely,</p> <p>The Happy Nairabricks Info Robot</p> </body> </html> """ % user.fullname html_email_sender(request, subject="Congratulations", recipients=user.email, body=body) request.session.flash('success; user verified') return HTTPFound(location=request.route_url('user_list'))
def userblog(self): path = self.request.matchdict['prefix'] user = Users.get_by_path(path) blogs = DBSession.query(Blogs).filter(Blogs.user == user).filter( Blogs.status == True).all() form = Form(self.request) title = user.fullname + "'s Blogs" page_url = PageURL_WebOb(self.request) page = int(self.request.params.get('page', 1)) paginator = Page(blogs, page=page, url=page_url) return dict(user=user, paginator=paginator, form=FormRenderer(form), bl='bl', title=title)
def user_favourites(self): path = self.request.matchdict['prefix'] user = Users.get_by_path(path) form = Form(self.request) listings = user.favourites title = "%s Saved Properties" % user.fullname page_url = PageURL_WebOb(self.request) page = int(self.request.params.get("page", 1)) paginator = Page(listings, page=page, items_per_page=10, url=page_url) return dict(user=user, paginator=paginator, form=FormRenderer(form), saved='saved', title=title)
def profile(self): form = Form(self.request) prefix = self.request.matchdict['prefix'] user = Users.get_by_path(prefix) if not user: self.session.flash('warning; No user with the given profile') return HTTPFound(location='/') total_sales = DBSession.query(Listings).filter_by(user=user).filter( Listings.status == False).count() title = user.fullname + "'s" + " profile" return dict(user=user, form=FormRenderer(form), title=title, total_sales=total_sales, profile_page="profile_page")
def ratingsandreview(self): prefix = self.request.matchdict['prefix'] form = Form(self.request) user = Users.get_by_path(prefix) title = user.fullname + "'s" + " Ratings and Reviews" ratings = user.rating page_url = PageURL_WebOb(self.request) paginator = Page(ratings, page=int(self.request.params.get("page", 1)), items_per_page=5, url=page_url) return dict(paginator=paginator, user=user, rv='rv', title=title, form=FormRenderer(form), rating_page="rating_page")
def userdraft(self): path = self.request.matchdict['prefix'] user = Users.get_by_path(path) blogs = DBSession.query(Blogs).filter(Blogs.user == user).filter( Blogs.status == False).all() bc = [s.categories for s in blogs if s.status == 0] bc = histogram(bc) form = Form(self.request) title = 'Drafts' page_url = PageURL_WebOb(self.request) page = int(self.request.params.get('page', 1)) paginator = Page(blogs, page=page, url=page_url) if page > 1: title = title + ' page ' + str(page) return dict(user=user, paginator=paginator, bl='bl', form=FormRenderer(form), title=title, bcategories=bc)
def contactAgent(self): form = Form(self.request, schema=ContactSchema) prefix = self.request.matchdict['prefix'] user = Users.get_by_path(prefix) if not user: self.session.flash('warning; No such user') return HTTPFound(location='/') if 'form_submitted' in self.request.POST and form.validate(): receiver = user.email fullname = form.data['fullname'] phone = form.data['mobile'] email = form.data['email'] body = form.data['body'] footer = "Reply this email to contact the sender" msg_body = "%s is requesting to contact you through nairabricks.com\r\n"%fullname +\ "Name: %s \n"%fullname+\ "Phone: %s\n"%phone+\ "Message: %s\n"%body+\ "%s"%footer sender = "%s via nairabricks.com <*****@*****.**>" % fullname extra_headers = { 'Reply-To': '{name} <{sender}>'.format(**{ 'name': fullname, 'sender': email }), } subject = "Contact request from %s via nairabricks.com" % fullname non_html_email_sender(self.request, recipients=receiver, subject=subject, body=msg_body, sender=sender, extra_headers=extra_headers) self.request.session.flash("success; Email sent") return HTTPFound( location=self.request.route_url('profile', prefix=prefix)) self.request.session.flash("success; Email not sent") return HTTPFound( location=self.request.route_url('profile', prefix=prefix))
def is_unique(path): url = Users.get_by_path(path) if url: return False return True