Ejemplo n.º 1
0
def demand_create(request):
    if request.method == 'GET':
        form = DemandCreateForm()
        return render(request, 'flow_create.html', {'form': form})
    elif request.method == 'POST':
        form = DemandCreateForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data['title']
            remark = form.cleaned_data['remark']
            executor = form.cleaned_data['executor']
            start_dt = form.cleaned_data['start_dt']
            end_dt = form.cleaned_data['end_dt']
            u = Employee.objects.get(user=request.user)
            obj = Flow(flow_type='demand',
                       title=title,
                       initiator=u.user,
                       remark=remark,
                       state='start',
                       executor=executor,
                       start_dt=start_dt,
                       end_dt=end_dt)
            obj.save()
            obj_node = FlowNode(operator=u.user,
                                operate='start',
                                remark=remark,
                                flowid=obj,
                                executor=executor)
            obj_node.save()
        return redirect('flow_submit')
Ejemplo n.º 2
0
    def setUp(self):
        self.flow = Flow()

        self.flow.name = "Test"
        self.flow.description = "A test flow"

        #self.flow.expires      = timezone.now() + datetime.timedelta(days=1)

        self.flow.save()

        self.flow.destination = '1.2.3.4/32'
        self.flow.source = '4.3.2.1/23'

        self.flow.protocol_set.create(protocol=12)
        self.flow.protocol_set.create(protocol=123)

        self.flow.port_set.create(port_number=23)
        self.flow.port_set.create(port_number=234, direction="source-port")

        self.flow.packetlength_set.create(packet_length=23)
        self.flow.packetlength_set.create(packet_length='>432')

        self.flow.dscp_set.create(dscp='<2')

        self.flow.icmp_set.create(icmp_type=3, icmp_code=0)
        self.flow.icmp_set.create(icmp_type=1)

        self.flow.tcpflag_set.create(tcp_flag=2)

        self.flow.fragment_set.create(fragment=8)

        self.flow.active = True
        self.flow.save()
Ejemplo n.º 3
0
def flow_create(request):
    if request.method == 'GET':
        form = FlowForm()
        return render(request, 'flow_create.html', {'form': form})
    elif request.method == 'POST':
        form = FlowForm(request.POST)
        if form.is_valid():
            flow_type = form.cleaned_data['flow_type']
            remark = form.cleaned_data['remark']
            u = Employee.objects.get(user=request.user)
            obj = Flow(flow_type=flow_type,
                       initiator=u.user,
                       remark=remark,
                       state='start',
                       executor=u.leader)
            obj.save()
            obj_node = FlowNode(operator=u.user,
                                operate='start',
                                remark=remark,
                                flowid=obj,
                                executor=u.leader)
            obj_node.save()
        return redirect('flow_submit')
Ejemplo n.º 4
0
product = Product.objects.get(name='Venezuelan Beaver Cheese')
product.number_sold += 1
product.save()

from django.contrib.auth.models import User
from flow.models import Flow,FlowNode,Employee
# 发起人信息从request.user中获取,通过i获取employee对象

u=Employee.objects.get(user=request.user)
<Employee: Employee object>
u.user
<User: rencs>
u.leader
<User: wangbin>
# 分别保存工作流和工作流节点两个对象
obj=Flow(flow_type='work',initiator=u.user,remark='test',state='init',executor=u.leader)
obj.save()

obj_node=FlowNode(operator=u.user,operate='init',remark='test',flowid=obj,executor=u.leader)
obj_node.save()
# 以上是用户创建表单时候的初始化,用户和用户leader数据从request.user取
# 以下是用户leader的审批,工作流id从url中传入,obj=Flow.objects.get(id=obj.id)
u2=Employee.objects.get(user=request.user)
# 从url中获取当前审批工作流的id,获取工作流对象,leader审批后新增一条工作流节点信息。并更新当前工作流对象。
obj=Flow.objects.get(id=obj.id)
obj_node2=FlowNode(operator=u2.user,operate='ok',remark='test',flowid=obj,executor=u2.leader)
obj_node2.save()

obj.state='doing'
obj.executor=u2.leader
obj.save()