[Flask] Macro expansion/evaluation?

Can Hoşgör canhosgor at gmail.com
Wed Oct 14 21:10:48 CEST 2015


See getattr and/or self.__dict__

14 Ekim 2015 Çarşamba tarihinde, Jim Icenhower via Flask <flask at python.org>
yazdı:

> Hi All,
> I'm sure this is a newbie question but I haven't been able to find the
> answer by searching. Probably because I don't know what this technique is
> called in Python.
> I have created a class which extends the Flask-Appbuilder Model class
> which extends a SQLAlchemy class. I'm trying to validate that all required
> fields are populated. I have created this function that returns all the
> mapped attributes of the class:
>
> def get_obj_mapped_columns(dbObj):
>     mapper = inspect(dbObj)
>     return mapper.mapper.columns
>
> This is my main class:
>
> class Event(Model):
>     EventID = Column(Integer, primary_key=True)
>     EventKey = Column(String(30), unique=True, nullable=False)
>     Name = Column(String(100), nullable=False)
>     Description = Column(Text(1000), nullable=False)
>     BeginDate = Column(Date)
>     EndDate = Column(Date)
>     RegBeginDate = Column(Date)
>     RegEndDate = Column(Date)
>     Location = Column(String(200))
>     Address1 = Column(String(200))
>     Address2 = Column(String(200))
>     City = Column(String(20))
>     State = Column(String(2))
>     Zip = Column(String(10))
>     URL = Column(String(100))
>     Email = Column(String(100))
>     Phone = Column(String(20))
>
> Which contains the following method:
>
>     def isValid(self):
>         columns = get_obj_mapped_columns(self)
>         for column in columns:
>             if (NOT column.nullable):
>                 print column.name
>                 print self.*<column.name <http://column.name>>*
>
>
> I would like to substitute the value in <column.name> in such a way that
> it is evaluated as the field name of the Event object.
>
> Any guidance would be greatly appreciated!
>
> Thanks,
> Jim
>
> Jim
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20151014/25f6a1f4/attachment-0001.html>


More information about the Flask mailing list