def toHTML(self, input=None): self.sort() model = {} bv = BoxView(self) for k in bv.keys(): model[k] = bv[k] model["stories"] = [ BoxView(s) for s in [o for o in self.stories if o.status != 'draft'][:NUM_ON_FRONTPAGE] ] return zebra.fetch(self.template, model)
def act_welcome(self): try: a, u = self.fetchUserAndAccount() except: return self.model.update(BoxView(a)) self.model.update(BoxView(u)) self.model["shortname"] = u.server.shortname self.model["message"] = zebra.fetch("eml_welcome", self.model) self.model["subject"] = "Welcome to Cornerhost!" self.model["bcc"] = "*****@*****.**" print >> self, zebra.fetch("frm_mailer", self.model)
def invoke(self, _clerk): signups = _clerk.match(Signup) def byDate(a, b): return cmp(a.TS, b.TS) signups.sort(byDate) return Model(signups=[BoxView(p) for p in signups])
def studyChannel(self, channelID): assert channelID, "must supply valid channelID" chan = self.clerk.fetch(Channel, channelID) self.model["categories"] = [(c.ID, c.name) for c in chan.categories] # @TODO: will need to limit number of past stories soon. self.model["stories"] = [BoxView(s) for s in chan.stories] self.model["stories"].sort(lambda a, b: -cmp(a["posted"], b["posted"])) return chan
class SignupApp(App): userClass = User tplDir = "." def __init__(self, input, clerk, auth): raise Exception( "this class sucks. don't use it. see the 'signup' lib, or refactor this mess" ) self.clerk = clerk self.auth = auth super(SignupApp, self).__init__(input) def act_(self): self.do("signup") def enter(self): self.errors = [] ## signup process ################################## ## signup --> save def act_signup(self): if self.input.get("action") != "save": self.consult(BoxView(userClass())) print >> self.out, zebra.fetch(self.tplDir + "/frm_signup", self.model) def act_save(self): try: raise Exception("this should work like adminapp...ugh") #obj = self.clerk.upsert(self.userClass, # self.input.get("ID"), # **self.input) except ValueError, err: #@TODO: clean up the type mess on ValueError if type(err) == type([]): self.complain(err[0]) else: self.complain(err.args[0]) if self.errors: # complain: self.consult(BoxView(obj)) self.consult(self.input) self.model["ID"] = obj.ID # security measure, just in case.. self.next = "signup" else: # now log in as that user: self.auth.login(obj.ID) self.next = "on_signup"
def act_sendpass(self): try: user = self.userClass(email=self.input["email"]) except: self.complain(''' The email address, <b>%s</b>, wasn\'t found in our database.<br> You can <a href="user.py?action=signup">create a new account</a>,<br> or you can try a different email address below. ''' % weblib.request["email"]) self.next = "requestpass" else: self.consult(BoxView(user)) msg = zebra.fetch("eml_sendpass", self.model) zikebase.sendmail(msg) self.msg_sentpass()
def list_channel(self): channels = [BoxView(c) for c in self.clerk.match(Channel)] self.generic_list(channels, "lst_channel")
def list_comments(self): self.generic_list([BoxView(c) for c in self.clerk.match(Comment)], "lst_comment")
def list_author(self): authors = [BoxView(a) for a in self.clerk.match(Author)] self.generic_list(authors, "lst_author")
def show_channel(self): chan = self.clerk.fetch(Channel, long(self.input["ID"])) model = {"errors": []} model.update(BoxView(chan)) self.write(zebra.fetch("sho_channel", model))
def toAtom(self): self.sort() return zebra.fetch("atom.zb", BoxView(self))
def act_signup(self): if self.input.get("action") != "save": self.consult(BoxView(userClass())) print >> self.out, zebra.fetch(self.tplDir + "/frm_signup", self.model)
def act_update(self): self.auth.check() self.consult(BoxView(self.auth.user)) import os print >> self.out, zebra.fetch(self.tplDir + "/frm_update", self.model)
def invoke(self, _clerk, ID): p = _clerk.fetch(Signup, ID=ID) return Model(signup=BoxView(p))
def toRSS(self): self.sort() return zebra.fetch("rss", BoxView(self))
def _showObject(self, obj, template): self.consult(BoxView(obj)) self.consult(self.input) # so we can pre-populate via url self._runZebra(template)
def invoke(self, _clerk): return Model(servers=[ BoxView(s) for s in _clerk.match(Server, status="active") ])