pyramid/bodhi/bodhi/models/models.py | 26 +++++++++++++++++++----- pyramid/bodhi/bodhi/resources.py | 10 +++------ pyramid/bodhi/bodhi/tests/models/test_models.py | 11 +++++++--- 3 files changed, 33 insertions(+), 14 deletions(-)
New commits: commit 9ad279c25541ecb211f6e8132fead2f44bf50bca Author: Luke Macken lmacken@redhat.com Date: Sat May 14 11:27:39 2011 -0400
Add a User model
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py index df1036f..a947e1b 100644 --- a/pyramid/bodhi/bodhi/models/models.py +++ b/pyramid/bodhi/bodhi/models/models.py @@ -263,9 +263,9 @@ class Update(Base):
id = Column(Integer, primary_key=True) _title = Column('title', UnicodeText) - submitter = Column(Unicode(32), nullable=False) + # TODO: more flexible karma schema karma = Column(Integer, default=0) - notes = Column(UnicodeText) + notes = Column(UnicodeText, nullable=False) # Mandatory notes
# Enumerated types type = Column(UpdateType.db_type(), nullable=False) @@ -317,6 +317,8 @@ class Update(Base): #releases = relation('Release', secondary=update_release_table, # backref='updates', lazy=False)
+ user_id = Column(Integer, ForeignKey('users.id')) + @synonym_for('_title') @property def title(self, show_nvrs=True, delim=' '): @@ -584,7 +586,7 @@ class Update(Base): val += u"\n Notes: %s" % '\n'.join(notes) val += u""" Submitter: %s - Submitted: %s\n""" % (self.submitter, self.date_submitted) + Submitted: %s\n""" % (self.user.name, self.date_submitted) if len(self.comments): val += u" Comments: " comments = [] @@ -821,7 +823,8 @@ class Comment(Base): anonymous = Column(Boolean, default=False) timestamp = Column(DateTime, default=datetime.utcnow)
- update_id = Column('update_id', Integer, ForeignKey('updates.id')) + update_id = Column(Integer, ForeignKey('updates.id')) + user_id = Column(Integer, ForeignKey('users.id'))
def __str__(self): karma = '0' @@ -961,6 +964,17 @@ class Bug(Base): return "%s/show_bug.cgi?id=%s" % (config.get('bz_baseurl'), self.bug_id)
+class User(Base): + __tablename__ = 'users' + + id = Column(Integer, primary_key=True) + name = Column(Unicode(32), unique=True, nullable=False) + + # One-to-many relationships + comments = relation(Comment, backref='user', lazy=False) + updates = relation(Update, backref='user', lazy=False) + + #class Stack(Base): # """ # A Stack in bodhi represents a group of packages that are commonly pushed @@ -973,13 +987,15 @@ class Bug(Base):
def populate(): session = DBSession() + user = User(name=u'bodhi') + session.add(user) release = Release(name=u'F15', long_name=u'Fedora 15', id_prefix=u'FEDORA', dist_tag=u'dist-f15') session.add(release) pkg = Package(name=u'bodhi') session.add(pkg) build = Build(nvr=u'bodhi-2.0-1.fc15', release=release) session.add(build) - update = Update(builds=[build], submitter=u'bodhi') + update = Update(builds=[build], user=user) update.type = UpdateType.bugfix session.add(update) session.commit() diff --git a/pyramid/bodhi/bodhi/resources.py b/pyramid/bodhi/bodhi/resources.py index e01f935..eb08470 100644 --- a/pyramid/bodhi/bodhi/resources.py +++ b/pyramid/bodhi/bodhi/resources.py @@ -3,7 +3,7 @@ import logging from sqlalchemy.orm.exc import NoResultFound
from bodhi.models import initialize_sql, DBSession -from bodhi.models import Update, Package, Build, Release #, User +from bodhi.models import Update, Package, Build, Release, User
log = logging.getLogger(__name__)
@@ -76,11 +76,9 @@ class ReleaseResource(BodhiResource): __model__ = Release __column__ = u'name'
- -# TODO: proper User model? -#class UserResource(BodhiResource): -# __model__ = Update -# __keys__ = (u'submitter') +class UserResource(BodhiResource): + __model__ = User + __keys__ = u'name'
root = BodhiRoot()
diff --git a/pyramid/bodhi/bodhi/tests/models/test_models.py b/pyramid/bodhi/bodhi/tests/models/test_models.py index 63f82d9..03d91a1 100644 --- a/pyramid/bodhi/bodhi/tests/models/test_models.py +++ b/pyramid/bodhi/bodhi/tests/models/test_models.py @@ -107,7 +107,6 @@ class TestUpdate(ModelTest): type=UpdateType.security, status=UpdateStatus.pending, request=UpdateRequest.testing, - submitter=u'lmacken', close_bugs=True, notes=u'foobar', karma=0, @@ -117,11 +116,12 @@ class TestUpdate(ModelTest): release = model.Release(**TestRelease.attrs) return dict( builds = [model.Build(nvr=u'TurboGears-1.0.8-3.fc11', - package=model.Package(**TestPackage.attrs), - release = release)], + package=model.Package(**TestPackage.attrs), + release = release)], bugs = [model.Bug(bug_id=1), model.Bug(bug_id=2)], cves = [model.CVE(cve_id=u'CVE-2009-0001')], release = release, + user = model.User(name=u'lmacken') )
def get_update(self, name=u'TurboGears-1.0.8-3.fc11'): @@ -331,3 +331,8 @@ class TestUpdate(ModelTest): eq_(self.obj.get_build_tag(), u'dist-f11-updates-testing') self.obj.status = UpdateStatus.stable eq_(self.obj.get_build_tag(), u'dist-f11-updates') + + +class TestUser(ModelTest): + klass = model.User + attrs = dict(name=u'Bob Vila')