示例#1
0
def create_query(args, q):
  valid = True
  user_id = args.get('user_id')
  type = args.get('type')
  if user_id:

    if user_id == "me":
      user = User.get_by_id(current_user.id)
    else:
      try:
        user_id = int(user_id)
        user = User.get_by_id(user_id)
      except ValueError:
        flash('Invalid User Id Entered')
        valid = False
    if valid:
      if type == 'assigned':
        q = q.filter(Task.assignees.any(id=user.id))
        title = "My Assigned Tasks"

      elif type == 'created':
        q = q.filter(Task.creator_id==user.id)
        title = "My Created Tasks"

      else:
        None
        title = "Query Results"

  return valid, q, title
示例#2
0
文件: views.py 项目: quaintm/octopus
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)
示例#3
0
文件: utils.py 项目: quaintm/octopus
def create_query(args, q):
  conditions = []
  joins = set()
  valid = True
  user_id = args.get('user_id')
  if user_id:
    if user_id == "me":
      user = User.get_by_id(current_user.id)
    else:
      try:
        user_id = int(user_id)
        user = User.get_by_id(user_id)
      except ValueError:
        flash('Invalid User Id Entered')
        valid = False
    if valid:
      q = q.join(CaseStaffMap, User).filter(
        CaseStaffMap.user_id == user.id)

  return valid, q
示例#4
0
文件: forms.py 项目: quaintm/octopus
  def __init__(self, user_id, *args, **kwargs):
    super(EditUserProfile, self).__init__(*args, **kwargs)
    self.user = User.get_by_id(user_id)
    self.username.placeholder = "Username"
    self.email.placeholder = "Email Address"
    self.first_name.placeholder = "First Name"
    self.last_name.placeholder = "Last Name"

    if not request.method == 'POST':
      self.username.data = self.user.username
      self.email.data = self.user.email
      self.first_name.data = self.user.first_name
      self.last_name.data = self.user.last_name
示例#5
0
def register():
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        new_user = User.create(username=form.username.data,
                               email=form.email.data,
                               password=form.password.data,
                               active=True)
        new_user.save()
        flash('New user created.')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
示例#6
0
    def commit_updates(self):
        if self.case_name.data:
            self.current_case.case_name = self.case_name.data
        if self.crd_number.data:
            self.current_case.crd_number = self.crd_number.data
        if self.start_date.data:
            self.current_case.start_date = self.start_date.data
        if self.end_date.data:
            self.current_case.end_date = self.end_date.data
        if self.case_type.data:
            case_type = CaseType.query.get(self.case_type.data)
            self.current_case.case_type = case_type
        if self.case_region.data:
            region = Region.query.get(self.case_region.data)
            self.current_case.region = region

        # TODO: This edit field doesn't currently work D:
        if self.case_status.data:
            case_status = CaseStatus.query.get(self.case_status.data)
            self.current_case.case_status = case_status

        if self.case_lead.data:
            # we can be sure that this won't throw an error -- it must be a
            # valid choice to make it here
            new_lead_id = int(self.case_lead.data)

            old_leads = CaseStaffMap.query.filter_by(case_id=self.case_id,
                                                     primary=True).all()

            if old_leads:
                change_in_lead = False
                for old_lead in old_leads:
                    # Just in case there's a double mapping somehow, kill it
                    # (thats why we loop through there should be just a single entry)
                    if old_lead.id != new_lead_id:
                        change_in_lead = True
                        old_lead.delete(commit=True)
            else:
                change_in_lead = True

            if change_in_lead:
                # We don't want to do this lest we need to
                user = User.get_by_id(new_lead_id)
                # at some point we will need to toggle primary or not,
                # this is how you set that flag
                CaseStaffMap.create(user=user,
                                    case=self.current_case,
                                    primary=True).save()

        self.current_case.save()
        return None
示例#7
0
 def prepare(self):
     # Simple auth
     user_name = self.get_query_argument('user', default=None)
     user_token = self.get_query_argument('t', default=None)
     user = User.get(user_name)
     if user_name and user is None:
         raise HTTPError(403, 'user_name_not_found:%s' % user_name,
                         reason='user_name_not_found')
     if user and user_token != user.token:
         raise HTTPError(403,
                         'user_token_unmatched:%s,%s' % (user_name,
                                                         user_token),
                         'user_token_unmatched')
     self.user = user.id if user else None
     logger.debug('User %s', user_name)
示例#8
0
文件: forms.py 项目: quaintm/octopus
    def commit_new_task(self):
        task = Task.create(task_name=self.task_name.data,
                           task_desc=self.task_desc.data,
                           start_date=self.start_date.data,
                           end_date=self.end_date.data,
                           case_id=int(self.parent_case.data),
                           creator_id=current_user.id)

        assigned_users = []
        for i in self.assignees.data:
            assigned_users.append(User.get_by_id(i))

        task.assignees = assigned_users
        task.save()

        return task
示例#9
0
文件: forms.py 项目: quaintm/octopus
    def commit_updates(self):
        if self.task_name.data:
            self.current_task.task_name = self.task_name.data
        if self.task_desc.data:
            self.current_task.task_desc = self.task_desc.data
        if self.start_date.data:
            self.current_task.start_date = self.start_date.data
        if self.end_date.data:
            self.current_task.end_date = self.end_date.data
        if self.parent_case.data:
            self.current_task.case_id = self.parent_case.data

        assigned_users = []
        if self.assignees.data:
            for i in self.assignees.data:
                assigned_users.append(User.get_by_id(i))

            self.current_task.assignees = assigned_users

        self.current_task.save()
示例#10
0
 def test_check_password(self):
   user = User.create(username="******", email="*****@*****.**",
                      password="******")
   assert user.check_password('foobarbaz123') is True
   assert user.check_password("barfoobaz") is False
示例#11
0
 def test_password_is_nullable(self):
   user = User(username='******', email='*****@*****.**')
   user.save()
   assert user.password is None
示例#12
0
 def test_created_at_defaults_to_datetime(self):
   user = User(username='******', email='*****@*****.**')
   user.save()
   assert bool(user.created_at)
   assert isinstance(user.created_at, dt.datetime)
示例#13
0
  def test_get_by_id(self):
    user = User('foo', '*****@*****.**')
    user.save()

    retrieved = User.get_by_id(user.id)
    assert retrieved == user
示例#14
0
 def get(self):
     users = User.list()
     data = {'data': [user.to_dict() for user in users]}
     self.write(data)
示例#15
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
示例#16
0
def load_user(id):
    return User.get_by_id(int(id))