Commits

Francisco Souza  committed c4f642e

Definição dos modelos.

  • Participants
  • Parent commits b5e80d2

Comments (0)

Files changed (5)

File pyconference/model/__init__.py

     #                           autoload_with=engine)
     #orm.mapper(Reflected, reflected_table)
     #
-    meta.Session.configure(bind=engine)
+    meta.Session.configure(bind = engine)
     meta.engine = engine
 
+orm.mapper(classes.Conference, tables.conferences)
+
+orm.mapper(classes.PresentationType, tables.presentation_types)
+
+orm.mapper(classes.Presentation, tables.presentations, properties = {
+        'conference' : orm.relation(classes.Conference, backref = 'presentations'),
+        'type' : orm.relation(classes.PresentationType)
+})
+
+orm.mapper(classes.Author, tables.authors, properties = {
+         'presentations' : orm.relation(classes.Presentation, tables.author_presentation, backref = 'authors') 
+})
+
+orm.mapper(classes.Person, tables.people)
+
+orm.mapper(classes.Subscription, tables.subscriptions, properties = {
+        'person' : orm.relation(classes.Person),
+        'presentation' : orm.relation(classes.Presentation, backref = 'subscriptions')
+})
+
 ## Non-reflected tables may be defined and mapped at module level
 #foo_table = sa.Table("Foo", meta.metadata,
 #    sa.Column("id", sa.types.Integer, primary_key=True),

File pyconference/model/classes.py

 
 class Conference(object):
     
-    def __init__(self, id = None, title = None, description = None):
+    def __init__(self,
+                 id = None,
+                 title = None,
+                 description = None,
+                 start_date = None,
+                 end_date = None):
         self.id = id
         self.title = title
         self.description = description
+        self.start_date = start_date
+        self.end_date = end_date
         
     def __unicode__(self):
-        return self.title
+        return self.title
+    
+    __str__ = __unicode__
+    
+class PresentationType(object):
+    
+    def __init__(self,
+                 id = None,
+                 name = None):
+        self.id = id
+        self.name = name
+    
+    def __unicode__(self):
+        return self.name
+    
+    __str__ = __unicode__
+    
+class Presentation(object):
+    
+    def __init__(self,
+                 id = None,
+                 title = None,
+                 description = None,
+                 requirements = None,
+                 time = None,
+                 conference_id = None,
+                 conference_type_id = None):
+        self.id = id
+        self.title = title
+        self.description = description
+        self.requirements = requirements
+        self.time = time
+        self.conference_id = conference_id
+        self.conference_type_id = conference_type_id
+    
+    def __unicode__(self):
+        return self.title
+    
+    __str__ = __unicode__
+    
+class Author(object):
+    
+    def __init__(self,
+                 id = None,
+                 name = None,
+                 title = None,
+                 abstract = None):
+        self.id = id
+        self.name = name
+        self.title = title
+        self.abstract = abstract
+        
+    def __unicode__(self):
+        return self.name
+    
+    __str__ = __unicode__
+    
+class Person(object):
+    
+    def __init__(self,
+                 id = None,
+                 name = None,
+                 email = None,
+                 password = None):
+        self.id = id
+        self.name = name
+        self.email = email
+        self.password = password
+        
+    def __unicode__(self):
+        return '%s %s' % (self.title, self.name)
+    
+    __str__ = __unicode__
+
+class Subscription(object):
+    
+    def __init__(self,
+                 id = None,
+                 subscription_date = None,
+                 presentation_id = None,
+                 person_id = None,
+                 status = None):
+        self.id = id
+        self.subscription_date = subscription_date
+        self.presentation = presentation_id
+        self.person = person_id
+        self.status = status
+        
+    def __unicode__(self):
+        return '<Subscription (\'%s\' on \'%s\')>' % (self.person.name, self.presentation.title)
+    
+    __str__ = __unicode__ 

File pyconference/model/tables.py

 #coding:utf-8
 
 import sqlalchemy as sa
-from sqlalchemy import orm
 
 from pyconference.model import meta
 
-conferences_table = sa.Table('conferences', meta.metadata,
-                             sa.Column('id', sa.types.Integer(), primay_key=True),
-                             sa.Column('title', sa.types.Unicode(100)),
-                             sa.Column('description', sa.types.Unicode(), default='')
-                    )
-presentations_table = sa.Table('presentations', meta.metadata,
-                             sa.Column('id', sa.types.Integer(), primary_key=True),
-                             sa.Column('title', sa.types.UnicodeText()),
-                             sa.Column('description', sa.types.UnicodeText(), default=''),
-                             sa.Column('requirements', sa.types.UnicodeText(), default=''),
-                             
+conferences = sa.Table('conferences', meta.metadata,
+                             sa.Column('id', sa.types.Integer(), primary_key = True),
+                             sa.Column('title', sa.types.Unicode(100), nullable = False),
+                             sa.Column('description', sa.types.Unicode(), nullable = True),
+                             sa.Column('start_date', sa.types.Date(), nullable = True),
+                             sa.Column('end_date', sa.types.Date(), nullable = True)
                     )
 
+presentation_types = sa.Table('presentation_types', meta.metadata,
+                                   sa.Column('id', sa.types.Integer(), primary_key = True),
+                                   sa.Column('name', sa.types.Unicode(255), nullable = False)
+                    )
+
+presentations = sa.Table('presentations', meta.metadata,
+                             sa.Column('id', sa.types.Integer(), primary_key = True),
+                             sa.Column('title', sa.types.UnicodeText(), nullable = False),
+                             sa.Column('description', sa.types.UnicodeText(), nullable = True),
+                             sa.Column('requirements', sa.types.UnicodeText(), nullable = True),
+                             sa.Column('time', sa.types.DateTime(), nullable = True),
+                             sa.Column('conference_id', sa.types.Integer(), nullable = False),
+                             sa.Column('presentation_type_id', sa.types.Integer(), nullable = True),
+                             sa.ForeignKeyConstraint(['conference_id', ], ['conferences.id', ]),
+                             sa.ForeignKeyConstraint(['presentation_type_id', ], ['presentation_types.id', ])
+                    )
+
+authors = sa.Table('authors', meta.metadata,
+                        sa.Column('id', sa.types.Integer(), primary_key = True),
+                        sa.Column('title', sa.types.Unicode(100), nullable = True),
+                        sa.Column('name', sa.types.Unicode(255), nullable = False),
+                        sa.Column('abstract', sa.types.UnicodeText(), nullable = True),
+                    )
+
+author_presentation = sa.Table('autor_presentation', meta.metadata,
+                                     sa.Column('author_id', sa.types.Integer(), primary_key = True),
+                                     sa.Column('presentation_id', sa.types.Integer(), primary_key = True),
+                                     sa.ForeignKeyConstraint(['author_id', ], ['authors.id', ]),
+                                     sa.ForeignKeyConstraint(['presentation_id', ], ['presentations.id', ])
+                    )
+
+people = sa.Table('people', meta.metadata,
+                        sa.Column('id', sa.types.Integer(), primary_key = True),
+                        sa.Column('name', sa.types.Unicode(255), nullable = False),
+                        sa.Column('email', sa.types.Unicode(255), nullable = False),
+                        sa.Column('password', sa.types.Unicode(255), nullable = False),
+                    )
+
+subscriptions = sa.Table('subscriptions', meta.metadata,
+                              sa.Column('id', sa.types.Integer(), primary_key = True),
+                              sa.Column('subscription_date', sa.types.Date(), nullable = False),
+                              sa.Column('person_id', sa.types.Integer(), nullable = False),
+                              sa.Column('presentation_id', sa.types.Integer(), nullable = False),
+                              sa.Column('status', sa.types.Boolean(), nullable = False, default = False),
+                              sa.ForeignKeyConstraint(['person_id', ], ['people.id', ]),
+                              sa.ForeignKeyConstraint(['presentation_id', ], ['presentations.id', ])
+                    )

File pyconference/websetup.py

     load_environment(conf.global_conf, conf.local_conf)
 
     # Create the tables if they don't already exist
-    meta.metadata.create_all(bind=meta.engine)
+    log.info('Creating tables...')
+    meta.metadata.bind = meta.engine
+    meta.metadata.create_all(checkfirst = True)
+    log.info('Success!')
     from setuptools import setup, find_packages
 
 setup(
-    name='pyconference',
-    version='0.1',
-    description='',
-    author='',
-    author_email='',
-    url='',
-    install_requires=[
+    name = 'pyconference',
+    version = '0.1',
+    description = 'PyConference is a automation software for use in conferences.',
+    author = 'Francisco Souza',
+    author_email = 'francisco@franciscosouza.net',
+    url = 'http://www.franciscosouza.net',
+    install_requires = [
         "Pylons>=0.9.7",
         "SQLAlchemy>=0.5",
     ],
-    setup_requires=["PasteScript>=1.6.3"],
-    packages=find_packages(exclude=['ez_setup']),
-    include_package_data=True,
-    test_suite='nose.collector',
-    package_data={'pyconference': ['i18n/*/LC_MESSAGES/*.mo']},
+    setup_requires = ["PasteScript>=1.6.3"],
+    packages = find_packages(exclude = ['ez_setup']),
+    include_package_data = True,
+    test_suite = 'nose.collector',
+    package_data = {'pyconference': ['i18n/*/LC_MESSAGES/*.mo']},
     #message_extractors={'pyconference': [
     #        ('**.py', 'python', None),
     #        ('templates/**.mako', 'mako', {'input_encoding': 'utf-8'}),
     #        ('public/**', 'ignore', None)]},
-    zip_safe=False,
-    paster_plugins=['PasteScript', 'Pylons'],
-    entry_points="""
+    zip_safe = False,
+    paster_plugins = ['PasteScript', 'Pylons'],
+    entry_points = """
     [paste.app_factory]
     main = pyconference.config.middleware:make_app