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 listing_category_edit(request): """listing category edit """ title = 'Edit listing category' id = request.matchdict['id'] dbsession = DBSession() category = PropertyCategory.get_by_id(id) if category is None: request.session.flash("warning; Category not found!") return HTTPFound(location=request.route_url("listing_category_list")) form = Form(request, schema=BlogCategoryForm, obj=category) if "form_submitted" in request.POST and form.validate(): form.bind(category) dbsession.add(category) request.session.flash("success;The Category is saved!") return HTTPFound(location=request.route_url("listing_category_list")) action_url = request.route_url("listing_category_edit", id=id) return dict(form=FormRenderer(form), action_url=action_url)
def delete_district(request): dbsession=DBSession() district_id = request.matchdict['district_id'] lga_id = request.matchdict['lga_id'] district = District.get_by_id(district_id) if district is None: request.session.flash('info; No such area') return HTTPFound(location = request.route_url("view_district",lga_id=lga_id)) try: dbsession.delete(district) DBSession.flush() request.session.flash('success; district deleted') return HTTPFound(location = request.route_url("view_lga",lga_id=lga_id)) except IntegrityError: transaction.abort() request.session.flash('info; operation failed') return HTTPFound(location = request.route_url("view_lga",lga_id=lga_id))
def delete_listing_category(request): dbsession = DBSession() id = request.matchdict['id'] category = PropertyCategory.get_by_id(id) if category is None: request.session.flash('danger; No such category ') return HTTPFound(location=request.route_url("listing_category_list")) try: transaction.begin() dbsession.delete(category) transaction.commit() request.session.flash('success; Category deleted') return HTTPFound(location=request.route_url("listing_category_list")) except IntegrityError: transaction.abort() request.session.flash('danger; Unable to delete category') return HTTPFound(location=request.route_url("listing_category_list"))
def search_users(request): dbsession = DBSession() search_term = request.params.get('search', '') searchstring = u'%%%s%%' % search_term title = "Real Estate Professionals" search = dbsession.query(Users).filter( or_(Users.firstname.like(searchstring), Users.surname.like(searchstring), Users.company_name.like(searchstring))).order_by( Users.join_date.desc()).all() page_url = PageURL_WebOb(request) page = int(request.params.get("page", 1)) paginator = Page(search, page=page, items_per_page=12, url=page_url) if page > 1: title = title + ' page ' + str(page) return render_to_response('buddy:templates/user/userlist.mako', dict(paginator=paginator, title=title), request=request)
def add_blog(self): title = "Write a blog post" user = self.request.user if user is None: self.request.session.flash('info; Not signed in, Please sign in') return HTTPFound(location=self.request.route_url('login')) if not self.request.user.email_verified: return HTTPFound( location=self.request.route_url('confirm_mail_holder')) dbsession = DBSession() from deform.widget import OptGroup def get_categories_inside(): p = DBSession.query(BlogCategory).all() c = [] for category in p: if category.children: g = [category.name] d = [(child.id, child.name) for child in category.children] for i in d: g.append(i) c.append(OptGroup(*tuple(g))) return c choices = tuple(get_categories_inside()) class BlogSchema(CSRFSchema): title = colander.SchemaNode(colander.String(), title="Title of blog post", widget=deform.widget.TextInputWidget( css_class="form-control required")) category_id = colander.SchemaNode( colander.Set(), title="Categorize your blog post", widget=deform.widget.SelectWidget(values=choices, multiple=True, css_class="required")) body = colander.SchemaNode(colander.String(), title="Body", widget=deform.widget.TextAreaWidget( css_class="required", id="editor", rows="10")) #state_id = colander.SchemaNode( # colander.String(), # title = "State", # missing=u'', # widget = deform.widget.SelectWidget(values=get_states(), # css_class="required") # ) # city = colander.SchemaNode( # colander.String(), # title = "City", # missing=u'', # widget = deform.widget.TextInputWidget(css_class="required") # ) def validator(form, value): if len(value['category_id']) > 8: exc = colander.Invalid(form, 'Categories must be less than 8') exc['category_id'] = 'Categories must be less than 8' raise exc button = deform.Button(name="submit", title="Publish", css_class="btn btn-primary pull-right") button2 = deform.Button(name="draft", title="Save as Draft", css_class="btn btn-warning pull-left") schema = BlogSchema(validator=validator).bind(request=self.request) rform = deform.Form(schema, buttons=(button, button2), bootstrap_form_style='form-horizontal') form = rform.render() if 'submit' in self.request.POST: controls = self.request.POST.items() # get the form controls try: appstruct = rform.validate(controls) # call validate except deform.ValidationFailure, e: return {'form': e.render(), 'title': title} blog = Blogs( user=self.request.user, name=urlify_name(appstruct['title']), title=appstruct['title'], body=appstruct['body'] #state_id = appstruct['state_id'] #city = appstruct['city'] ) for category in appstruct['category_id']: t = DBSession.query(BlogCategory).get(category) blog.categories.append(t) blog.status = True dbsession.add(blog) #non_html_email_sender( # self.request, # recipients=["*****@*****.**"], # subject="Blog post added on site", # body="A user published a blog right now" #) dbsession.flush() return HTTPFound( location=self.request.route_url('blog_view', name=blog.name))