Initial commit
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# created at 15-6-27
|
||||
# coding=utf-8
|
||||
__author__ = 'zhugl'
|
||||
@@ -0,0 +1,54 @@
|
||||
# created at 15-6-30
|
||||
# coding=utf-8
|
||||
__author__ = 'zhugl'
|
||||
|
||||
|
||||
class Operation(object):
|
||||
APPROVE = 1
|
||||
DENY = 3
|
||||
TERMINATE = 4
|
||||
|
||||
|
||||
class WorkflowAction(object):
|
||||
|
||||
name = ''
|
||||
description = ''
|
||||
|
||||
def action(self,request,obj,node_config,operation=Operation.APPROVE):
|
||||
"""
|
||||
|
||||
:param request:
|
||||
:param obj:
|
||||
:param node_config:
|
||||
:return:
|
||||
"""
|
||||
|
||||
|
||||
class TestAction(WorkflowAction):
|
||||
name = 'action.test'
|
||||
|
||||
def action(self,request,obj,node_config,operation=Operation.APPROVE):
|
||||
print 'this is a workflow test action'
|
||||
print 'request user is %s,current node is %s'%(request.user,node_config)
|
||||
|
||||
|
||||
class WorkflowActionManager(object):
|
||||
"""
|
||||
|
||||
"""
|
||||
actions = {}
|
||||
registed = False
|
||||
|
||||
def __init__(self):
|
||||
if WorkflowActionManager.registed:
|
||||
pass
|
||||
else:
|
||||
WorkflowActionManager.register(TestAction)
|
||||
WorkflowActionManager.registed = True
|
||||
|
||||
@classmethod
|
||||
def register(cls,action):
|
||||
if cls.actions.get(action.name):
|
||||
raise Exception('%s already exists,register failed'%action.name)
|
||||
if issubclass(action,WorkflowAction):
|
||||
WorkflowActionManager.actions[action.name] = action()
|
||||
@@ -0,0 +1,54 @@
|
||||
# created at 15-6-30
|
||||
# coding=utf-8
|
||||
__author__ = 'zhugl'
|
||||
from workflow.models import Node
|
||||
|
||||
|
||||
class NextNodeHandler(object):
|
||||
"""
|
||||
|
||||
"""
|
||||
name = ''
|
||||
description = ''
|
||||
|
||||
def handle(self,request,obj,node_config):
|
||||
"""
|
||||
|
||||
:param request:
|
||||
:param obj:
|
||||
:param node_config:
|
||||
:return:workflow.models.Node
|
||||
"""
|
||||
return None
|
||||
|
||||
|
||||
class TestHandler(NextNodeHandler):
|
||||
name = 'project.budge.gt.10000'
|
||||
description = '预算金额大于10000,由总经理审批'
|
||||
|
||||
def handle(self,request,obj,node_config):
|
||||
budget = getattr(obj,'budget',None)
|
||||
if budget and budget > 10000:
|
||||
return Node.objects.filter(id=7).all()
|
||||
|
||||
|
||||
class NextNodeManager(object):
|
||||
"""
|
||||
|
||||
"""
|
||||
handlers = {}
|
||||
registed = False
|
||||
|
||||
def __init__(self):
|
||||
if NextNodeManager.registed:
|
||||
pass
|
||||
else:
|
||||
NextNodeManager.register(TestHandler)
|
||||
NextNodeManager.registed = True
|
||||
|
||||
@classmethod
|
||||
def register(cls,handler):
|
||||
if cls.handlers.get(handler.name):
|
||||
raise Exception('%s already exists,register failed'%handler.name)
|
||||
if issubclass(handler,NextNodeHandler):
|
||||
NextNodeManager.handlers[handler.name] = handler()
|
||||
@@ -0,0 +1,67 @@
|
||||
# created at 15-6-30
|
||||
# coding=utf-8
|
||||
__author__ = 'zhugl'
|
||||
|
||||
|
||||
class NextUserHandler(object):
|
||||
"""
|
||||
|
||||
"""
|
||||
name = ''
|
||||
description = ''
|
||||
|
||||
def handle(self,request,obj,node_config):
|
||||
"""
|
||||
|
||||
:param request:
|
||||
:param obj:
|
||||
:param node_config:
|
||||
:return:django.contrib.auth.models.User[]
|
||||
"""
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class UpPosition(NextUserHandler):
|
||||
"""
|
||||
|
||||
"""
|
||||
name = 'up.position.user'
|
||||
|
||||
def handle(self,request,obj,node_config):
|
||||
from basedata.models import Employee,Position
|
||||
emp_query = Employee.objects.filter(user=request.user)
|
||||
if emp_query.count()>0:
|
||||
emp = emp_query.all()
|
||||
parent = []
|
||||
for e in emp:
|
||||
if e.position and e.position.parent:
|
||||
parent.append(e.position.parent)
|
||||
# print emp
|
||||
# print parent
|
||||
query2 = Employee.objects.filter(position__in=parent).exclude(user=None)
|
||||
return [x.user for x in query2.all()]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
class NextUserManager(object):
|
||||
"""
|
||||
|
||||
"""
|
||||
handlers = {}
|
||||
registed = False
|
||||
|
||||
def __init__(self):
|
||||
if NextUserManager.registed:
|
||||
pass
|
||||
else:
|
||||
NextUserManager.register(UpPosition)
|
||||
NextUserManager.registed = True
|
||||
|
||||
@classmethod
|
||||
def register(cls,handler):
|
||||
if cls.handlers.get(handler.name):
|
||||
raise Exception('%s already exists,register failed'%handler.name)
|
||||
if issubclass(handler,NextUserHandler):
|
||||
NextUserManager.handlers[handler.name] = handler()
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
# created at 15-6-27
|
||||
# coding=utf-8
|
||||
__author__ = 'zhugl'
|
||||
import xlrd
|
||||
import os
|
||||
import datetime
|
||||
from mis import settings
|
||||
|
||||
|
||||
class Handler(object):
|
||||
name = ''
|
||||
|
||||
def handle(self,obj,f):
|
||||
pass
|
||||
|
||||
|
||||
class OPSHandler(Handler):
|
||||
"""
|
||||
导入基础信息:部门,岗位,职员
|
||||
"""
|
||||
name = 'OPS'
|
||||
|
||||
def handle(self,obj,f):
|
||||
if f and f.name.endswith('.xls'):
|
||||
path = os.path.join(settings.MEDIA_ROOT,f.name)
|
||||
workbook = xlrd.open_workbook(path)
|
||||
for sheet in workbook.sheets():
|
||||
if sheet.name == u'部门' or sheet.name == 'department':
|
||||
self.department(obj,sheet)
|
||||
elif sheet.name == u'岗位' or sheet.name == 'position':
|
||||
self.position(obj,sheet)
|
||||
elif sheet.name == u'职员' or sheet.name == 'employee':
|
||||
self.stuff(obj,sheet)
|
||||
|
||||
def department(self,obj,sheet):
|
||||
from organ.models import OrgUnit
|
||||
row_count = sheet.nrows
|
||||
if obj.is_clear:
|
||||
OrgUnit.objects.update(end=datetime.date.today())
|
||||
for row_index in range(1,row_count):
|
||||
row = sheet.row_values(row_index)
|
||||
weight = 99
|
||||
if row[6]:
|
||||
weight = row[6]
|
||||
OrgUnit.objects.create(code=row[0],name=row[1],short=row[2],pinyin=row[3],begin=datetime.date.today(),
|
||||
end=datetime.date(9999,12,31),weight=weight)
|
||||
for row_index in range(1,row_count):
|
||||
row = sheet.row_values(row_index)
|
||||
if len(row[4]) > 0:
|
||||
try:
|
||||
parent = OrgUnit.objects.get(code=row[4])
|
||||
OrgUnit.objects.filter(code=row[0]).update(parent=parent)
|
||||
except Exception,e:
|
||||
pass
|
||||
|
||||
def position(self,obj,sheet):
|
||||
from organ.models import Position,OrgUnit
|
||||
row_count = sheet.nrows
|
||||
if obj.is_clear:
|
||||
Position.objects.update(end=datetime.date.today())
|
||||
for row_index in range(1,row_count):
|
||||
row = sheet.row_values(row_index)
|
||||
depart = None
|
||||
if len(row[4]) > 0:
|
||||
try:
|
||||
depart = OrgUnit.objects.filter(code=row[4],end__gt=datetime.date.today()).all()[0]
|
||||
except Exception,e:
|
||||
pass
|
||||
weight = 99
|
||||
if row[6]:
|
||||
weight = row[6]
|
||||
Position.objects.create(code=row[0],name=row[1],unit=depart,begin=datetime.date.today(),
|
||||
end=datetime.date(9999,12,31),weight=weight)
|
||||
for row_index in range(1,row_count):
|
||||
row = sheet.row_values(row_index)
|
||||
if len(row[2]) > 0:
|
||||
try:
|
||||
parent = Position.objects.filter(code=row[2],end__gt=datetime.date.today()).all()[0]
|
||||
Position.objects.filter(code=row[0]).update(parent=parent)
|
||||
except Exception,e:
|
||||
pass
|
||||
|
||||
def stuff(self,obj,sheet):
|
||||
from organ.models import Position
|
||||
from basedata.models import Employee
|
||||
from django.contrib.auth.models import User,Group
|
||||
row_count = sheet.nrows
|
||||
try:
|
||||
group = Group.objects.get_by_natural_key(u'职员')
|
||||
except Exception,e:
|
||||
pass
|
||||
for row_index in range(1,row_count):
|
||||
row = sheet.row_values(row_index)
|
||||
position = Position.objects.filter(code=row[8],end__gt=datetime.date.today()).all()[0]
|
||||
username = row[10]
|
||||
email = row[11]
|
||||
password = row[4][-6:]
|
||||
if position is None:
|
||||
raise Exception(u'职员%s-%s未分配岗位,或者您选择的岗位已失效,不可被引用'%(row[0],row[1]))
|
||||
try:
|
||||
employee = Employee.objects.get(code=row[0])
|
||||
if employee.position.code == row[8]:
|
||||
continue
|
||||
else:
|
||||
employee.position = position
|
||||
employee.save()
|
||||
except Exception,e:
|
||||
employee = Employee.objects.create(code=row[0],name=row[1],pinyin=row[2],gender=row[3],idcard=row[4],
|
||||
birthday=row[5],workday=row[6],startday=row[7],position=position)
|
||||
if username:
|
||||
try:
|
||||
user = User.objects.get_by_natural_key(username)
|
||||
except Exception,e:
|
||||
user = User.objects.create_user(username=username,password=password)
|
||||
user.is_staff = True
|
||||
user.is_active = True
|
||||
user.first_name = row[1]
|
||||
if email:
|
||||
user.email = email
|
||||
if group:
|
||||
user.groups.add(group)
|
||||
user.save()
|
||||
employee.user = user
|
||||
employee.save()
|
||||
|
||||
|
||||
class UserHandler(Handler):
|
||||
"""
|
||||
基础数据导入:用户
|
||||
"""
|
||||
name = 'admin.user'
|
||||
|
||||
def handle(self,obj,f):
|
||||
from django.contrib.auth.models import User,Group
|
||||
if f and f.name.endswith('.xls'):
|
||||
path = os.path.join(settings.MEDIA_ROOT,f.name)
|
||||
workbook = xlrd.open_workbook(path)
|
||||
sheet = workbook.sheet_by_index(0)
|
||||
row_count = sheet.nrows
|
||||
try:
|
||||
group = Group.objects.get_by_natural_key(u'职员')
|
||||
except Exception,e:
|
||||
pass
|
||||
|
||||
for row_index in range(2,row_count):
|
||||
row = sheet.row_values(row_index)
|
||||
username = row[0]
|
||||
password = row[1]
|
||||
last_name = row[2]
|
||||
first_name = row[3]
|
||||
email = row[4]
|
||||
if username == '':
|
||||
continue
|
||||
try:
|
||||
user = User.objects.get_by_natural_key(username)
|
||||
except Exception,e:
|
||||
user = User.objects.create_user(username=username,password=password,email=email)
|
||||
user.is_staff = True
|
||||
user.is_active = True
|
||||
user.last_name = last_name
|
||||
user.first_name = first_name
|
||||
if group:
|
||||
user.groups.add(group)
|
||||
user.save()
|
||||
|
||||
|
||||
class ExcelManager(object):
|
||||
"""
|
||||
|
||||
"""
|
||||
handlers = {}
|
||||
|
||||
def __init__(self):
|
||||
ExcelManager.register(OPSHandler)
|
||||
ExcelManager.register(UserHandler)
|
||||
|
||||
@classmethod
|
||||
def register(cls,handler):
|
||||
if cls.handlers.get(handler.name):
|
||||
raise Exception('%s already exists,register failed'%handler.name)
|
||||
if issubclass(handler,Handler):
|
||||
ExcelManager.handlers[handler.name] = handler()
|
||||
|
||||
Reference in New Issue
Block a user