Пример #1
0
class IndexTemplate(template.Element):
    loader = template.XMLString(templateString)

    def __init__(self, name, isAdmin):
        self.name = name
        self.isAdmin = isAdmin


    @template.renderer
    def message(self, request, tag):
        message = "You are {name} and you are {status}."

        if self.name is None:
            name = "unregistered"
        else:
            name = self.name

        if self.isAdmin:
            status = "an administrator. Yay! Congratulations! You did it"
        else:
            status = "not an administrator"

        return tag(message.format(name=name, status=status))


    @template.renderer
    def registrationForm(self, request, tag):
        if self.name is not None:  # Already registered
            return []

        label = template.tags.label("Name:")
        name = template.tags.input(type="text", name="name", id="name")
        submit = template.tags.input(type="submit", value="Register")
        return tag(label, name, submit)
Пример #2
0
 def __init__(self, packages):
     template.Element.__init__(self, template.XMLString(packages_template))
     self._packages = packages