Beispiel #1
0
def create(project_id,task_name,priority,assign_to,description,creator):
    session = database.get_session()
    task_name = task_name.strip()
    t = Task()
    t.ProjectId = project_id
    t.TaskName = task_name
    t.Priority = priority
    t.Progress = 0
    if assign_to == -1:
        t.AssignTo = creator
    else:
        t.AssignTo = assign_to
    assign_to = t.AssignTo
    t.Effort = 0
    t.Status = TaskStatus.New
    t.Description = description
    t.Creator = creator
    t.CreateDate = datetime.now()
    t.LastUpdateDate = datetime.now()

    session.add(t)
    session.commit()
    session.close()

    calcprogress(project_id)

    if ENABLE_MAIL_NOTICE:
        u = userservice.get_user_by_id(assign_to)
        body = mailservice.render_mail_template('Task/NoticeAssignTo.html',TaskName=task_name,Description=description,SystemUrl=HOST)
        mailservice.send_mail(u.Email, u'指派给您的新任务 ' + task_name,body)
Beispiel #2
0
def get(project_id):
    session = database.get_session()

    p = session.query(Project).options(joinedload(Project.UserProfile)).filter(Project.ProjectId == project_id).one()

    session.close()
    return p
Beispiel #3
0
def update(task_id,task_name,assign_to,priority,progress,status,effort,description):
    session = database.get_session()

    task_name = task_name.strip()
    task = session.query(Task).filter(Task.TaskId == task_id).one()

    changeAssignTo = not (task.AssignTo == assign_to)

    task.TaskName = task_name
    task.AssignTo = assign_to
    task.Priority = priority
    task.Progress = progress
    task.Status = status
    task.Description = description
    task.Effort = task.Effort + float(effort)
    task.LastUpdateDate = datetime.now()
    project_id = task.ProjectId
    session.commit()
    session.close()

    calcprogress(project_id)

    if ENABLE_MAIL_NOTICE and changeAssignTo:
        u = userservice.get_user_by_id(assign_to)
        body = mailservice.render_mail_template('Task/NoticeAssignTo.html',TaskName=task_name,Description=description,SystemUrl=HOST)
        mailservice.send_mail(u.Email, u'指派给您的新任务 ' + task_name,body)

    return True
Beispiel #4
0
def query(task_name,assign_to,status_new,status_in_progress,status_completed,status_canceled,order_by,page_no):
    session = database.get_session()

    filters = []
    status = []

    task_name = task_name.strip()
    if len(task_name) > 0:
        filters.append(Task.TaskName.like('%' + task_name + '%'))
    if not assign_to == 0:
        filters.append(Task.AssignTo == assign_to)
    if status_new:
        status.append(TaskStatus.New)
    if status_in_progress:
        status.append(TaskStatus.InProgress)
    if status_completed:
        status.append(TaskStatus.Completed)
    if status_canceled:
        status.append(TaskStatus.Canceled)
    if len(status) > 0:
        filters.append(Task.Status.in_(status))

    q = session.query(Task).join(UserProfile,UserProfile.UserId == Task.Creator).join(UserProfile,UserProfile.UserId == Task.AssignTo)
    for f in filters:
        q = q.filter(f)
    (row_count,page_count,page_no,page_size,data) = database.pager(q,order_by,page_no,PAGESIZE)

    session.close()
    return (row_count,page_count,page_no,page_size,data)
Beispiel #5
0
def create(project_id,subject,priority,assign_to,description,category_id,creator):
    session = database.get_session()
    subject = subject.strip()
    issue = Issue()
    issue.ProjectId = project_id
    issue.CategoryId = category_id
    issue.Subject = subject
    issue.Priority = priority
    issue.Description = description
    issue.Status = IssueStatus.Open
    if int(assign_to) == -1:
        issue.AssignTo = creator
    else:
        issue.AssignTo = assign_to
    assign_to=issue.AssignTo
    issue.Creator = creator
    issue.CreateDate = datetime.now()
    issue.LastUpdateDate = datetime.now()

    session.add(issue)
    session.commit()
    session.close()

    if ENABLE_MAIL_NOTICE:
        u = userservice.get_user_by_id(assign_to)
        body = mailservice.render_mail_template('Issue/NoticeAssignTo.html',Subject=subject,Description=description,SystemUrl=HOST)
        mailservice.send_mail(u.Email, u'指派给您的新问题 ' + subject,body)
Beispiel #6
0
def enable_user(user_id):
    session = database.get_session()

    user = session.query(UserProfile).filter(UserProfile.UserId == user_id).update({'Status':UserStatus.Enabled})

    session.commit()
    session.close()
Beispiel #7
0
def disable_category(categoryid):
    session = database.get_session()

    user = session.query(IssueCategory).filter(IssueCategory.CategoryId == categoryid).update({'Status':IssueCategoryStatus.Disabled})

    session.commit()
    session.close()
Beispiel #8
0
def query(subject,assign_to,category_id,status_open,status_fixed,status_closed,status_canceled,order_by,page_no):
    session = database.get_session()

    filters = []
    status = []

    subject = subject.strip()
    if len(subject) > 0:
        filters.append(Issue.Subject.like('%' + subject + '%'))
    if not assign_to == 0:
        filters.append(Issue.AssignTo == assign_to)
    if not category_id == -1:
        filters.append(Issue.CategoryId == category_id)
    if status_open:
        status.append(IssueStatus.Open)
    if status_fixed:
        status.append(IssueStatus.Fixed)
    if status_closed:
        status.append(IssueStatus.Closed)
    if status_canceled:
        status.append(IssueStatus.Canceled)
    if len(status) > 0:
        filters.append(Issue.Status.in_(status))

    q = session.query(Issue).join(UserProfile,UserProfile.UserId == Issue.Creator).join(UserProfile,UserProfile.UserId == Issue.AssignTo)
    for f in filters:
        q = q.filter(f)
    (row_count,page_count,page_no,page_size,data) = database.pager(q,order_by,page_no,PAGESIZE)

    session.close()
    return (row_count,page_count,page_no,page_size,data)
Beispiel #9
0
def get(issue_id):
    session = database.get_session()

    issue = session.query(Issue).options(joinedload(Issue.CreatorProfile),joinedload(Issue.AssignToProfile),joinedload(Issue.Category)).filter(Issue.IssueId == issue_id).one()

    session.close()
    return issue
Beispiel #10
0
def get(task_id):
    session = database.get_session()

    task = session.query(Task).options(joinedload(Task.CreatorProfile)).filter(Task.TaskId == task_id).one()

    session.close()
    return task
Beispiel #11
0
def reset_password(user_id):
    session = database.get_session()

    user = session.query(UserProfile).filter(UserProfile.UserId == user_id).update({'Password': DEFAULT_PASSWORD})

    session.commit()
    session.close()
Beispiel #12
0
def member_candidate(project_id):
    session = database.get_session()

    projectMember = session.query(Member.UserId).filter(Member.ProjectId == project_id)
    candidate = session.query(UserProfile).filter(UserProfile.Status == UserStatus.Enabled,not_(UserProfile.UserId.in_(projectMember)))

    session.close()
    return candidate
Beispiel #13
0
def member_in_project(project_id):
    session = database.get_session()

    projectMember = session.query(Member.UserId).filter(Member.ProjectId == project_id)
    memberList = session.query(UserProfile).filter(UserProfile.Status == UserStatus.Enabled,UserProfile.UserId.in_(projectMember))

    session.close()
    return memberList
Beispiel #14
0
def get_history(issue_id):
    session = database.get_session()

    history_list = session.query(IssueHistory).options(joinedload(IssueHistory.RawAssignToProfile),joinedload(IssueHistory.NewAssignToProfile),joinedload(IssueHistory.CreatorProfile),joinedload(IssueHistory.RawIssueCategory),joinedload(IssueHistory.NewIssueCategory)).filter(IssueHistory.IssueId == issue_id)

    session.close()

    return history_list
Beispiel #15
0
def delete(issue_id):
    session = database.get_session()

    session.query(Issue).filter(Issue.IssueId == issue_id).delete()
    session.query(IssueHistory).filter(IssueHistory.IssueId == issue_id).delete()

    session.commit()
    session.close()
Beispiel #16
0
def exist_category(categoryname):
    session = database.get_session()

    c = session.query(IssueCategory).filter(IssueCategory.CategoryName == categoryname).count()

    session.close()

    return c > 0
Beispiel #17
0
def delete(project_id):
    session = database.get_session()

    session.query(Member).filter(Member.ProjectId == project_id).delete()
    session.query(Task).filter(Task.ProjectId == project_id).delete()
    session.query(Project).filter(Project.ProjectId == project_id).delete()

    session.commit()
    session.close()
Beispiel #18
0
def calcprogress(project_id):
    session = database.get_session()

    all_project_task = session.query(Task).filter(Task.ProjectId == project_id).count()
    complete_project_task = session.query(Task).filter(Task.ProjectId == project_id).filter(Task.Status.in_([TaskStatus.Completed,TaskStatus.Canceled])).count()

    session.query(Project).filter(Project.ProjectId == project_id).update({'Progress':(complete_project_task * 100.0 / all_project_task),'LastUpdateDate':datetime.now()})
    session.commit()
    session.close()
Beispiel #19
0
def assign_admin(user_id):
    session = database.get_session()

    user = session.query(UserProfile).filter(UserProfile.UserId == user_id).one()

    user.IsAdmin = not user.IsAdmin

    session.commit()
    session.close()
Beispiel #20
0
def statistics(project_id):
    session = database.get_session()

    issue_status = session.query(Issue.Status,func.count(Issue.Status)).filter(Issue.ProjectId == project_id).group_by(Issue.Status).all()
    issue_priority = session.query(Issue.Priority,func.count(Issue.Priority)).filter(Issue.ProjectId == project_id).group_by(Issue.Priority).all()

    session.commit()
    session.close()

    return (issue_status,issue_priority)
Beispiel #21
0
def delete(task_id):
    session = database.get_session()

    task = session.query(Task).filter(Task.TaskId == task_id).one()
    project_id = task.ProjectId
    session.delete(task)
    session.commit()
    session.close()

    calcprogress(project_id)
Beispiel #22
0
def statistics(project_id):
    session = database.get_session()

    task_status = session.query(Task.Status,func.count(Task.Status)).filter(Task.ProjectId == project_id).group_by(Task.Status).all()
    task_priority = session.query(Task.Priority,func.count(Task.Priority)).filter(Task.ProjectId == project_id).group_by(Task.Priority).all()

    session.commit()
    session.close()

    return (task_status,task_priority)
Beispiel #23
0
def create_category(categoryname):
    session = database.get_session()

    c = IssueCategory()
    c.CategoryName = categoryname.strip()
    c.Status = IssueCategoryStatus.Enabled

    session.add(c)

    session.commit()
    session.close()
Beispiel #24
0
def update(project_id, project_name, status):
    session = database.get_session()

    session.query(Project).filter(Project.ProjectId == project_id).update(
        {"ProjectName": project_name.strip(), "Status": status, "LastUpdateDate": datetime.now()}
    )

    session.commit()
    session.close()

    return True
Beispiel #25
0
def change_password(raw_password,new_password,user_id):
    session = database.get_session()

    user = session.query(UserProfile).filter(UserProfile.UserId == user_id).first()
    if not user.Password == raw_password:
        session.close()
        return False
    user.Password = new_password

    session.commit()
    session.close()
    return True
Beispiel #26
0
def remove_member(project_id,user_id):
    session = database.get_session()

    session.query(Member).filter(Member.ProjectId == project_id,Member.UserId == user_id).delete()

    session.commit()
    session.close()

    if ENABLE_MAIL_NOTICE:
        p = projectservice.get(project_id)
        u = userservice.get_user_by_id(user_id)
        body = mailservice.render_mail_template('Team/RemoveMember.html',ProjectName=p.ProjectName,SystemUrl=HOST)
        mailservice.send_mail(u.Email, u'您已经被 ' + p.ProjectName + u' 项目组移除',body)
Beispiel #27
0
def add_member(project_id,email):
    session = database.get_session()

    user = userservice.get(email)

    member = Member()
    member.ProjectId = project_id
    member.UserId = user.UserId

    session.add(member)
    session.commit()
    session.close()

    if ENABLE_MAIL_NOTICE:
        p = projectservice.get(project_id)
        body = mailservice.render_mail_template('Team/AddMember.html',ProjectName=p.ProjectName,SystemUrl=HOST)
        mailservice.send_mail(email,p.ProjectName + u' 项目组欢迎您的加入 :)',body)
Beispiel #28
0
def query_user(mail_or_nick,status,order_by,page_no):
    session = database.get_session()

    filters = []
    if len(mail_or_nick) > 0:
        filters.append(or_(UserProfile.Email.like('%' + mail_or_nick + '%'), UserProfile.Nick.like('%' + mail_or_nick + '%')))
    if not status == -1:
        filters.append(UserProfile.Status == status)

    q = session.query(UserProfile)
    for f in filters:
        q = q.filter(f)

    (row_count,page_count,page_no,page_size,data) = database.pager(q,order_by,page_no,PAGESIZE)
    session.close()

    return (row_count,page_count,page_no,page_size,data)
Beispiel #29
0
def create(project_name, creator):
    session = database.get_session()

    p = Project()
    p.ProjectName = project_name.strip()
    p.Status = ProjectStatus.InProgress
    p.Progress = 0
    p.Creator = creator
    p.CreateDate = datetime.now()
    p.LastUpdateDate = datetime.now()

    m = Member()
    m.UserId = creator
    p.Members.append(m)

    session.add(p)
    session.commit()
    session.close()
Beispiel #30
0
def query(project_name, status, page_no, order_by, current_user):
    filters = []
    project_name = project_name.strip()
    if len(project_name) > 0:
        filters.append(Project.ProjectName.like("%" + project_name + "%"))
    if not status == "-1":
        filters.append(Project.Status == status)

    session = database.get_session()

    project_list = session.query(Member.ProjectId).filter(Member.UserId == current_user)

    q = session.query(Project).filter(Project.ProjectId.in_(project_list))
    for f in filters:
        q = q.filter(f)
    (row_count, page_count, page_no, page_size, data) = database.pager(q, order_by, page_no)

    session.close()
    return (row_count, page_count, page_no, page_size, data)