Ejemplo n.º 1
0
 def render(self, template_name=None, **kwds):
     if template_name is None:
         if not hasattr(self, 'template'):
             self.template = '%s/%s.htm' % (
                 self.__module__.replace('.', '/'),
                 lower_name(self.__class__.__name__)
             )
         template_name = self.template
     current_user = self.current_user
     kwds['current_user'] = current_user
     kwds['request'] = self.request
     kwds['this'] = self
     kwds['xsrf'] = self.xsrf_form_html()
     #kwds.update(RENDER_KWDS)
     mytemplate = MYLOOKUP.get_template(template_name)
     content = mytemplate.render(**kwds)
     if not self._finished:
         self.finish(content) 
Ejemplo n.º 2
0
    def __new__(cls, name, bases, attrs):
        #print "init",name
        if name == 'Model' :
            return super(ModelBase, cls).__new__(cls, name, bases, attrs)

        new_class = type.__new__(cls, name, bases, attrs)

        if not getattr(new_class, 'Meta', None):
            class Empty:
                pass
            new_class.Meta = Empty

        if not getattr(new_class.Meta, 'table', None):
            new_class.Meta.table = lower_name(name)
        new_class.Meta.table_safe = escape(new_class.Meta.table)

        # Assume id is the default
        #if not getattr(new_class.Meta, 'pk', None):
        new_class.Meta.pk = 'id'
        # if not getattr(new_class.Meta, 'mc_key', None):
        #     mc_ver = getattr(new_class.Meta, "mc_ver", "")
        #     if mc_ver:
        #         new_class.Meta.mc_key = "%s@%s:%%s"%(name, mc_ver)
        #     else:
        new_class.Meta.mc_key = '%%s$%s'%name

        db = new_class.db = db_by_table(new_class.Meta.table)

        q = db.cursor()
        q.execute('SELECT * FROM %s LIMIT 0' % new_class.Meta.table_safe)
        q.connection.commit()

        new_class._fields = [f[0] for f in q.description]

        cache.add(new_class)
        return new_class