#module: member.py # from pso import parser, form, fields, tags import login from datamodel import Member import datamodel class MemberMixin(tags.DataMixin): KEY= Member.IDKEY DATAMODEL=datamodel def getRecord(self, handler, key): return Member.load(key) class MemberForm(form.Form): def goNext(self, handler, cdata): handler.req().redirect('test.cgi') class NewForm(MemberForm): def submit(self, handler, cdata): data = self.prepareData(handler) member = Member(**data) member.save() #while we are at it lets log the bugger in. login.LoginLogout().logIn(handler, data['memberId']) class EditForm(MemberForm): def submit(self, handler, cdata): data = self.prepareData(handler) member = Member.load(data[Member.IDKEY]) member.update(self.prepareData(handler)) member.save() class NameInput(form.Input, MemberMixin): pass class EmailInput(fields.EmailInput, MemberMixin):pass class StateSelect(fields.StateSelect, MemberMixin):pass class ZipInput(fields.ZipInput, MemberMixin):pass class MemberIdInput(fields.UserIdInput, MemberMixin):pass class PasswordGroup(form.PasswordGroup):pass class PasswordInput(form.PasswordInput, MemberMixin):pass class PasswordConfirmInput(form.PasswordConfirmInput, MemberMixin):pass class Os( form.Options, MemberMixin):pass class OsCheckBox(form.CheckBox, MemberMixin):pass class Spam(form.Options, MemberMixin):pass class SpamRadio(form.Radio, MemberMixin):pass class JoinUpSubmit(form.Submit):pass class MessageTextArea(form.TextArea, MemberMixin):pass class PhotoFile(form.File, MemberMixin): pass class MyAccount(parser.Tag): """ if user is logged in shows welcome with link to edit""" WELCOME="Welcome" def __call__(self, handler, cdata=''): user = login.LoginLogout().getLogin(handler) if user: welcome = self.getAttrs().get('welcome', self.WELCOME) return '%s' % (user, user) return "" class Security(parser.Tag): def __call__(self, handler, cdata): if self.check(handler): return '' # if so do nothing # not authorized or some malicious exception ? bang him to the login page handler.req().redirect('test.cgi?action=login') def check(self, handler): user = login.LoginLogout().getLogin(handler) # check if the user owns the record return user == handler.req().getInput('memberId') class List(tags.List, MemberMixin): def fetch(self, handler, line, pageSize): " must return a list of somethings" return Member.LOADER.fetch() #line=line, pageSize= pageSize) def prepareRow(self, handler, record): " must return a dictionary of fields that will be merged with the cdata" return record ass Photo(MemberMixin, parser.Tag): def __call__(self, handler, cdata): photo = self.record(handler).getPhoto() if photo: return """""" % photo return ''