Exemple #1
0
    def setUp(self):
        self.request = testing.DummyRequest()
        self.request.user = None
        self.config = testing.setUp(request=self.request)
        self.config.include('pyconca')

        engine = create_engine('sqlite://')
        DBSession.configure(bind=engine)

        from pyconca.models import (
            Base,
            User,
            UserGroup,
            Group,
            )
        Base.metadata.create_all(engine)
        with transaction.manager:
            self._admin_id = 1
            self._speaker_id = 2
            for model in (
                User(id=self._admin_id, username='******', password='', first_name='Admin', last_name='Istrator', email='*****@*****.**'),
                User(id=self._speaker_id, username='******', password='', first_name='Spe', last_name='Aker', email='*****@*****.**'),
                Group(id=1, name='admin'),
                UserGroup(user_id=self._admin_id, group_id=1),
                ):
                DBSession.add(model)
Exemple #2
0
    def setUp(self):
        self.request = testing.DummyRequest()
        self.request.user = None
        self.config = testing.setUp(request=self.request)
        self.config.include('pyconca')

        engine = create_engine('sqlite://')
        DBSession.configure(bind=engine)

        from pyconca.models import (
            Base,
            User,
            UserGroup,
            Group,
            Talk
            )
        Base.metadata.create_all(engine)
        with transaction.manager:
            self._admin_id = 1
            self._speaker_id = 2
            for model in (
                User(id=self._admin_id, username='******', password='', first_name='Admin', last_name='Istrator', email='*****@*****.**'),
                User(id=self._speaker_id, username='******', password='', first_name='Spe', last_name='Aker', email='*****@*****.**'),
                Group(id=1, name='admin'),
                UserGroup(user_id=self._admin_id, group_id=1),
                Talk(id=self._admin_id, owner_id=self._admin_id, title='Admin Title', type='talk', level='experienced', abstract='Abstract', outline='Outline', reviewer_notes='Reviewed?'),
                Talk(id=self._speaker_id, owner_id=self._speaker_id, title='Speaker Title', type='tutorial', level='novice', abstract='Strabact', outline='Silhouette', reviewer_notes='Viewed again.'),
                ):
                DBSession.add(model)
Exemple #3
0
 def _loggedInAdmin(self):
     from pyconca.models import User
     # This plus the fixtures gives us info['is_admin'] == True
     self.request.user = DBSession.query(User).get(self._admin_id)
     # This gives us info['logged_in'] == 'pyramid_admin'
     self.config.testing_securitypolicy(userid='pyramid_admin',
                                        permissive=True)
Exemple #4
0
    def setUp(self):
        self.request = testing.DummyRequest()
        self.request.user = None
        self.config = testing.setUp(request=self.request)
        self.config.include('pyconca')

        engine = create_engine('sqlite://')
        DBSession.configure(bind=engine)

        from pyconca.models import (Base, User, UserGroup, Group, Talk)
        Base.metadata.create_all(engine)
        with transaction.manager:
            self._admin_id = 1
            self._speaker_id = 2
            for model in (
                    User(id=self._admin_id,
                         username='******',
                         password='',
                         first_name='Admin',
                         last_name='Istrator',
                         email='*****@*****.**'),
                    User(id=self._speaker_id,
                         username='******',
                         password='',
                         first_name='Spe',
                         last_name='Aker',
                         email='*****@*****.**'),
                    Group(id=1, name='admin'),
                    UserGroup(user_id=self._admin_id, group_id=1),
                    Talk(id=self._admin_id,
                         owner_id=self._admin_id,
                         title='Admin Title',
                         type='talk',
                         level='experienced',
                         abstract='Abstract',
                         outline='Outline',
                         reviewer_notes='Reviewed?'),
                    Talk(id=self._speaker_id,
                         owner_id=self._speaker_id,
                         title='Speaker Title',
                         type='tutorial',
                         level='novice',
                         abstract='Strabact',
                         outline='Silhouette',
                         reviewer_notes='Viewed again.'),
            ):
                DBSession.add(model)
Exemple #5
0
 def _loggedInAdmin(self):
     from pyconca.models import User
     # This plus the fixtures gives us info['is_admin'] == True
     self.request.user = DBSession.query(User).get(self._admin_id)
     # This gives us info['logged_in'] == 'pyramid_admin'
     self.config.testing_securitypolicy(
         userid='pyramid_admin',
         permissive=True)
Exemple #6
0
def schedule(request):
    from sqlalchemy.orm import joinedload
    from pyconca.models import DBSession, ScheduleSlot
    response = _build_response(request)
    response.update({
        'slots':
        dict((slot.code, slot)
             for slot in DBSession.query(ScheduleSlot).options(
                 joinedload('talk'),
                 joinedload('talk.owner'),
             )),
    })
    return response
Exemple #7
0
def schedule(request):
    from sqlalchemy.orm import joinedload
    from pyconca.models import DBSession, ScheduleSlot
    response = _build_response(request)
    response.update({
        'slots': dict(
            (slot.code, slot)
            for slot in DBSession.query(ScheduleSlot).options(
                joinedload('talk'),
                joinedload('talk.owner'),
            )
        ),
    })
    return response
Exemple #8
0
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()
Exemple #9
0
 def _query(self):
     return DBSession.query(self.model)
Exemple #10
0
 def _query(self):
     query = DBSession.query(self.model)
     default_order_by = self._default_order_by()
     if default_order_by:
         query = query.order_by(*default_order_by)
     return query
Exemple #11
0
 def save(self, instance):
     DBSession.add(instance)
     DBSession.flush()
Exemple #12
0
def main(argv=sys.argv):
    from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot

    ignore_errors = False
    if "--ignore-errors" in argv:
        argv.remove("--ignore-errors")
        ignore_errors = True

    if len(argv) != 2:
        usage(argv)
        return 1

    if "--dry-run" in argv:
        print "\n".join(map(str, parse_schedule(schedule)))
        return 0

    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    dumpdb = os.path.join(os.path.dirname(__file__), "../../prod_mysqldump")
    if os.path.exists(dumpdb):
        print "Running %r..." % (dumpdb, )
        res = os.system(dumpdb)
        if res:
            return res

    with transaction.manager:
        for slot in parse_schedule(schedule):
            s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first()
            if s is None:
                s = ScheduleSlot()
            vals = slot._asdict()
            talk = vals.pop("talk")
            s.__dict__.update(vals)
            DBSession.add(s)
            if talk:
                t = DBSession.query(Talk).filter_by(id=talk.id).first()
                if not t:
                    if ignore_errors:
                        continue
                    raise Exception("invalid talk: %r" % (talk, ))
                actual_talk_owner = "%s %s" % (t.owner.first_name,
                                               t.owner.last_name)
                assert actual_talk_owner.lower() == talk.owner_name.lower(), \
                        "bad data? owners don't match: %r != %r" %(
                            actual_talk_owner, talk.owner_name)
                ts = DBSession.query(TalkScheduleSlot).filter_by(
                    talk_id=t.id).first()
                if not ts:
                    ts = TalkScheduleSlot()
                    ts.talk_id = t.id
                ts.schedule_slot = s
                DBSession.add(ts)
        DBSession.flush()
Exemple #13
0
 def _loggedInStaff(self):
     from pyconca.models import User
     self.request.user = DBSession.query(User).get(self._speaker_id)
     self.config.testing_securitypolicy(
         userid='pyramid_speaker',
         permissive=True)
Exemple #14
0
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()
Exemple #15
0
def main(argv=sys.argv):
    from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot

    ignore_errors = False
    if "--ignore-errors" in argv:
        argv.remove("--ignore-errors")
        ignore_errors = True

    if len(argv) != 2:
        usage(argv)
        return 1

    if "--dry-run" in argv:
        print "\n".join(map(str, parse_schedule(schedule)))
        return 0

    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    dumpdb = os.path.join(os.path.dirname(__file__), "../../prod_mysqldump")
    if os.path.exists(dumpdb):
        print "Running %r..." %(dumpdb, )
        res = os.system(dumpdb)
        if res:
            return res

    with transaction.manager:
        for slot in parse_schedule(schedule):
            s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first()
            if s is None:
                s = ScheduleSlot()
            vals = slot._asdict()
            talk = vals.pop("talk")
            for (k, v) in vals.items():
                setattr(s, k, v)
            DBSession.add(s)
            if talk:
                t = DBSession.query(Talk).filter_by(id=talk.id).first()
                if not t:
                    if ignore_errors:
                        continue
                    raise Exception("invalid talk: %r" %(talk, ))
                actual_talk_owner = "%s %s" %(t.owner.first_name, t.owner.last_name)
                assert actual_talk_owner.lower() == talk.owner_name.lower(), \
                        "bad data? owners don't match: %r != %r" %(
                            actual_talk_owner, talk.owner_name)
                ts = DBSession.query(TalkScheduleSlot).filter_by(talk_id=t.id).first()
                if not ts:
                    ts = TalkScheduleSlot()
                    ts.talk_id = t.id
                ts.schedule_slot = s
                DBSession.add(ts)
        DBSession.flush()
Exemple #16
0
 def _loggedInStaff(self):
     from pyconca.models import User
     self.request.user = DBSession.query(User).get(self._speaker_id)
     self.config.testing_securitypolicy(userid='pyramid_speaker',
                                        permissive=True)
Exemple #17
0
def main(argv=sys.argv):
    from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot

    if len(argv) != 2:
        usage(argv)
        sys.exit(1)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, "sqlalchemy.")
    DBSession.configure(bind=engine)

    with transaction.manager:
        for slot in parse_schedule(schedule):
            s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first()
            if s is None:
                s = ScheduleSlot()
            vals = slot._asdict()
            talk = vals.pop("talk")
            s.__dict__.update(vals)
            DBSession.add(s)
            if talk:
                t = DBSession.query(Talk).filter_by(id=talk.id).first()
                if not t:
                    raise Exception("invalid talk: %r" % (talk,))
                actual_talk_owner = "%s %s" % (t.owner.first_name, t.owner.last_name)
                assert (
                    actual_talk_owner.lower() == talk.owner_name.lower()
                ), "bad data? owners don't match: %r != %r" % (actual_talk_owner, talk.owner_name)
                ts = DBSession.query(TalkScheduleSlot).filter_by(talk_id=t.id).first()
                if not ts:
                    ts = TalkScheduleSlot()
                    ts.talk_id = t.id
                ts.schedule_slot = s
                DBSession.add(ts)

        DBSession.flush()
Exemple #18
0
def main(argv=sys.argv):
    from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot

    if len(argv) != 2:
        usage(argv)
        sys.exit(1)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    with transaction.manager:
        for slot in parse_schedule(schedule):
            s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first()
            if s is None:
                s = ScheduleSlot()
            vals = slot._asdict()
            talk = vals.pop("talk")
            s.__dict__.update(vals)
            DBSession.add(s)
            if talk:
                t = DBSession.query(Talk).filter_by(id=talk.id).first()
                if not t:
                    raise Exception("invalid talk: %r" % (talk, ))
                actual_talk_owner = "%s %s" % (t.owner.first_name,
                                               t.owner.last_name)
                assert actual_talk_owner.lower() == talk.owner_name.lower(), \
                        "bad data? owners don't match: %r != %r" %(
                            actual_talk_owner, talk.owner_name)
                ts = DBSession.query(TalkScheduleSlot).filter_by(
                    talk_id=t.id).first()
                if not ts:
                    ts = TalkScheduleSlot()
                    ts.talk_id = t.id
                ts.schedule_slot = s
                DBSession.add(ts)

        DBSession.flush()
Exemple #19
0
 def delete(self, instance):
     DBSession.delete(instance)
Exemple #20
0
 def delete(self, instance):
     DBSession.delete(instance)
Exemple #21
0
 def _query(self):
     query = DBSession.query(self.model)
     default_order_by = self._default_order_by()
     if default_order_by:
         query = query.order_by(*default_order_by)
     return query
Exemple #22
0
 def save(self, instance):
     DBSession.add(instance)
     DBSession.flush()