def put(self, milestone_id, milestone):
        """Modify this milestone.

        :param milestone_id: An ID of the milestone.
        :param milestone: A milestone within the request body.
        """

        milestone_dict = milestone.as_dict(omit_unset=True)

        if milestone.expiration_date:
            abort(400, _("Can't change expiration date."))

        if "expired" in six.iterkeys(milestone_dict):
            if milestone_dict["expired"]:
                milestone_dict["expiration_date"] = datetime.now(tz=pytz.utc)
            else:
                milestone_dict["expiration_date"] = None

        if milestone.branch_id:
            original_milestone = milestones_api.milestone_get(milestone_id)

            if not original_milestone:
                raise exc.NotFound(_("Milestone %s not found") % milestone_id)

            if milestone.branch_id != original_milestone.branch_id:
                abort(400, _("You can't associate milestone %s "
                             "with another branch.") % milestone_id)

        result = milestones_api.milestone_update(milestone_id, milestone_dict)

        if result:
            return wmodels.Milestone.from_db_model(result)
        else:
            raise exc.NotFound(_("Milestone %s not found") % milestone_id)
Exemple #2
0
    def put(self, milestone_id, milestone):
        """Modify this milestone.

        :param milestone_id: An ID of the milestone.
        :param milestone: A milestone within the request body.
        """

        milestone_dict = milestone.as_dict(omit_unset=True)

        if milestone.expiration_date:
            abort(400, _("Can't change expiration date."))

        if "expired" in six.iterkeys(milestone_dict):
            if milestone_dict["expired"]:
                milestone_dict["expiration_date"] = datetime.now(tz=pytz.utc)
            else:
                milestone_dict["expiration_date"] = None

        if milestone.branch_id:
            original_milestone = milestones_api.milestone_get(milestone_id)

            if not original_milestone:
                raise exc.NotFound(_("Milestone %s not found") % milestone_id)

            if milestone.branch_id != original_milestone.branch_id:
                abort(400, _("You can't associate milestone %s "
                             "with another branch.") % milestone_id)

        result = milestones_api.milestone_update(milestone_id, milestone_dict)

        if result:
            return wmodels.Milestone.from_db_model(result)
        else:
            raise exc.NotFound(_("Milestone %s not found") % milestone_id)
Exemple #3
0
    def get_one(self, milestone_id):
        """Retrieve information about the given milestone.

        :param milestone_id: Milestone ID.
        """

        milestones = milestones_api.milestone_get(milestone_id)

        if milestones:
            return wmodels.Milestone.from_db_model(milestones)
        else:
            raise exc.NotFound(_("Milestone %s not found") % milestone_id)
    def get_one(self, milestone_id):
        """Retrieve information about the given milestone.

        :param milestone_id: Milestone ID.
        """

        milestones = milestones_api.milestone_get(milestone_id)

        if milestones:
            return wmodels.Milestone.from_db_model(milestones)
        else:
            raise exc.NotFound(_("Milestone %s not found") % milestone_id)
Exemple #5
0
    def get_all(self,
                marker=None,
                limit=None,
                name=None,
                branch_id=None,
                sort_field='id',
                sort_dir='asc'):
        """Retrieve a list of milestones.

        :param marker: The resource id where the page should begin.
        :param limit: The number of milestones to retrieve.
        :param name: Filter milestones based on name.
        :param branch_id: Filter milestones based on branch_id.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).
        """
        # Boundary check on limit.
        if limit is not None:
            limit = max(0, limit)

        # Resolve the marker record.
        marker_milestone = milestones_api.milestone_get(marker)

        milestones = \
            milestones_api.milestone_get_all(marker=marker_milestone,
                                             limit=limit,
                                             name=name,
                                             branch_id=branch_id,
                                             sort_field=sort_field,
                                             sort_dir=sort_dir)
        milestones_count = \
            milestones_api.milestone_get_count(
                name=name,
                branch_id=branch_id)

        # Apply the query response headers.
        if limit:
            response.headers['X-Limit'] = str(limit)
        response.headers['X-Total'] = str(milestones_count)
        if marker_milestone:
            response.headers['X-Marker'] = str(marker_milestone.id)

        return [wmodels.Milestone.from_db_model(m) for m in milestones]
Exemple #6
0
def milestone_is_valid(task):
    """Check that milestone exists, milestone and task associated with the
    same branch and milestone is not expired.
    """

    milestone_id = task.milestone_id
    milestone = milestones_api.milestone_get(milestone_id)

    if not milestone:
        raise exc.NotFound(_("Milestone %s not found.") %
                           milestone_id)

    if milestone['expired']:
        abort(400, _("You can't associate task to expired milestone %s.")
              % milestone_id)

    if task.branch_id and milestone.branch_id != task.branch_id:
        abort(400, _("Milestone %(m_id)s doesn't associate "
                     "with branch %(b_id)s.")
              % {'m_id': milestone_id, 'b_id': task.branch_id})
    def get_all(self, marker=None, limit=None, name=None, branch_id=None,
                sort_field='id', sort_dir='asc'):
        """Retrieve a list of milestones.

        :param marker: The resource id where the page should begin.
        :param limit: The number of milestones to retrieve.
        :param name: Filter milestones based on name.
        :param branch_id: Filter milestones based on branch_id.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).
        """
        # Boundary check on limit.
        if limit is not None:
            limit = max(0, limit)

        # Resolve the marker record.
        marker_milestone = milestones_api.milestone_get(marker)

        milestones = \
            milestones_api.milestone_get_all(marker=marker_milestone,
                                             limit=limit,
                                             name=name,
                                             branch_id=branch_id,
                                             sort_field=sort_field,
                                             sort_dir=sort_dir)
        milestones_count = \
            milestones_api.milestone_get_count(
                name=name,
                branch_id=branch_id)

        # Apply the query response headers.
        if limit:
            response.headers['X-Limit'] = str(limit)
        response.headers['X-Total'] = str(milestones_count)
        if marker_milestone:
            response.headers['X-Marker'] = str(marker_milestone.id)

        return [wmodels.Milestone.from_db_model(m) for m in milestones]