Ejemplo n.º 1
0
    def commit_new_case(self):
        case_type = CaseType.query.get(self.case_type.data)
        region = Region.query.get(self.case_region.data)
        case_status = CaseStatus.query.get(self.case_status.data)
        case_lead = User.query.get(self.case_lead.data)

        case = Case.create(
            crd_number=self.crd_number.data,
            case_name=self.case_name.data,
            case_desc=self.case_desc.data,
            start_date=self.start_date.data,
            end_date=self.end_date.data,
            case_type=case_type,
            region=region,
            case_status=case_status,
        )

        # add case lead to staff table
        lead = CaseStaffMap.create(user_id=case_lead.id,
                                   case_id=case.id,
                                   primary=True)
        lead.save()

        # if case creator not admin and not case lead, auto add to case staff
        if not current_user.is_admin:
            if current_user != case_lead:
                CaseStaffMap.create(user=current_user, case=case).save()

        return case
Ejemplo n.º 2
0
    def __init__(self, case_id, db_field_name, *args, **kwargs):
        super(PageDownForm, self).__init__(*args, **kwargs)
        self.case_id = case_id
        self.db_field_name = db_field_name
        case = Case.get_by_id(self.case_id)

        if request.method != 'POST':
            self.pagedown.data = getattr(case, self.db_field_name)
Ejemplo n.º 3
0
def view(case_id=0):
    lead, staff, tasks = queries.single_case_staff(case_id)
    case = Case.get_by_id(case_id)
    if not case:
        abort(404)

    return render_template('case/case.html',
                           case=case,
                           lead=lead,
                           staff=staff,
                           tasks=tasks)
Ejemplo n.º 4
0
def view(case_id=0):
  lead, staff, tasks = queries.single_case_staff(case_id)
  case = Case.get_by_id(case_id)
  if not case:
    abort(404)

  return render_template('case/case.html', case=case, lead=lead, staff=staff,
                         tasks=tasks)
Ejemplo n.º 5
0
def view(task_id=0):
  task = Task.get_by_id(task_id)
  creator = User.get_by_id(task.creator_id)
  parent = Case.get_by_id(task.case_id)
  if not task:
    abort(404)

  return render_template('task/task.html', task=task, creator=creator,
                         parent=parent)
Ejemplo n.º 6
0
    def commit_updates(self):
        """
    type: IO ()
    commit updates to database
    :raise ValueError:
    :returns None
    """
        case = Case.get_by_id(self.case_id)

        tags = []
        if self.tag_values:
            for t in self.tag_values:
                tag = Tag.query.filter(Tag.kind == self.tag_kind,
                                       Tag.tag == t).first()
                if tag:
                    tags.append(tag)
                else:
                    tags.append(Tag.create(kind=self.tag_kind, tag=t))

        case.tags = tags + [
            i for i in Tag.query.filter(Tag.kind != self.tag_kind)
        ]
        case.save()
        return None
Ejemplo n.º 7
0
    def __init__(self, case_id, kind, *args, **kwargs):
        """

    :param case_id: int
    :param kind: must be one of 'risk', 'non_qau_staff'
    """
        super(CaseTagsForm, self).__init__(*args, **kwargs)
        self.case_id = case_id
        if kind not in {'risk', 'non_qau_staff'}:
            raise ValueError(
                'tag "kind" must be one of: "risk", "non_qau_staff"')
        self.tag_kind = kind
        self.case_tags.choices = [(i.tag, i.tag)
                                  for i in Case.get_by_id(case_id).tags
                                  if i.kind == self.tag_kind]
        self.tag_values = None
Ejemplo n.º 8
0
    def __init__(self, case_id, *args, **kwargs):
        super(EditCoreCaseForm, self).__init__(*args, **kwargs)
        self.case_id = case_id
        self.current_case = Case.get_by_id(self.case_id)

        # This step is needed for bypassing a defaulting of the SelectField bug
        # we set the default by making the first element of the list the
        # default value
        case_types = [(unicode(i.id), i.code) for i in CaseType.query]
        if self.current_case.case_type.id:
            for c, (i, d) in enumerate(case_types):
                if i == self.current_case.case_type.id:
                    case_types.insert(0, case_types.pop(c))
                    break
        self.case_type.choices = case_types
        regions = [(unicode(i.id), i.code) for i in Region.query]
        if self.current_case.region.id:
            for c, (i, d) in enumerate(regions):
                if i == self.current_case.region.id:
                    regions.insert(0, regions.pop(c))
        self.case_region.choices = regions

        case_staff = [(unicode(i.id), i.full_name) for i in User.query]
        lead, _, _ = single_case_staff(self.case_id)
        if lead:
            for c, (i, d) in enumerate(case_staff):
                if i == unicode(lead[0].id):
                    case_staff.insert(0, case_staff.pop(c))
        self.case_lead.choices = case_staff

        case_status = [(unicode(i.id), i.type) for i in CaseStatus.query]
        self.case_status.choices = case_status

        if request.method != 'POST':
            if self.current_case.case_status:
                self.case_status.default = self.current_case.case_status.id
                self.process()

            self.crd_number.data = self.current_case.crd_number
            self.case_name.data = self.current_case.case_name
            self.start_date.data = self.current_case.start_date
            self.end_date.data = self.current_case.end_date
Ejemplo n.º 9
0
class PageDownForm(Form):
    pagedown = PageDownField('Enter your markdown')
    submit = SubmitField('Submit')

    def __init__(self, case_id, db_field_name, *args, **kwargs):
        super(PageDownForm, self).__init__(*args, **kwargs)
        self.case_id = case_id
        self.db_field_name = db_field_name
        case = Case.get_by_id(self.case_id)

        if request.method != 'POST':
            self.pagedown.data = getattr(case, self.db_field_name)

    def validate(self):
        initial_validation = super(PageDownForm, self).validate()
        if not initial_validation:
            return False
        return True

    def commit_updates(self):
        case = Case.get_by_id(self.case_id)
        setattr(case, self.db_field_name, self.pagedown.data)
        case.save()
        return None
Ejemplo n.º 10
0
class CaseStaffForm(Form):
    contractors = SelectMultipleField(label='QAU Contractor Resources',
                                      validators=[Optional()],
                                      coerce=int)
    qau_staff = SelectMultipleField(label='QAU Full Time Resources',
                                    validators=[Optional()],
                                    coerce=int)

    def __init__(self, case_id, *args, **kwargs):
        super(CaseStaffForm, self).__init__(*args, **kwargs)
        self.case_id = case_id

        self.contractors.choices = [(i.id, i.username) for i in User.query
                                    if i.is_contractor]
        self.qau_staff.choices = [(i.id, i.username) for i in User.query
                                  if i.is_permanent]

        if request.method != 'POST':
            staff = db.session.query(User). \
              join('user_cases', 'case'). \
              filter(User.user_cases.any(case_id=case_id)). \
              filter(CaseStaffMap.primary != 1).all()

            self.contractors.default = [
                unicode(i.id) for i in staff if i.is_contractor
            ]
            self.qau_staff.default = [
                unicode(i.id) for i in staff if i.is_permanent
            ]
            self.process()

    def validate(self):
        initial_validation = super(CaseStaffForm, self).validate()
        if not initial_validation:
            return False
        return True

    def commit_updates(self):

        case = Case.get_by_id(self.case_id)

        staff = db.session.query(User). \
          join('user_cases', 'case'). \
          filter(User.user_cases.any(case_id=self.case_id)).all()

        # set of previously assigned users
        prev_assigned = set([i.id for i in staff])
        # set of what the new assignment should be
        all_assigned = set(self.contractors.data + self.qau_staff.data)
        # set of to be removed entries
        prev_assigned_remove = prev_assigned.difference(all_assigned)
        # set of all the new users added to the case
        new_assigned_add = all_assigned.difference(prev_assigned)

        # start removing the old entries
        for user_id in prev_assigned_remove:
            user = User.get_by_id(user_id)
            case.users.remove(user)
        case.save()

        # add in the new changes
        for user_id in new_assigned_add:
            user = User.get_by_id(user_id)
            # at some point we will need to toggle primary or not, this is
            # how you set that flag
            CaseStaffMap.create(user=user, case=case).save()

        return None