Operation and maintenance Ticket--server request a total order

Source: Internet
Author: User

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/71/F9/wKioL1XcF Q_Q wub3aage4q-v2aw789.jpg "title=" Boke.png "alt=" wkiol1xcf Q_Q wub3aage4q-v2aw789.jpg "/>

Server to apply for a public order, encountered three difficult points

The first is the front-end page of the new public order, server applications, not necessarily only one, there may be two, three, each server configuration requirements may also be different, so need to dynamically add server public order, I realized that the Click button Add row will add a new row of server table, Click Remove to delete a row of server tables

Front-end HTML:

                <thead>                          <tr>                       <th> Equipment Type </th>                        <th> HDD </th>                       <th> Memory </th>                        <th>cpu</th>                                          <th> Quantity </th>                       <th> Operations </th>                     </tr >                   </thead>                   <tbody id= "Tbody" >                     <tr id= "TR" >                        <td>                       <select name= "Device_type"  >                 <option value= "Windows" >windows</option>                 <option value= " Linux ">linux</option>                       </select>                       </td>                        <td><input class= "Span11"  id= "Id_title"  maxlength= " " Placeholder= "Like 500G"  name= "Disk" &Nbsp;type= "text"  required= "required" ></td>                       <td><input class= " Span11 " id=" Id_title " maxlength=" " placeholder=" such as 8G " name=" Memory " type=" text "  required= "Required" ></td>                       <td class= "Center" ><input  class= "Span11"  id= "Id_title"  maxlength= " placeholder=" such as 8 " name=" CPU " type=" Text " required=" required "></td>                       <td class= "Center" >< input class= "Span11"  id= "Id_title"  maxlength= " placeholder=" such as 2 " name=" number "  type= "text"  required= "RequirEd "></td>                        <td><input type= "button"  value= "Remove"  onclick= "Removerow (this.parentNode.parentNode)" ></td>                     </tr>                     </ Tbody>

jquery:

<script type= "Text/javascript" >function removerow (r) {    var root  = r.parentnode;    var allrows = root.getelementsbytagname (' tr ')     if (allrows.length>1)          Root.removechild (R);     else        alert ("Only  one row left, you not need to remove it. "); Function addrow () { $ ("#tbody"). Append (' <tr id= "tr" ><td><select name= "device _type "><option value=" Windows ">windows</option><option value=" Linux ">linux</ option></select></td><td><input class= "Span11"  id= "Id_title"  maxlength= " required=" "Required"  name= "Disk"  type= "text" ></td><td><input class= " Span11 " required=" required "  id=" id_tItle " maxlength="  name= "Memory"  type= "text" ></td><td class= "center" >< input class= "Span11"  id= "Id_title"  maxlength= ""  name= "CPU"  type= "text"   Required= "Required" ></td><td class= "center" ><input required= "required"  class= "Span11"  id= "Id_title"  maxlength= ""  name= "number"  type= "text" ></td><td> <input  type= "button"  value= "Remove"  onclick= "Removerow (This.parentNode.parentNode)" ></td></tr> ');}

The first idea is to clone the code, and later test found that the clone code will even the first row of server table content is cloned into the new server table, so instead of directly add code, in AddRow () directly append written code, test results are good

The second backend data acquisition and data access, if the server to create a public order, when the request for more than one server, then the name attribute Memory,disk,nmuber and so on the backend will get to a dictionary format data, such as the backend obtained

Request. POST:

<querydict: {u ' creator ': [u ' mujibin '], U ' title ': [u ' \u6e38\u620f\u670d\u52a1\u5668\u7533\u8bf7 '], u ' number ': [u ' 2 ', U ' 1 '], U ' note ': [u '], u ' approveuser ': [u ' \u5434\u542f\u8d85 '], U ' device_type ': [u ' Linux ', U ' Linux '], u ' memory ': [u ' 8G ', U ' 8G '], u ' disk ': [u ' 500G ', U ' 500G '], U ' type ': [u ' \u670d\u52a1\u5668\u7533\u8bf7 '], U ' CPU ': [u ' 8 ', U ' 8 ']}>

So you need to loop out, re-form the list, and then into the database:

Back-end View:

if request.method ==  ' POST ':                 req_dic={}                 for k in request. post:                     req_dic[k]=request. Post.getlist (k) # Fetch data                  note=req_dic[' Note '][0]                 note=note.encode (' Utf-8 ')                  title=req_dic[' title '][0]                 title=title.encode (' Utf-8 ')                                   number=[] # the memory, HDD, CPU, number, device type, form list                  disk=[]                 memory=[]                 cpu=[]                 device_type=[]                 for i in range (len (req_dic[' disk ')):                     number.append (req_ dic[' number '][i].encode ("Utf-8"))                   &nBsp;  disk.append (req_dic[' Disk '][i].encode ("Utf-8"))                      memory.append (req_dic[' memory '] [ I].encode ("Utf-8"))                      cpu.append (req_dic[' CPU '][i].encode ("Utf-8"))                      device_type.append ( req_dic[' Device_type '][i].encode ("Utf-8"))                     d=task (Number=number,note=note,disk=disk,memory=memory,device_ TYPE=DEVICE_TYPE,TITLE=TITLE,APPROVEUSER=APPROVEUSER,APPROVEUSER_ID=APPROVEUSER_ID,CPU=CPU,TYPE=TYPE_ID, Creator=name,state= ' awaiting approval ', state_id=1)                  d.save ()                data= Task.objects.filter (Creator=name). order_by ('-id ') [0:1]                  #send_email_server. Delay (subject= ' ticket message notification ', content=data,to_name_list= Leader_ename_mail_list)                  return httpresponseredirect ('/index/')               else:                               pass                 return  Render_to_response (' add_server_b.html ', {' name ': Name, ' Task_type ': Task_type, ' Approveuser ': Approveuser})

The third difficulty, front-end server application public order, details display page, the front-end can not judge to show the server application data have several servers, so there is no way to write dead code in the front end, need to judge the server to request the number of servers in public order, composition code, to the front end

Back-end Display view:

if table ==  ' Details_worklist ':                 passelif table ==  ' Details_server ':          all_data=task.objects.filter (Id=id). All ()           for i in all_data:                 number=eval (i.number) # list is stored in the database and then read it, the type is not a list type, you need to re-convert to the list type                  device_type=eval ( I.device_type)                  Memory=eval (i.memory)                  disk=eval (I.disk)                  cpu=eval (I.CPU) &Nbsp;               create_time= I.create_time.strftime ("%y-%m-%d %h:%i:%s")            Html_list=[]          for i in range (len (CPU) ):                 prev= ' <tr ><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s </td><td>%s</td></tr> '  %  (Device_type[i],disk[i],memory[i],cpu[i],number[i], Create_time)                  Html_list.append (prev)           html_list=mark_safe (". Join" ( html_list))           return render_to_response (' details _server.html ', {' resUlt ': all_data, ' name ': Name, ' html_list ': html_list } ' elif table ==  ' Details_task ':                  pass

Front-end HTML:

                <thead>                 <tr>                    <th> Equipment Type </th>                   <th> HDD </th>                   <th> Memory </th>                   <th>cpu</th>                   <th> Quantity </th>                   <th> creation Time </Th>                </tr >              </thead>               <tbody id= "Tbody" >                 <tr id = "TR" >                   {{ html_list }}                 </tr>                 </tbody>

Show:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/71/FD/wKiom1XcGvWiLXuIAAEzoKw9E4c086.jpg "title=" Boke1.png "alt=" Wkiom1xcgvwilxuiaaezokw9e4c086.jpg "/>

This article is from the "Python Random Notes" blog, so be sure to keep this source http://6252961.blog.51cto.com/6242961/1688074

Operation and maintenance Ticket--server request a total order

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.