def help(self,id = 0): if id > 0: c.item = Site.get(-1,id) c.base_url = config['demisauce.url'] else: c.item = Site.get(-1,c.user.site_id) return render('/help/help.html')
def help(self, id=0): if id > 0: c.item = Site.get(-1, id) c.base_url = config["demisauce.url"] else: c.item = Site.get(-1, self.user.site_id) self.render("/help/help.html")
def view(self,id = 0): if id > 0 and (c.user is not None) and c.user.issysadmin: c.item = Site.saget(id) elif id is None or id == '' and c.user: c.item = Site.get(-1,c.user.site_id) else: c.item = Site.get(-1,id) if not c.item.public: c.item = None return render('/site/site.html')
def view(self, id=0): id = int(id) if id is not None else 0 log.debug("in site view id= %s" % (id)) if id > 0 and (self.user is not None) and self.user.issysadmin: item = Site.saget(id) elif self.user and ((id is None or id == 0) or (self.user.site_id == id)): item = Site.get(-1, self.user.site_id) else: item = Site.get(-1, id) if not item.public: item = None self.render("site/site.html", viewing_user=self.user, item=item)
def action_get_object(self,id, data_dict = {}): if self.site.is_sysadmin == True or (self.site.id == self.id or self.site.slug == self.id): if type(id) == int and id > 0: self.object = Site.saget(id) elif type(id) == int and id == 0 and 'slug' in data_dict: log.debug("they asked for id = 0, lets ignore and doublecheck slug = %s" % data_dict['slug']) self.object = Site.by_slug(data_dict['slug']) else: log.debug("they asked for id = %s, lets ignore and doublecheck slug" % (self.id)) self.object = Site.by_slug(self.id) if self.object: self.qry = [self.object] else: self.set_status(404) log.error("no site %s, status=%s" % (self.id, self._status_code))
def edit_POST(self,id = 0): """ User has selected to change site config info """ if 'objectid' in request.params: site = Site.get(-1,request.params['objectid']) if site is None: h.add_error("We experienced an error, please try again") else: site.name = self.form_result['name'] site.description = self.form_result['description'] site.email = self.form_result['email'] site.slug = self.form_result['real_permalink'] # TODO, check uniqueness site.public = bool(self.form_result['public']) site.base_url = self.form_result['base_url'] site.site_url = self.form_result['site_url'] site.save() # refresh session store user = Person.get(c.user.site_id,c.user.id) self.start_session(user) h.add_alert("Site settings were updated") else: h.add_error("There was an Error") return redirect_wsave('/site/view')
def feedbackform(self,id=''): site = Site.by_slug(str(id)) if site: c.site = site help = Help(site_id=site.id,email=sanitize(self.form_result['email'])) if c.user: help.set_user_info(c.user) else: if 'authorname' in self.form_result: help.authorname = sanitize(self.form_result['authorname']) if 'blog' in self.form_result: help.blog = sanitize(self.form_result['blog']) if help.blog == "your blog url": help.blog = '' if 'category' in self.form_result: help.category = sanitize(self.form_result['category']) help.url = sanitize(self.form_result['url']) help.content = sanitize(self.form_result['content']) if 'HTTP_X_FORWARDED_FOR' in request.environ: help.ip = request.environ['HTTP_X_FORWARDED_FOR'] elif 'REMOTE_ADDR' in request.environ: help.ip = request.environ['REMOTE_ADDR'] help.save() if 'goto' in request.POST and len(request.POST['goto']) > 5: c.goto_url = request.POST['goto'] return render('/refresh.html') else: c.result = True return render('/help/help_feedback.html') else: log.error('feedback from came in with no site id=%s, params= %s' % (id,request.params)) return render('/help/help_feedback.html')
def edit_POST(self, id=0): """ User has selected to change site config info """ site = Site.get(-1, self.get_argument("id")) form = SiteForm(QueryDict(self.request.arguments)) if form and site and form.validate(): if site is None: self.add_error("We experienced an error, please try again") else: site.name = form.name.data log.debug("description pre sanitize = %s" % form.description.data) site.description = sanitize.sanitize(form.description.data) site.email = form.email.data site.slug = self.get_argument("real_permalink") # TODO, check uniqueness site.public = bool(form.public.data) site.base_url = form.base_url.data site.site_url = form.site_url.data site.save() # refresh session store user = Person.get(self.user.site_id, self.user.id) self.set_current_user(user) self.add_alert("Site settings were updated") else: log.error(form.errors) log.error("There was an Error site=%s form.data%s" % (site, form.data)) self.add_error("There was an Error") return self.render("/site/site_edit.html", item=site, form=form) return self.redirect("/site/view?msg=Site+Updated")
def interest(self,id=0): """ User has selected to enter an email to be on waitinglist """ log.debug(self.request.arguments) form = SignupForm(QueryDict(self.request.arguments)) log.debug(form.data) if 'email' in self.request.arguments and form.validate(): user = meta.DBSession.query(Person).filter_by( email=self.get_argument("email").lower()).first() if user is None: new_email = form.email.data.lower() site = Site(name=new_email,email=new_email) site.save() user = Person(site_id=site.id,email=new_email, displayname=new_email) user.slug = user.hashedemail user.save() a = Activity(site_id=user.site_id,person_id=user.id,activity='Signup Interest Form') #a.ref_url = 'comment url' a.ip = self.request.remote_ip a.category = 'account' a.save() link = '%s/user/verify?unique=%s&node=%s&return_url=%s' %\ (options.base_url, user.user_uniqueid, user.id, urllib.quote_plus('/user/viewh/%s' % (user.hashedemail))) json_dict = { 'emails':[user.email], 'template_name':'thank_you_for_registering_with_demisauce', 'template_data':{ 'link':link, 'displayname':user.displayname, 'email':user.email, 'title':'welcome' } } self.db.gearman_client.do_task(Task("email_send",json.dumps(json_dict), background=True)) self.add_alert("Thank You!") self.redirect("/") return self.render('/user/signup.html',form=form)
def submitfeedback(self,id): site = Site.by_slug(str(id)) if site: c.site_slug = site.slug if 'url' in request.params: c.current_url = request.params['url'] c.hasheader = True c.isblue = False return render('/help/help_feedback.html')
def feedback(self,id): site = Site.by_slug(str(id)) if site: c.site_slug = site.slug if 'url' in request.params: c.current_url = request.params['url'] c.category = 'help' if 'category' in request.params: c.category = sanitize(request.params['category']) c.isblue = True return render('/help/help_feedback.html')
def handshake(self,id=0): if 'token' in request.params and 'site_slug' in request.params: # start a handshake, to figure out if we know this user. site = Site.by_slug(str(request.params['site_slug'])) if site and site.id > 0: # lookup user? how? expire_seconds = 60*60*24*31 #TODO: verify that url it came from is in site config response.set_cookie('dsu', user.public_token(),path='/', expires=expire_seconds, secure=False) return '' elif 'usertoken' in request.params: pass """
def __before__(self): super(ServiceController, self).__before__() c.app_list = [['','']] self.site = Site.get(-1,c.site_id) self.other = [] if not hasattr(self,'filters'): self.filters = FilterList() request.environ['filters'] = self.filters self.filters.context = 'service' if self.filters.current() == None: self.filters.set(ServiceFilter(name='owner',clauses={'owner':'all'})) if 'filterstatus' in request.params and \ request.params['filterstatus'] == 'refresh': self.filters.set(ServiceFilter(name='owner',clauses={'owner':'all'})) c.filters = self.filters
def edit(self,id=0): log.info('what the heck, in service edit %s' % id) site = Site.get(-1,c.site_id) c.app_list = [['%s' % app.id,app.name] for app in site.apps] if id == 0 or id == None: c.item = App() c.service = Service() log.info('hm, id == 0') else: c.service = Service.get(c.user.site_id,id) if not c.service and not c.user.issysadmin: h.add_alert('No permission to this service') return self.index() elif c.user.issysadmin: c.service = Service.get(-1,id) c.item = c.service.app return render('/service/service_edit.html')
def ratearticle(self,id=''): site = Site.by_slug(str(id)) data = {'success':False} if site and 'resource_id' in request.params: userid = 0 #TODO: add rating_ct to ??? (context? help? cms?) displayname = 'anonymous' if c.user: userid = c.user.id displayname = c.user.displayname rating_val = int(request.params['rating']) r = Rating(userid,'/ds/help/article',rating_val,sanitize(request.params['resource_id']),displayname) r.save() data = {'success':True,'html':r.id} json = simplejson.dumps(data) response.headers['Content-Type'] = 'text/json' return '%s(%s)' % (request.params['jsoncallback'],json)
def appedit(self,id=0): #log.info('what the heck, in edit %s' % id) id = request.POST['app_id'] site = Site.get(-1,c.site_id) if id == 0 or id == None or id == '0': app = App() app.site_id = site.id app.owner_id = c.user.id log.info('hm, id == 0') else: app = App.get(site.id,id) app.slug = sanitize(request.POST['real_permalink2']) app.name = sanitize(request.POST['app_name']) app.authn = sanitize(request.POST['authn']) app.description = sanitize(request.POST['description']) app.base_url = sanitize(request.POST['base_url']) app.save() return app.id
def edit(self,id=0): log.info('what the heck, in service edit id=%s' % id) site = Site.get(-1,self.user.site_id) app_list = [['%s' % app.id,app.name] for app in site.apps] if id == 0 or id == None or id=='': app = App() service = Service() log.info('hm, id == 0') else: service = Service.get(self.user.site_id,id) if not service and not self.user.issysadmin: self.add_alert('No permission to this service') return self.index() elif self.user.issysadmin: service = Service.get(-1,id) if service: app = service.app self.render('/service/service_edit.html',site=site,app_list=app_list, app=app,serviceitem=service)
def appedit(self,id=0): log.info('what the heck, in edit %s' % id) id = self.get_argument("app_id") site = Site.get(-1,self.user.site_id) if id == 0 or id == None or id == '0': app = App() app.site_id = site.id app.owner_id = self.user.id log.info('hm, id == 0') else: app = App.get(site.id,id) log.info('args = %s' % (str(self.request.arguments))) app.slug = sanitize(self.get_argument('real_permalink2')) app.name = sanitize(self.get_argument('app_name')) app.authn = sanitize(self.get_argument('authn')) #if 'description' in self.request.arguments: app.description = sanitize(self.get_argument('description','')) app.base_url = sanitize(self.get_argument('base_url')) app.save() self.write(str(app.id))
def init_user(self): # Need site? ds_id = self.id site_key = self.db.cache.get(str(ds_id)) log.debug("init_user ds_id,site_key = %s = %s" % (ds_id,site_key)) if site_key: site = Site.by_apikey(str(site_key)) if site: user = Person.get(site.id,ds_id) if not user: log.error("user not found? id = %s" % ds_id) else: log.error("no site? %s" % ds_id) self.set_current_user(user,is_authenticated = True) log.debug("tried to init_user succeeded") self.set_status(204) # succuess, no content else: log.error("tried to init_user failed ds_id = %s, url=%s" % (ds_id,self.request.full_url())) self.set_status(400) self.write("{'status':'failure'}")
def commentform(self, id=0): site = Site.by_slug(str(id)) c.source = "js" if site and site.id > 0: c.site_slug = site.slug c.site = site if "source" in request.params: c.source = request.params["source"] c.resource_id = "" if "rid" in request.params: c.resource_id = request.params["rid"] if request.GET.has_key("url"): c.goto_url = request.GET["url"] else: if c.user: c.goto_url = c.user.url else: c.goto_url = "http://www.google.com" else: raise Exception("that site was not found") # c.hasheader = False # c.isblue = True return render("/comment/comment_commentform.html")
def js2(self, id=""): slug = id hash = compute_userhash() # verify that they if hash != None and "url" in request.params: site = Site.by_slug(str(slug)) url = str(request.params["url"]) url = url[: url.find("/", 8)] if site and len(url) > 5 and url in site.site_url: # filter comments for just url being requested c.site = site c.url = str(request.params["url"]) c.items = Comment.for_url(site, request.params["url"]) return render("/comment/comment_js2.js") else: log.error("%s not in site_url" % (url)) else: log.info("not in site_url") return ( """document.getElementById('demisauce-comments').innerHTML = '<a href="%s/">Sorry Go to Demisauce to Comment</a>';""" % c.base_url )
def commentsubmit(self, id=""): site = Site.by_slug(str(id)) if site: c.site = site item = Comment(site_id=site.id) if c.user: item.set_user_info(c.user) a = activity.Activity(site_id=c.user.site_id, person_id=c.user.id, activity="Commenting") # a.ref_url = 'comment url' a.category = "comment" a.save() else: item.authorname = sanitize(self.form_result["authorname"]) item.blog = sanitize(self.form_result["blog"]) if self.form_result.has_key("email"): item.set_email(sanitize(self.form_result["email"])) if item.blog == "your blog url": item.blog = "" # prod environment proxy: apache if "HTTP_X_FORWARDED_FOR" in request.environ: item.ip = request.environ["HTTP_X_FORWARDED_FOR"] elif "REMOTE_ADDR" in request.environ: item.ip = request.environ["REMOTE_ADDR"] item.comment = sanitize(self.form_result["comment"]) if self.form_result.has_key("type"): item.type = sanitize(self.form_result["type"]) else: item.type = "blogentry" if self.form_result.has_key("goto"): dest = self.form_result["goto"] item.uri = dest elif c.user: dest = c.user.url else: # TODO panic? return if "rid" in self.form_result: item.uri = self.form_result["rid"].lower() item.save() # send emails from demisauce.lib import scheduler dnew = { "sitename": c.site.name, "displayname": item.authorname, "email": item.email, "url": dest, "blog": item.blog, } scheduler.add_interval_task(send_emails, 0, ("comment-notification", [c.site.email], dnew), initialdelay=4) # TODO '?#demisauce-comments' c.goto_url = dest c.resource_id = "" if "rid" in self.form_result: c.resource_id = self.form_result["rid"] source = "js" if "source" in self.form_result: source = self.form_result["source"] if "jsoncallback" in request.params: data = {"success": True, "html": item.comment} json = simplejson.dumps(data) response.headers["Content-Type"] = "text/json" return "%s(%s)" % (request.params["jsoncallback"], json) # if source == 'js': # return render('/refresh.html') # else: c.items = [item] # c.show_form = False return render("/comment/comment_nobody.html") else: # TODO panic? raise "eh" pass return
def cmntconfig(self): c.item = Site.get(-1,c.user.site_id) return render('/site/comment.html')
def commentsubmitjsonp(self, id=""): site = Site.by_slug(str(id)) if site: c.site = site item = Comment(site_id=site.id) if c.user: item.set_user_info(c.user) a = activity.Activity(site_id=c.user.site_id, person_id=c.user.id, activity="Commenting") # a.ref_url = 'comment url' a.category = "comment" a.save() else: if "authorname" in request.params: item.authorname = sanitize(request.params["authorname"]) if "blog" in request.params: item.blog = sanitize(request.params["blog"]) if "email" in request.params: item.set_email(sanitize(request.params["email"])) if item.blog == "your blog url": item.blog = "" # prod environment proxy: apache if "HTTP_X_FORWARDED_FOR" in request.environ: item.ip = request.environ["HTTP_X_FORWARDED_FOR"] elif "REMOTE_ADDR" in request.environ: item.ip = request.environ["REMOTE_ADDR"] if "comment" in request.params: item.comment = sanitize(request.params["comment"]) if "type" in request.params: item.type = sanitize(request.params["type"]) else: item.type = "blogentry" if "rid" in request.params: item.uri = urllib.unquote_plus(request.params["rid"].lower()) item.save() # send emails from demisauce.lib import scheduler dnew = { "sitename": c.site.name, "displayname": item.authorname, "email": item.email, "url": "dest", "blog": item.blog, } scheduler.add_interval_task(send_emails, 0, ("comment-notification", [c.site.email], dnew), initialdelay=4) if "jsoncallback" in request.params: c.items = [item] data = {"success": True, "html": render("/comment/comment_nobody.html")} json = simplejson.dumps(data) response.headers["Content-Type"] = "text/json" return "%s(%s)" % (request.params["jsoncallback"], json) else: # TODO panic? raise "eh" pass return
def cmntconfig(self): item = Site.get(-1, self.user.site_id) self.render("/site/comment.html", item=item)