Exemplo n.º 1
0
def populate(engine):

    session = DBSession()

    cp = VacationType.by_id(session, 1)
    rtt = VacationType.by_id(session, 2)
    parent = VacationType.by_id(session, 3)

    fr_country = Countries.by_name(session, u'fr')
    session.add(fr_country)
    lu_country = Countries.by_name(session, u'lu')
    session.add(lu_country)
    us_country = Countries.by_name(session, u'us')
    session.add(us_country)
    zh_country = Countries.by_name(session, u'zh')
    session.add(zh_country)

    # CP is available for everyone
    cp.countries.append(fr_country)
    cp.countries.append(lu_country)
    cp.countries.append(us_country)
    cp.countries.append(zh_country)

    # RTT only available for france
    rtt.countries.append(fr_country)

    # parent is available for everyone
    parent.countries.append(fr_country)
    parent.countries.append(lu_country)
    parent.countries.append(us_country)
    parent.countries.append(zh_country)

    session.commit()
Exemplo n.º 2
0
    def update_view(self, model, view):
        settings = self.request.registry.settings
        ldap = False
        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if view['errors']:
            self.request.session.flash('error;%s' % ','.join(view['errors']))

        view['groups'] = Group.all(self.session, order_by=Group.name)
        view['managers'] = User.by_role(self.session, 'manager')

        if ldap:
            ldap = LdapCache()
            login = self.get_model().login
            if login:
                view['ldap_user'] = ldap.search_user_by_login(login)
            else:
                view['ldap_user'] = {}
            view['managers'] = ldap.list_manager()
            view['units'] = ldap.list_ou()
            view['countries'] = Countries.all(self.session,
                                              order_by=Countries.name)
            # generate a random password for the user, he must change it later
            password = randomstring()
            log.info('temporary password generated: %s' % password)
            view['password'] = password
            view['view_name'] = self.__class__.__name__.lower()
            view['myself'] = (self.user.id == self.get_model().id)
Exemplo n.º 3
0
 def set_country(self, account):
     r = self.request
     if 'set_country' in r.params:
         _ct = r.params['set_country']
     else:
         _ct = u'fr'
     country = Countries.by_name(self.session, _ct)
     account._country = country
Exemplo n.º 4
0
 def setUp(self):
     super(AccountTestCase, self).setUp()
     import uuid
     from pyvac.models import User, Group, Countries
     fr_country = Countries.by_name(self.session, u'fr')
     self.account_login = unicode(uuid.uuid4())
     u = User(login=self.account_login, password=u'secret',
              _country=fr_country)
     u.groups.append(Group.by_name(self.session, u'user'))
     self.session.add(u)
     self.session.flush()
     self.account_id = u.id
     self.account_todelete = [self.account_id]
Exemplo n.º 5
0
 def set_country(self, account):
     r = self.request
     if 'set_country' in r.params:
         _ct = r.params['set_country']
     else:
         # country cannot be edited by user, only admin
         # so default to logged user country
         if self.user:
             _ct = self.user.country
         else:
             _ct = u'fr'
     country = Countries.by_name(self.session, _ct)
     account._country = country
Exemplo n.º 6
0
    def render(self):
        if self.user and not self.user.is_admin:
            return HTTPFound(location=route_url('home', self.request))

        country = Countries.by_name(self.session, self.user.country)
        users = User.by_country(self.session, country.id)

        today = datetime.now()
        data = []
        rtt_usage = {}
        cp_usage = {}
        for user in users:
            if user.login in self.ignore_users:
                continue

            usage = dict([(k, v.amount) for k, v in list(user.pool.items())])
            rtt_usage[user.login] = usage.get('RTT', 0)
            cp_total = usage.get('CP acquis', 0) + usage.get('CP restant', 0)
            cp_usage[user.login] = cp_total
            if user.login not in self.ignore_users:
                data.append('%s,%s,%s' % (
                    user.login,
                    rtt_usage[user.login],
                    cp_usage[user.login],
                ))

        if data:
            # sort list by name
            data = sorted(data)
            header = ('%s,%s,%s' % ('Login', 'RTT', 'CP'))
            data.insert(0, header)

        ret = {
            'user_count': User.find(self.session, count=True),
            'users': users,
            'today': today,
            'cp_usage': cp_usage,
            'exported': '\n'.join(data)
        }

        if self.user.country == 'fr':
            ret['rtt_usage'] = rtt_usage

        return ret
Exemplo n.º 7
0
    def update_view(self, model, view):
        settings = self.request.registry.settings
        ldap = False
        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if view['errors']:
            self.request.session.flash('error;%s' % ','.join(view['errors']))

        view['groups'] = Group.all(self.session, order_by=Group.name)
        view['managers'] = User.by_role(self.session, 'manager')
        view['countries'] = Countries.all(self.session,
                                          order_by=Countries.name)
        if ldap:
            ldap = LdapCache()
            login = self.get_model().login
            view['ldap_user'] = {}
            if login:
                try:
                    view['ldap_user'] = ldap.search_user_by_login(login)
                except UnknownLdapUser:
                    msg = 'Unknown ldap user %s' % login
                    self.request.session.flash('error;%s' % msg)

            view['managers'] = ldap.list_manager()
            view['units'] = ldap.list_ou()

            view['teams'] = ldap.list_teams()
            uteams = {}
            for team, members in view['teams'].iteritems():
                for member in members:
                    uteams.setdefault(member, []).append(team)
            view['user_teams'] = uteams.get(view['ldap_user'].get('dn'), [])

            # generate a random password for the user, he must change it later
            password = randomstring()
            log.debug('temporary password generated: %s' % password)
            view['password'] = password
            view['view_name'] = self.__class__.__name__.lower()
            view['myself'] = (self.user.id == self.get_model().id)

            jpeg = view['ldap_user'].get('jpegPhoto')
            if jpeg:
                view['ldap_user']['photo'] = base64.b64encode(jpeg)
Exemplo n.º 8
0
    def update_view(self, model, view):
        settings = self.request.registry.settings
        ldap = False
        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if view['errors']:
            self.request.session.flash('error;%s' % ','.join(view['errors']))

        view['groups'] = Group.all(self.session, order_by=Group.name)
        view['managers'] = User.by_role(self.session, 'manager')

        if ldap:
            ldap = LdapCache()
            login = self.get_model().login
            view['ldap_user'] = {}
            if login:
                try:
                    view['ldap_user'] = ldap.search_user_by_login(login)
                except UnknownLdapUser:
                    msg = 'Unknown ldap user %s' % login
                    self.request.session.flash('error;%s' % msg)

            view['managers'] = ldap.list_manager()
            view['units'] = ldap.list_ou()

            view['teams'] = ldap.list_teams()
            uteams = {}
            for team, members in view['teams'].iteritems():
                for member in members:
                    uteams.setdefault(member, []).append(team)
            view['user_teams'] = uteams.get(view['ldap_user'].get('dn'), [])

            view['countries'] = Countries.all(self.session,
                                              order_by=Countries.name)
            # generate a random password for the user, he must change it later
            password = randomstring()
            log.debug('temporary password generated: %s' % password)
            view['password'] = password
            view['view_name'] = self.__class__.__name__.lower()
            view['myself'] = (self.user.id == self.get_model().id)
Exemplo n.º 9
0
def populate(engine):

    Base.metadata.create_all(engine)
    session = DBSession()

    user_perm = Permission(name='user_view')
    admin_perm = Permission(name='admin_view')
    manager_perm = Permission(name='manager_view')
    sudo_perm = Permission(name='sudo_view')
    session.add(user_perm)
    session.add(admin_perm)
    session.add(manager_perm)
    session.add(sudo_perm)

    admin_group = Group(name='admin')
    admin_group.permissions.append(user_perm)
    admin_group.permissions.append(admin_perm)
    admin_group.permissions.append(manager_perm)
    admin_group.permissions.append(sudo_perm)
    session.add(admin_group)

    manager_group = Group(name='manager')
    manager_group.permissions.append(user_perm)
    manager_group.permissions.append(manager_perm)
    manager_group.permissions.append(sudo_perm)
    session.add(manager_group)

    user_group = Group(name='user')
    user_group.permissions.append(user_perm)
    session.add(user_group)

    sudoer_group = Group(name='sudoer')
    sudoer_group.permissions.append(sudo_perm)
    session.add(sudoer_group)

    vactype1 = VacationType(name='CP')
    session.add(vactype1)
    vactype2 = VacationType(name='RTT')
    session.add(vactype2)
    vactype3 = VacationType(name='Congé Parental')
    session.add(vactype3)
    vactype4 = VacationType(name='Récupération')
    session.add(vactype4)
    vactype5 = VacationType(name='Maladie', visibility='admin')
    session.add(vactype5)
    vactype6 = VacationType(name='Exceptionnel')
    session.add(vactype6)
    vactype7 = VacationType(name='Compensatoire')
    session.add(vactype7)
    vactype8 = VacationType(name='Télétravail')
    session.add(vactype8)

    fr_country = Countries(name='fr')
    session.add(fr_country)
    lu_country = Countries(name='lu')
    session.add(lu_country)
    us_country = Countries(name='us')
    session.add(us_country)
    zh_country = Countries(name='zh')
    session.add(zh_country)

    now = datetime.now()
    cp_pool1 = Pool(name='acquis',
                    date_start=datetime(now.year, 6, 1),
                    date_end=datetime(now.year + 1, 5, 31),
                    status='active',
                    vacation_type=vactype1,
                    country=fr_country,
                    pool_group=1,
                    date_last_increment=now,
                    )
    session.add(cp_pool1)
    cp_pool2 = Pool(name='restant',
                    date_start=datetime(now.year - 1, 6, 1),
                    date_end=datetime(now.year, 5, 31),
                    status='active',
                    vacation_type=vactype1,
                    country=fr_country,
                    pool_group=1,
                    date_last_increment=now,
                    )
    session.add(cp_pool2)
    cplu_pool1 = Pool(name='acquis',
                      alias='légaux',
                      date_start=datetime(now.year, 1, 1),
                      date_end=datetime(now.year + 1, 3, 31),
                      status='active',
                      vacation_type=vactype1,
                      country=lu_country,
                      pool_group=2,
                      date_last_increment=now,
                      )
    session.add(cplu_pool1)
    cplu_pool2 = Pool(name='restant',
                      alias='report',
                      date_start=datetime(now.year - 1, 1, 1),
                      date_end=datetime(now.year, 3, 31),
                      status='active',
                      vacation_type=vactype1,
                      country=lu_country,
                      pool_group=2,
                      date_last_increment=now,
                      )
    session.add(cplu_pool2)
    rtt_pool = Pool(name=vactype2.name,
                    date_start=datetime(now.year, 1, 1),
                    date_end=datetime(now.year + 1, 12, 31),
                    status='active',
                    vacation_type=vactype2,
                    country=fr_country,
                    date_last_increment=now,
                    )
    session.add(rtt_pool)

    # CP is available for everyone
    vactype1.countries.append(fr_country)
    vactype1.countries.append(lu_country)
    vactype1.countries.append(us_country)
    vactype1.countries.append(zh_country)

    # RTT only available for france
    vactype2.countries.append(fr_country)

    # Parental vacation is available for everyone
    vactype3.countries.append(fr_country)
    vactype3.countries.append(lu_country)
    vactype3.countries.append(us_country)
    vactype3.countries.append(zh_country)

    # Recovery is available for everyone
    vactype4.countries.append(fr_country)
    vactype4.countries.append(lu_country)
    vactype4.countries.append(us_country)
    vactype4.countries.append(zh_country)

    # Sickness vacation is available for all countries
    vactype5.countries.append(fr_country)
    vactype5.countries.append(lu_country)
    vactype5.countries.append(us_country)
    vactype5.countries.append(zh_country)

    # Exception vacation is available for all countries
    vactype6.countries.append(fr_country)
    vactype6.countries.append(lu_country)
    vactype6.countries.append(us_country)
    vactype6.countries.append(zh_country)

    # Holiday recovery is only available for LU
    vactype7.countries.append(lu_country)

    # Remote is available for everyone
    vactype8.countries.append(fr_country)
    vactype8.countries.append(lu_country)
    vactype8.countries.append(us_country)
    vactype8.countries.append(zh_country)

    common_password = '******'

    admin = User(login='******',
                 password=common_password,
                 email='*****@*****.**',
                 firstname='The',
                 lastname='Administrator',
                 role='admin',
                 _country=fr_country)
    admin.groups.append(admin_group)
    session.add(admin)

    session.commit()
Exemplo n.º 10
0
def setUpModule():

    engine = create_engine(settings)
    populate(engine)

    session = DBSession()
    user_group = Group.by_name(session, 'user')
    manager_group = Group.by_name(session, 'manager')
    sudoer_group = Group.by_name(session, 'sudoer')
    common_password = '******'

    cp_vacation = VacationType.by_name(session, 'CP')
    rtt_vacation = VacationType.by_name(session, 'RTT')
    recovery_vacation = VacationType.by_name(session, 'Récupération')
    sickness_vacation = VacationType.by_name(session, 'Maladie')
    exception_vacation = VacationType.by_name(session, 'Exceptionnel')

    fr_country = Countries.by_name(session, 'fr')
    us_country = Countries.by_name(session, 'us')
    lu_country = Countries.by_name(session, 'lu')

    manager1 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        firstname='First',
        lastname='Manager',
        role='manager',
        _country=fr_country,
    )
    manager1.groups.append(manager_group)
    session.add(manager1)

    manager2 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        firstname='Second',
        lastname='Manager',
        role='manager',
        _country=fr_country,
    )
    manager2.groups.append(manager_group)
    session.add(manager2)

    manager_us = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        firstname='Third',
        lastname='Manager',
        role='manager',
        _country=us_country,
    )
    manager_us.groups.append(manager_group)
    session.add(manager_us)

    user1 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        manager=manager1,
        firstname='John',
        lastname='Doe',
        _country=fr_country,
        registration_number=1337,
    )
    user1.groups.append(user_group)
    session.add(user1)

    user2 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        manager=manager2,
        firstname='Jane',
        lastname='Doe',
        _country=fr_country,
    )
    user2.groups.append(user_group)
    user2.groups.append(sudoer_group)
    session.add(user2)

    session.flush()
    sudoer = Sudoer(source_id=user2.id, target_id=1)
    session.add(sudoer)

    user3 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        manager=manager1,
        firstname='Sarah',
        lastname='Doe',
        _country=lu_country,
    )
    user3.groups.append(user_group)
    session.add(user3)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('14/04/2015', '%d/%m/%Y')
    req1 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=cp_vacation,
                   status='PENDING',
                   user=user1,
                   notified=False)
    session.add(req1)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('21/04/2015', '%d/%m/%Y')
    req2 = Request(
        date_from=date_from,
        date_to=date_to,
        days=10,
        vacation_type=cp_vacation,
        status='PENDING',
        user=user2,
        notified=False,
    )
    session.add(req2)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req3 = Request(
        date_from=date_from,
        date_to=date_to,
        days=5,
        vacation_type=rtt_vacation,
        status='ACCEPTED_MANAGER',
        user=user1,
        notified=True,
    )
    session.add(req3)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req4 = Request(
        date_from=date_from,
        date_to=date_to,
        days=5,
        vacation_type=rtt_vacation,
        status='CANCELED',
        user=user1,
        notified=True,
    )
    session.add(req4)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req5 = Request(
        date_from=date_from,
        date_to=date_to,
        days=5,
        vacation_type=rtt_vacation,
        status='APPROVED_ADMIN',
        user=manager_us,
        notified=True,
    )
    session.add(req5)

    date_from = datetime.strptime('24/08/2011', '%d/%m/%Y')
    date_to = datetime.strptime('24/08/2011', '%d/%m/%Y')
    req6 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status='APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label='AM')
    session.add(req6)

    date_from = datetime.strptime('14/07/2014', '%d/%m/%Y')
    date_to = datetime.strptime('14/07/2014', '%d/%m/%Y')
    req7 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status='APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label='AM')
    session.add(req7)

    # used for rtt vacation checks

    date_from = datetime.strptime('01/04/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/04/2016', '%d/%m/%Y')
    req8 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status='PENDING',
                   user=user1,
                   notified=True)
    session.add(req8)

    date_from = datetime.strptime('01/03/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/03/2016', '%d/%m/%Y')
    req9 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status='ACCEPTED_MANAGER',
                   user=user1,
                   notified=True)
    session.add(req9)

    date_from = datetime.strptime('01/02/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/02/2016', '%d/%m/%Y')
    req10 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status='APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req10)

    date_from = datetime.strptime('01/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/06/2016', '%d/%m/%Y')
    req11 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=recovery_vacation,
                    status='APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req11)

    date_from = datetime.strptime('12/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('12/04/2015', '%d/%m/%Y')
    req12 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status='DENIED',
                    user=user1,
                    notified=True)
    session.add(req12)

    date_from = datetime.strptime('06/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('06/06/2016', '%d/%m/%Y')
    req13 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=sickness_vacation,
                    status='APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req13)

    date_from = datetime.strptime('13/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('13/06/2016', '%d/%m/%Y')
    req14 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=exception_vacation,
                    status='APPROVED_ADMIN',
                    user=user2,
                    message="I need to see Star Wars, I'm a huge fan",
                    notified=True)
    session.add(req14)

    session.commit()
Exemplo n.º 11
0
def populate(engine):

    Base.metadata.create_all(engine)
    session = DBSession()

    user_perm = Permission(name=u'user_view')
    admin_perm = Permission(name=u'admin_view')
    manager_perm = Permission(name=u'manager_view')
    sudo_perm = Permission(name=u'sudo_view')
    session.add(user_perm)
    session.add(admin_perm)
    session.add(manager_perm)
    session.add(sudo_perm)

    admin_group = Group(name=u'admin')
    admin_group.permissions.append(user_perm)
    admin_group.permissions.append(admin_perm)
    admin_group.permissions.append(manager_perm)
    admin_group.permissions.append(sudo_perm)
    session.add(admin_group)

    manager_group = Group(name=u'manager')
    manager_group.permissions.append(user_perm)
    manager_group.permissions.append(manager_perm)
    manager_group.permissions.append(sudo_perm)
    session.add(manager_group)

    user_group = Group(name=u'user')
    user_group.permissions.append(user_perm)
    session.add(user_group)

    sudoer_group = Group(name=u'sudoer')
    sudoer_group.permissions.append(sudo_perm)
    session.add(sudoer_group)

    vactype1 = VacationType(name=u'CP')
    session.add(vactype1)
    vactype2 = VacationType(name=u'RTT')
    session.add(vactype2)
    vactype3 = VacationType(name=u'Congé Parental')
    session.add(vactype3)
    vactype4 = VacationType(name=u'Récupération')
    session.add(vactype4)
    vactype5 = VacationType(name=u'Maladie', visibility=u'admin')
    session.add(vactype5)
    vactype6 = VacationType(name=u'Exceptionnel')
    session.add(vactype6)
    vactype7 = VacationType(name=u'Compensatoire')
    session.add(vactype7)

    fr_country = Countries(name=u'fr')
    session.add(fr_country)
    lu_country = Countries(name=u'lu')
    session.add(lu_country)
    us_country = Countries(name=u'us')
    session.add(us_country)
    zh_country = Countries(name=u'zh')
    session.add(zh_country)

    # CP is available for everyone
    vactype1.countries.append(fr_country)
    vactype1.countries.append(lu_country)
    vactype1.countries.append(us_country)
    vactype1.countries.append(zh_country)

    # RTT only available for france
    vactype2.countries.append(fr_country)

    # Parental vacation is available for everyone
    vactype3.countries.append(fr_country)
    vactype3.countries.append(lu_country)
    vactype3.countries.append(us_country)
    vactype3.countries.append(zh_country)

    # Recovery is available for everyone
    vactype4.countries.append(fr_country)
    vactype4.countries.append(lu_country)
    vactype4.countries.append(us_country)
    vactype4.countries.append(zh_country)

    # Sickness vacation is available for all countries
    vactype5.countries.append(fr_country)
    vactype5.countries.append(lu_country)
    vactype5.countries.append(us_country)
    vactype5.countries.append(zh_country)

    # Exception vacation is available for all countries
    vactype6.countries.append(fr_country)
    vactype6.countries.append(lu_country)
    vactype6.countries.append(us_country)
    vactype6.countries.append(zh_country)

    # Holiday recovery is only available for LU
    vactype7.countries.append(lu_country)

    common_password = u'changeme'

    admin = User(login=u'admin',
                 password=common_password,
                 email=u'*****@*****.**',
                 firstname=u'The',
                 lastname=u'Administrator',
                 role=u'admin',
                 _country=fr_country)
    admin.groups.append(admin_group)
    session.add(admin)

    session.commit()
Exemplo n.º 12
0
def setUpModule():

    engine = create_engine(settings)
    populate(engine)

    session = DBSession()
    user_group = Group.by_name(session, u'user')
    manager_group = Group.by_name(session, u'manager')
    sudoer_group = Group.by_name(session, u'sudoer')
    common_password = u'changeme'

    cp_vacation = VacationType.by_name(session, u'CP')
    rtt_vacation = VacationType.by_name(session, u'RTT')
    recovery_vacation = VacationType.by_name(session, u'Récupération')
    sickness_vacation = VacationType.by_name(session, u'Maladie')
    exception_vacation = VacationType.by_name(session, u'Exceptionnel')

    fr_country = Countries.by_name(session, u'fr')
    us_country = Countries.by_name(session, u'us')

    manager1 = User(login=u'manager1',
                    password=common_password,
                    email=u'*****@*****.**',
                    firstname=u'First',
                    lastname=u'Manager',
                    role=u'manager',
                    _country=fr_country,
                    )
    manager1.groups.append(manager_group)
    session.add(manager1)

    manager2 = User(login=u'manager2',
                    password=common_password,
                    email=u'*****@*****.**',
                    firstname=u'Second',
                    lastname=u'Manager',
                    role=u'manager',
                    _country=fr_country,
                    )
    manager2.groups.append(manager_group)
    session.add(manager2)

    manager_us = User(login=u'manager3',
                      password=common_password,
                      email=u'*****@*****.**',
                      firstname=u'Third',
                      lastname=u'Manager',
                      role=u'manager',
                      _country=us_country,
                      )
    manager_us.groups.append(manager_group)
    session.add(manager_us)

    user1 = User(login=u'jdoe',
                 password=common_password,
                 email=u'*****@*****.**',
                 manager=manager1,
                 firstname=u'John',
                 lastname=u'Doe',
                 _country=fr_country,
                 )
    user1.groups.append(user_group)
    session.add(user1)

    user2 = User(login=u'janedoe',
                 password=common_password,
                 email=u'*****@*****.**',
                 manager=manager2,
                 firstname=u'Jane',
                 lastname=u'Doe',
                 _country=fr_country,
                 )
    user2.groups.append(user_group)
    user2.groups.append(sudoer_group)
    session.add(user2)

    session.flush()
    sudoer = Sudoer(source_id=user2.id, target_id=1)
    session.add(sudoer)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('14/04/2015', '%d/%m/%Y')
    req1 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=cp_vacation,
                   status=u'PENDING',
                   user=user1,
                   notified=False)
    session.add(req1)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('21/04/2015', '%d/%m/%Y')
    req2 = Request(date_from=date_from,
                   date_to=date_to,
                   days=10,
                   vacation_type=cp_vacation,
                   status=u'PENDING',
                   user=user2,
                   notified=False,)
    session.add(req2)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req3 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'ACCEPTED_MANAGER',
                   user=user1,
                   notified=True,)
    session.add(req3)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req4 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'CANCELED',
                   user=user1,
                   notified=True,)
    session.add(req4)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req5 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=manager_us,
                   notified=True,)
    session.add(req5)

    date_from = datetime.strptime('24/08/2011', '%d/%m/%Y')
    date_to = datetime.strptime('24/08/2011', '%d/%m/%Y')
    req6 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label=u'AM')
    session.add(req6)

    date_from = datetime.strptime('14/07/2014', '%d/%m/%Y')
    date_to = datetime.strptime('14/07/2014', '%d/%m/%Y')
    req7 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label=u'AM')
    session.add(req7)

    # used for rtt vacation checks

    date_from = datetime.strptime('01/04/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/04/2016', '%d/%m/%Y')
    req8 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status=u'PENDING',
                   user=user1,
                   notified=True)
    session.add(req8)

    date_from = datetime.strptime('01/03/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/03/2016', '%d/%m/%Y')
    req9 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status=u'ACCEPTED_MANAGER',
                   user=user1,
                   notified=True)
    session.add(req9)

    date_from = datetime.strptime('01/02/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/02/2016', '%d/%m/%Y')
    req10 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req10)

    date_from = datetime.strptime('01/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/06/2016', '%d/%m/%Y')
    req11 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=recovery_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req11)

    date_from = datetime.strptime('12/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('12/04/2015', '%d/%m/%Y')
    req12 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status=u'DENIED',
                    user=user1,
                    notified=True)
    session.add(req12)

    date_from = datetime.strptime('06/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('06/06/2016', '%d/%m/%Y')
    req13 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=sickness_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req13)

    date_from = datetime.strptime('13/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('13/06/2016', '%d/%m/%Y')
    req14 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=exception_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user2,
                    message=u"I need to see Star Wars, I'm a huge fan",
                    notified=True)
    session.add(req14)

    session.commit()
Exemplo n.º 13
0
def setUpModule():

    engine = create_engine(settings)
    populate(engine)

    session = DBSession()
    user_group = Group.by_name(session, u'user')
    manager_group = Group.by_name(session, u'manager')
    common_password = u'changeme'

    cp_vacation = VacationType.by_name(session, u'CP')
    rtt_vacation = VacationType.by_name(session, u'RTT')

    fr_country = Countries.by_name(session, u'fr')
    us_country = Countries.by_name(session, u'us')

    manager1 = User(login=u'manager1',
                    password=common_password,
                    email=u'*****@*****.**',
                    firstname=u'First',
                    lastname=u'Manager',
                    role=u'manager',
                    _country=fr_country,
                    )
    manager1.groups.append(manager_group)
    session.add(manager1)

    manager2 = User(login=u'manager2',
                    password=common_password,
                    email=u'*****@*****.**',
                    firstname=u'Second',
                    lastname=u'Manager',
                    role=u'manager',
                    _country=fr_country,
                    )
    manager2.groups.append(manager_group)
    session.add(manager2)

    manager_us = User(login=u'manager3',
                      password=common_password,
                      email=u'*****@*****.**',
                      firstname=u'Third',
                      lastname=u'Manager',
                      role=u'manager',
                      _country=us_country,
                      )
    manager_us.groups.append(manager_group)
    session.add(manager_us)

    user1 = User(login=u'jdoe',
                 password=common_password,
                 email=u'*****@*****.**',
                 manager=manager1,
                 firstname=u'John',
                 lastname=u'Doe',
                 _country=fr_country,
                 )
    user1.groups.append(user_group)
    session.add(user1)

    user2 = User(login=u'janedoe',
                 password=common_password,
                 email=u'*****@*****.**',
                 manager=manager2,
                 firstname=u'Jane',
                 lastname=u'Doe',
                 _country=fr_country,
                 )
    user2.groups.append(user_group)
    session.add(user2)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('14/04/2015', '%d/%m/%Y')
    req1 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=cp_vacation,
                   status=u'PENDING',
                   user=user1,
                   notified=False)
    session.add(req1)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('21/04/2015', '%d/%m/%Y')
    req2 = Request(date_from=date_from,
                   date_to=date_to,
                   days=10,
                   vacation_type=cp_vacation,
                   status=u'PENDING',
                   user=user2,
                   notified=False,)
    session.add(req2)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req3 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'ACCEPTED_MANAGER',
                   user=user1,
                   notified=True,)
    session.add(req3)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req4 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'CANCELED',
                   user=user1,
                   notified=True,)
    session.add(req4)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req5 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=manager_us,
                   notified=True,)
    session.add(req5)

    date_from = datetime.strptime('24/08/2011', '%d/%m/%Y')
    date_to = datetime.strptime('24/08/2011', '%d/%m/%Y')
    req6 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label=u'AM')
    session.add(req6)

    date_from = datetime.strptime('14/07/2014', '%d/%m/%Y')
    date_to = datetime.strptime('14/07/2014', '%d/%m/%Y')
    req7 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label=u'AM')
    session.add(req7)

    # used for rtt vacation checks

    date_from = datetime.strptime('01/04/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/04/2016', '%d/%m/%Y')
    req8 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status=u'PENDING',
                   user=user1,
                   notified=True)
    session.add(req8)

    date_from = datetime.strptime('01/03/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/03/2016', '%d/%m/%Y')
    req9 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status=u'ACCEPTED_MANAGER',
                   user=user1,
                   notified=True)
    session.add(req9)

    date_from = datetime.strptime('01/02/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/02/2016', '%d/%m/%Y')
    req10 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req10)

    session.commit()