当前位置: 首页>>代码示例>>Python>>正文


Python models.DBSession类代码示例

本文整理汇总了Python中intranet3.models.DBSession的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tmpl_ctx

    def tmpl_ctx(self):

        sprint = self.v.get("sprint")
        if not sprint:
            sprint_id = self.request.GET.get("sprint_id")
            sprint = Sprint.query.get(sprint_id)
        project = Project.query.get(sprint.project_id)

        sprints = (
            DBSession.query(Sprint.project_id, Sprint.worked_hours, Sprint.bugs_worked_hours, Sprint.achieved_points)
            .filter(Sprint.project_id == sprint.project_id)
            .all()
        )

        sprint.calculate_velocities(sprints)

        self.v["project"] = project
        self.v["sprint"] = sprint

        prev_sprint = (
            DBSession.query(Sprint)
            .filter(Sprint.project_id == sprint.project_id)
            .filter(Sprint.start < sprint.start)
            .order_by(Sprint.start.desc())
            .first()
        )
        next_sprint = (
            DBSession.query(Sprint)
            .filter(Sprint.project_id == sprint.project_id)
            .filter(Sprint.start > sprint.start)
            .order_by(Sprint.start.asc())
            .first()
        )
        return dict(project=project, sprint=sprint, prev_sprint=prev_sprint, next_sprint=next_sprint)
开发者ID:pagenoare,项目名称:intranet,代码行数:34,代码来源:sprint.py

示例2: post

    def post(self):
        args = self.request.json
        year = int(args.pop('year'))
        if 1999 > year > 2099:
            return dict(status='nok', reason='Zły rok %s' % year)

        leaves = Leave.query.filter(Leave.year==year).all()
        leaves = groupby(leaves, lambda l: l.user_id)
        for user_id, (mandated, remarks) in args.iteritems():
            user_id = int(user_id)
            try:
                mandated = int(mandated)
            except Exception:
                user = User.query.get(user_id)
                return dict(
                    status='nok',
                    reason=self._(u'Wrong hours format: ${hours} for user ${name}', hours=mandated, name=user.name)
                )

            if 0 > mandated  or mandated > 99:
                user = User.query.get(user_id)
                return dict(
                    status='nok',
                    reason=self._(u'Wrong hours number: ${hours} for user ${name}', hours=mandated, name=user.name)
                )

            leave_obj = leaves.get(user_id)
            if not leave_obj:
                leave_obj = Leave(user_id=user_id, year=year)
            else:
                leave_obj = leave_obj[0]
            leave_obj.number = mandated
            leave_obj.remarks = remarks
            DBSession.add(leave_obj)
        return dict(status='ok')
开发者ID:Rhenan,项目名称:intranet-open,代码行数:35,代码来源:list.py

示例3: UserChoices

class UserChoices(object):
    def __init__(self, empty=False, inactive=False):
        self.empty = empty
        self.inactive = inactive
        self.session = DBSession()

    def __iter__(self):
        if self.empty:
            yield "", u"-- None --"
        query = (
            self.session.query(User.id, User.name)
            .filter(not_(User.is_client()))
            .filter(User.is_active == True)
            .order_by(User.name)
        )
        for id, name in query:
            yield str(id), name

        if self.inactive:
            yield "", " " * 8
            query = (
                self.session.query(User.id, User.name)
                .filter(User.is_client())
                .filter(User.is_active == False)
                .order_by(User.name)
            )
            for id, name in query:
                yield str(id), name
开发者ID:KenjiTakahashi,项目名称:intranet,代码行数:28,代码来源:utils.py

示例4: get

    def get(self):
        check_role = self.request.GET.get('role')
        if not check_role or check_role == 'None':
            pivot_q = DBSession.query(User.id, User.name, User.start_work, User.stop_work, User.roles)\
                                .filter(User.is_not_client())\
                                .filter(User.is_active==True)\
                                .order_by(User.name)
        else:
            pivot_q = DBSession.query(User.id, User.name, User.start_work, User.stop_work, User.roles)\
                                .filter(User.is_not_client())\
                                .filter(User.is_active==True)\
                                .filter(User.roles.op('&&')('{%s}'%(check_role)))\
                                .order_by(User.name)

        users = {}
        for s in pivot_q:
            if s.start_work:
                users.setdefault(s.start_work.year, [0]*24)[s.start_work.month-1] += 1
            if s.stop_work:
                users.setdefault(s.stop_work.year, [0]*24)[s.stop_work.month-1+12] += 1
        role = User.ROLES
        return dict(
            start=users,
            roles=role,
            check=check_role,
            quarters_sum=self._quarters_sum,
            link_with_year=self._create_link_with_year,
            link_with_month=self._create_link_with_month,
            link_with_quarter=self._create_link_with_quarter,
        )
开发者ID:Rhenan,项目名称:intranet-open,代码行数:30,代码来源:list.py

示例5: tmpl_ctx

    def tmpl_ctx(self):

        sprint = self.v.get('sprint')
        if not sprint:
            sprint_id = self.request.GET.get('sprint_id')
            sprint = Sprint.query.get(sprint_id)
        project = Project.query.get(sprint.project_id)

        sprint.calculate_velocities()

        self.v['project'] = project
        self.v['sprint'] = sprint

        prev_sprint = DBSession.query(Sprint)\
            .filter(Sprint.project_id == sprint.project_id)\
            .filter(Sprint.start < sprint.start)\
            .order_by(Sprint.start.desc()).first()

        next_sprint = DBSession.query(Sprint) \
            .filter(Sprint.project_id == sprint.project_id) \
            .filter(Sprint.start > sprint.start) \
            .order_by(Sprint.start.asc()).first()

        return dict(
            project=project,
            sprint=sprint,
            prev_sprint=prev_sprint,
            next_sprint=next_sprint,
        )
开发者ID:Rhenan,项目名称:intranet-open,代码行数:29,代码来源:sprint.py

示例6: __init__

    def __init__(self, event):
        today = datetime.date.today()

        user = event['request'].user
        self.arrival = None
        if not user:
            return
        row = DBSession.query('ts').from_statement("""
            SELECT MIN(p.ts) as "ts"
            FROM presence_entry p
            WHERE DATE(p.ts) = :today
              AND p.user_id = :user_id
            """).params(today=today, user_id=user.id).first()

        if not (row and row.ts):
            return

        arrival = row.ts
        now = datetime.datetime.now()
        since_morning_hours = float((now - arrival).seconds) / 3600
        self.present = since_morning_hours
        noted = 0.0
        row = DBSession.query('time').from_statement("""
            SELECT COALESCE(SUM(t.time), 0.0) as "time"
            FROM time_entry t
            WHERE t.date = :today
              AND t.user_id = :user_id
              AND t.deleted = FALSE
            """).params(user_id=user.id, today=today).first()
        if row:
            noted = row.time
        self.noted = noted
        self.remaining = since_morning_hours - noted
        self.arrival = arrival
开发者ID:Rhenan,项目名称:intranet-open,代码行数:34,代码来源:subscribers.py

示例7: add_time

def add_time(user_id, date, bug_id, project_id, hours, subject):
    # try finding existing entry for this bug
    session = DBSession()
    bug_id = str(bug_id)
    entry = TimeEntry.query.filter(TimeEntry.user_id==user_id) \
                           .filter(TimeEntry.date==date.date()) \
                           .filter(TimeEntry.ticket_id==bug_id) \
                           .filter(TimeEntry.project_id==project_id).first()
    if not entry:
        # create new entry
        entry = TimeEntry(
            user_id=user_id,
            date=date.date(),
            time=hours,
            description=subject,
            ticket_id=bug_id,
            project_id = project_id,
            modified_ts=date
        )
        session.add(entry)
        LOG(u'Adding new entry')
    else:
        # update existing entry
        if not entry.frozen:
            entry.time += hours
            entry.modified_ts = date # TODO: this might remove an already existing lateness
            session.add(entry)
            LOG(u'Updating existing entry')
        else:
            LOG(u'Omission of an existing entry because it is frozen')
开发者ID:KenjiTakahashi,项目名称:intranet,代码行数:30,代码来源:timeentry.py

示例8: post

    def post(self):
        tracker_id = self.request.GET.get('tracker_id')
        tracker =  Tracker.query.get(tracker_id)
        credentials = self._get_current_users_credentials_for_tracker(tracker)
        form = TrackerLoginForm(self.request.POST, obj=credentials)

        _add_tracker_login_validator(tracker.name, form)

        if form.validate():
            if credentials is None:
                credentials = TrackerCredentials(
                    user_id=self.request.user.id,
                    tracker_id=tracker.id,
                    login=form.login.data,
                    password=form.password.data,
                )
                DBSession.add(credentials)
            else:
                credentials.login=form.login.data
                credentials.password=form.password.data
            self.flash(self._(u"Credentials saved"))
            LOG(u"Credentials saved")
            url = self.request.url_for('/tracker/list')
            return HTTPFound(location=url)
        return dict(form=form, tracker=tracker)
开发者ID:Rhenan,项目名称:intranet-open,代码行数:25,代码来源:tracker.py

示例9: post

    def post(self):
        if not self.request.is_xhr:
            return HTTPBadRequest()

        date = self.v['date']
        form = TimeEntryForm(self.request.POST)

        if form.validate():
            project_id = form.project_id.data
            time = TimeEntry(
                date = date,
                user_id = self.request.user.id,
                time = form.time.data,
                description = form.description.data,
                ticket_id = form.ticket_id.data,
                project_id = project_id if project_id else None
            )
            DBSession.add(time)
            LOG(u'Ajax - Time entry added')

            entries = self._get_time_entries(date)
            total_sum = sum(entry.time for (tracker, entry) in entries if not entry.deleted)
            template = render(
                '/times/_list.html',
                dict(entries=entries, total_sum=total_sum),
                request=self.request
            )

            return dict(status='success', html=template)

        errors = u'<br />'.join((u"%s - %s" % (field, u', '.join(errors)) for field, errors in form.errors.iteritems()))
        return dict(status='error', errors=errors)
开发者ID:Rhenan,项目名称:intranet-open,代码行数:32,代码来源:__init__.py

示例10: post

    def post(self):
        lateness = self.request.json.get('lateness')
        form = LateApplicationForm(MultiDict(**lateness), user=self.request.user)
        if form.validate():
            date = form.popup_date.data
            explanation = form.popup_explanation.data
            in_future = date > datetime.date.today()
            late = Late(
                user_id=self.request.user.id,
                date=date,
                explanation=explanation,
                justified=in_future or None,
                late_start=form.late_start.data,
                late_end=form.late_end.data,
                work_from_home=form.work_from_home.data,
            )

            DBSession.add(late)
            memcache.delete(MEMCACHED_NOTIFY_KEY % date)

            if in_future and is_production:
                event_id = self._add_event(date, explanation)

            return dict(
                entry=True
            )

        self.request.response.status = 400
        return form.errors
开发者ID:Rhenan,项目名称:intranet-open,代码行数:29,代码来源:lateness.py

示例11: dispatch

 def dispatch(self):
     form = ClientAddForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         coordinator_id = int(form.coordinator_id.data) if form.coordinator_id.data.isdigit() else None
         client = Client(
             name=form.name.data,
             google_card=form.google_card.data,
             google_wiki=form.google_wiki.data,
             color=form.color.data,
             selector=form.selector.data,
             emails=form.emails.data,
             coordinator_id=coordinator_id,
             street=form.street.data,
             city=form.city.data,
             postcode=form.postcode.data,
             nip=form.nip.data,
             note=form.note.data,
             wiki_url=form.wiki_url.data,
             mailing_url=form.mailing_url.data
         )
         DBSession.add(client)
         DBSession.flush()
         self.flash(self._(u"New client added"))
         LOG(u"Client added")
         return HTTPFound(location=self.request.url_for("/client/view", client_id=client.id))
     return dict(form=form)
开发者ID:Rhenan,项目名称:intranet-open,代码行数:26,代码来源:client.py

示例12: dispatch

 def dispatch(self):
     form = SprintForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         project = Project.query.get(int(form.project_id.data))
         sprint = Sprint(
             name=form.name.data,
             client_id=project.client_id,
             project_id=project.id,
             team_id=form.team_id.data or None,
             bugs_project_ids = map(int, form.bugs_project_ids.data),
             start=form.start.data,
             end=form.end.data,
             board=form.board.data,
             goal=form.goal.data,
             retrospective_note = form.retrospective_note.data,
         )
         DBSession.add(sprint)
         DBSession.flush()
         self.flash(self._(u"New sprint added"))
         LOG(u"Sprint added")
         url = self.request.url_for('/scrum/sprint/show', sprint_id=sprint.id)
         return HTTPFound(location=url)
     return dict(
         form=form,
     )
开发者ID:Rhenan,项目名称:intranet-open,代码行数:25,代码来源:sprint.py

示例13: calculate_velocities

    def calculate_velocities(self):
        self.velocity = \
            8.0 * self.achieved_points / self.worked_hours \
            if self.worked_hours else 0.0

        self.story_velocity = \
            8.0 * self.achieved_points / self.bugs_worked_hours \
            if self.bugs_worked_hours else 0.0

        sprint_velocities = DBSession.query(
            Sprint.velocity,
            Sprint.story_velocity,
        ).filter(Sprint.project_id == self.project_id) \
            .filter(Sprint.id != self.id) \
            .all()

        sprint_velocities.append((self.velocity, self.story_velocity))

        velocities, story_velocities = zip(*sprint_velocities)

        self.velocity_mean = float(sum(velocities)) / len(velocities)

        self.story_velocity_mean = \
            float(sum(story_velocities)) / len(story_velocities)

        DBSession.add(self)
开发者ID:Rhenan,项目名称:intranet-open,代码行数:26,代码来源:sprint.py

示例14: dispatch

 def dispatch(self):
     client_id = self.request.GET.get('client_id')
     client = Client.query.get(client_id)
     form = ProjectForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         tracker_id = form.tracker_id.data
         coordinator_id = int(form.coordinator_id.data) if form.coordinator_id.data.isdigit() else None
         project = Project(
             client=client,
             name=form.name.data,
             coordinator_id=coordinator_id,
             tracker_id=tracker_id,
             turn_off_selectors=form.turn_off_selectors.data,
             project_selector=form.project_selector.data,
             component_selector=form.component_selector.data,
             version_selector=form.version_selector.data,
             ticket_id_selector=form.ticket_id_selector.data,
             active=form.active.data,
             google_card=form.google_card.data,
             google_wiki=form.google_wiki.data,
             mailing_url=form.mailing_url.data,
             working_agreement=form.working_agreement.data,
             definition_of_done=form.definition_of_done.data,
             definition_of_ready=form.definition_of_ready.data,
             continuous_integration_url=form.continuous_integration_url.data,
             backlog_url=form.backlog_url.data,
             status = form.status.data,
         )
         DBSession.add(project)
         DBSession.flush()
         self.flash(self._(u"Project added"))
         LOG(u"Project added")
         SelectorMapping.invalidate_for(tracker_id)
         return HTTPFound(location=self.request.url_for('/client/view', client_id=project.client_id))
     return dict(client=client, form=form)
开发者ID:Rhenan,项目名称:intranet-open,代码行数:35,代码来源:__init__.py

示例15: dispatch

    def dispatch(self):
        form = AbsenceCreateForm(self.request.POST, request=self.request)
        days, mandated, used, left = 0, 0, 0, 0
        if form.popup_date_start.data:
            mandated, used, left = user_leave(self.request, form.popup_date_start.data.year)
            if form.popup_date_end.data:
                days = h.get_working_days(form.popup_date_start.data, form.popup_date_end.data)
                left -= days
        if self.request.method == 'POST' and form.validate():
            date_start = form.popup_date_start.data
            date_end = form.popup_date_end.data
            type = form.popup_type.data
            remarks = form.popup_remarks.data
            user_id = form.popup_user_id.data
            absence = Absence(
                user_id=user_id,
                date_start=date_start,
                date_end=date_end,
                days=days,
                type=type,
                remarks=remarks,
            )
            DBSession.add(absence)
            return Response(self._('Done') + RELOAD_PAGE)

        return dict(
            form=form,
            days=days,
            mandated=mandated,
            used=used,
            left=left
        )
开发者ID:Rhenan,项目名称:intranet-open,代码行数:32,代码来源:form.py


注:本文中的intranet3.models.DBSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。