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


Python DBSession.add方法代码示例

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


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

示例1: dispatch

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
 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,代码行数:37,代码来源:__init__.py

示例2: dispatch

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
 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,代码行数:27,代码来源:sprint.py

示例3: post

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
    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,代码行数:27,代码来源:tracker.py

示例4: dispatch

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
    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,代码行数:34,代码来源:form.py

示例5: calculate_velocities

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
    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,代码行数:28,代码来源:sprint.py

示例6: add_time

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
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,代码行数:32,代码来源:timeentry.py

示例7: dispatch

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
    def dispatch(self):
        client_id = self.request.GET.get('client_id')
        client = Client.query.get(client_id)
        form = ClientForm(self.request.POST, obj=client)
        if self.request.method == 'POST' and form.validate():
            coordinator_id = int(form.coordinator_id.data) if form.coordinator_id.data.isdigit() else None

            client.name = form.name.data
            client.active = client.active
            client.google_card = form.google_card.data
            client.google_wiki = form.google_wiki.data
            client.color=form.color.data
            client.selector = form.selector.data
            client.emails = form.emails.data
            client.coordinator_id = coordinator_id
            client.street = form.street.data
            client.city = form.city.data
            client.postcode = form.postcode.data
            client.nip = form.nip.data
            client.note = form.note.data
            client.wiki_url = form.wiki_url.data
            client.mailing_url = form.mailing_url.data

            DBSession.add(client)
            self.flash(self._(u"Client saved"))
            LOG(u"Client saved")
            return HTTPFound(location=self.request.url_for("/client/view", client_id=client.id))
        projects = client.projects
        return dict(client_id=client.id, form=form, projects=projects)
开发者ID:Rhenan,项目名称:intranet-open,代码行数:31,代码来源:client.py

示例8: post

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
    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,代码行数:34,代码来源:__init__.py

示例9: post

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
    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,代码行数:37,代码来源:list.py

示例10: make_admin

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
def make_admin(config_path):
    from intranet3.models import DBSession, Base
    from intranet3.models import User
    user_login = sys.argv[-1]
    if len(sys.argv) < 4:
        print u"Provide user login"
        return

    session = DBSession()

    user = session.query(User).filter(User.email==user_login).first()

    if not user:
        print u"No such user: %s" % user_login
        return

    if 'admin' in user.groups:
        print u'Removing %s from group admin' % user.name
        groups = list(user.groups)
        groups.remove('admin')
        user.groups = groups
    else:
        print u'Adding %s to group admin' % user.name
        groups = list(user.groups)
        groups.append('admin')
        user.groups = groups

    session.add(user)
    transaction.commit()
开发者ID:KenjiTakahashi,项目名称:intranet,代码行数:31,代码来源:__init__.py

示例11: post

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
    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,代码行数:31,代码来源:lateness.py

示例12: __call__

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
    def __call__(self, *args, **kwargs):
        config = ApplicationConfig.get_current_config(allow_empty=True)
        if config is None:
            WARN(u'Application config not found, emails cannot be checked')
            return
        trackers = dict(
            (tracker.mailer, tracker)
                for tracker in Tracker.query.filter(Tracker.mailer != None).filter(Tracker.mailer != '')
        )
        if not len(trackers):
            WARN(u'No trackers have mailers configured, email will not be checked')
            return

        username = config.google_user_email.encode('utf-8')
        password = config.google_user_password.encode('utf-8')

        # TODO
        logins_mappings = dict(
            (tracker.id, TrackerCredentials.get_logins_mapping(tracker))
                for tracker in trackers.itervalues()
        )
        selector_mappings = dict(
            (tracker.id, SelectorMapping(tracker))
                for tracker in trackers.itervalues()
        )

        # find all projects connected to the tracker
        projects = dict(
            (project.id, project)
                for project in Project.query.all()
        )

        # all pre-conditions should be checked by now

        # start fetching
        fetcher = MailFetcher(
            username,
            password,
        )

        # ok, we have all mails, lets create timeentries from them
        extractor = TimeEntryMailExtractor(
            trackers,
            logins_mappings,
            projects,
            selector_mappings,
        )

        for msg in fetcher:
            timeentry = extractor.get(msg)
            if timeentry:
                DBSession.add(timeentry)
        transaction.commit()
开发者ID:Rhenan,项目名称:intranet-open,代码行数:55,代码来源:mail_fetcher.py

示例13: create_config

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
def create_config(env):
    from intranet3.models import *
    import transaction
    config = ApplicationConfig(
        office_ip='',
        google_user_email='',
        google_user_password='',
        holidays_spreadsheet='',
        hours_employee_project='',
    )
    DBSession.add(config)
    transaction.commit()
开发者ID:KenjiTakahashi,项目名称:intranet,代码行数:14,代码来源:__init__.py

示例14: dispatch

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
    def dispatch(self):
        subpage = self.request.GET.get('subpage', 'general')
        if subpage not in ['general', 'reports', 'spreadsheets', 'access']:
            return HTTPForbidden()

        config_obj = ApplicationConfig.get_current_config(allow_empty=True)

        FormRef = getattr(config_forms, "%sForm"% subpage.title())

        if config_obj is not None:
            LOG(u"Found config object from %s" % (config_obj.date, ))
            form = FormRef(self.request.POST, obj=config_obj)
        else:
            LOG(u"Config object not found")
            form = FormRef(self.request.POST)

        if self.request.method == 'POST' and form.validate():
            if config_obj is None:
                config_obj =  ApplicationConfig()

            # Add/Edit data
            if subpage == 'general':
                config_obj.office_ip = form.office_ip.data
                config_obj.google_user_email = form.google_user_email.data
                config_obj.google_user_password = form.google_user_password.data
                config_obj.cleaning_time_presence = form.cleaning_time_presence.data
                config_obj.absence_project_id = form.absence_project_id.data if form.absence_project_id.data else None
                config_obj.monthly_late_limit = form.monthly_late_limit.data
                config_obj.monthly_incorrect_time_record_limit = form.monthly_incorrect_time_record_limit.data
            elif subpage == 'reports':
                config_obj.reports_project_ids = [int(id) for id in form.reports_project_ids.data]
                config_obj.reports_omit_user_ids = [int(id) for id in form.reports_omit_user_ids.data]
                config_obj.reports_without_ticket_project_ids = [int(id) for id in form.reports_without_ticket_project_ids.data]
                config_obj.reports_without_ticket_omit_user_ids = [int(id) for id in form.reports_without_ticket_omit_user_ids.data]
            elif subpage == 'spreadsheets':
                config_obj.holidays_spreadsheet = form.holidays_spreadsheet.data
                config_obj.hours_employee_project = form.hours_employee_project.data
                config_obj.hours_ticket_user_id = form.hours_ticket_user_id.data if form.hours_ticket_user_id.data else None
            elif subpage == "access":
                config_obj.freelancers = form.freelancers.data

            DBSession.add(config_obj)
            config_obj.invalidate_office_ip()

            LOG(u"Config object saved")
            self.flash(self._(u'Application Config saved'), klass='success')
            return HTTPFound(location=self.request.url_for('/config/view', subpage=subpage))

        return dict(
            form=form,
            subpage=subpage
        )
开发者ID:Rhenan,项目名称:intranet-open,代码行数:54,代码来源:config.py

示例15: post

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import add [as 别名]
 def post(self):
     form = WrongTimeJustificationForm(self.request.POST, user=self.request.user)
     if form.validate():
         wrongtime = WrongTime(
             user_id=self.request.user.id,
             date=form.popup_date.data,
             explanation=form.popup_explanation.data,
         )
         DBSession.add(wrongtime)
         LOG(u"WrongTime added")
         response = '%s %s' % (self._(u'Explanation added'), CHANGE_STATUS % self._('Waits for verification'))
         return Response(response)
     return dict(form=form)
开发者ID:Rhenan,项目名称:intranet-open,代码行数:15,代码来源:form.py


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