Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. models.py
  2. ------------
  3. UNIT_CHOICES = (
  4. ('dumb_terminal', 'Dumb Terminal'),
  5. ('computer', 'Computer'),
  6. )
  7.  
  8. class Unit(models.Model):
  9. unittype = models.CharField( choices=UNIT_CHOICES)
  10.  
  11. forms.py
  12. ------------
  13. class GenericForm(ModelForm):
  14. class Meta:
  15. model = Inventory_Unit
  16.  
  17. class computerForm(ModelForm):
  18. class Meta:
  19. model = Inventory_Unit
  20. fields = ('make', 'model', 'serial', 'drive_number', 'asset_tag', 'asset_tag_2')
  21.  
  22.  
  23.  
  24. views.py
  25. ------------
  26. @login_required
  27. def inventory_freight(request, p_id):
  28.  
  29. shipment = get_object_or_404(Shipment, id=p_id)
  30.  
  31. message = ""
  32.  
  33. addform = ""
  34.  
  35. selection = "No selection"
  36.  
  37. query = request.GET.get('unit_select', '')
  38.  
  39. if query:
  40. if hasattr(forms, query+'Form'):
  41. formClass = getattr(forms, query+'Form')
  42. else:
  43. formClass = forms.GenericForm
  44.  
  45. selection = "You've selected " + query
  46. addform = formClass()
  47.  
  48. if request.method == 'POST':
  49. addform = formClass(request.POST)
  50.  
  51. if addform.is_valid():
  52. instance = addform.save(commit=False)
  53. instance.shipment = shipment
  54. instance.unittype = query
  55. instance.save()
  56. # Form is valid and the new unit has been saved.
  57. # so we'll return a new empty unit for the user to fill in.
  58. form = formClass()
  59. message = "Unit successfully saved."
  60. else:
  61. addform = formClass()
  62. message = "Add "+ query +" Unit"
  63.  
  64. else:
  65. #results = []
  66. selection = "No unit type has been selected..."
  67.  
  68.  
  69. return render_to_response('inventory_shipment.html', {'units': shipment.inventory_unit_set.all(), 'selection': selection, 'shipment': shipment, 'addform': addform, 'UNIT_CHOICES': UNIT_CHOICES,})
  70.  
  71.  
  72.  
  73. template
  74. ---------
  75. {% extends "base_site.html" %}
  76. {% block title %}Order: PCD{{ shipment.id }}<div style="float: right;"><a href="/shiptrack/ci/search/"><input type="button" value="Back to Orders"></a></div>
  77. {% endblock %}
  78. {% block content %}
  79. <b>Company Name:</b> {{ shipment.company }}
  80. <br />
  81. <br />
  82. <div style="float: left; width: 25%">
  83. {{ selection }}<br />
  84. <br />
  85. <form method="get">
  86. <select name='unit_select' size="15" onchange='this.form.submit()'>
  87. <option value = "EMPTY">Choose a unit type...</option>
  88. {% for c in UNIT_CHOICES %}
  89. <option value = "c[0]">c[1]</option>
  90. {% endfor %}
  91. </select>
  92. </form>
  93. </div>
  94. <div style="float: right; width: 73%">
  95. {% if addform %}
  96. <form method="post">
  97. {{ addform.as_p }}
  98. <input type="submit" onmouseover="Tip('Click here to add a unit to this order.')" onmouseout="UnTip()" value="Add Unit" name="Add Unit" />
  99. </form>
  100. {% endif %}
  101. </div>
  102. <br />
  103.  
  104. <div style="clear: both;">&nbsp;<br /></div>
  105.  
  106. {% if units %}
  107. {% for s in units %}
  108. <tr class="{% cycle odd,even %}">
  109. <td><a href="">{{s.unittype}}</a></td>
  110. <td><a href="">{{s.make}}</a></td>
  111. <td><a href="">{{s.model}}</a></td>
  112. <td><a href="">{{s.serial}}</a></td>
  113. <td><a href="">{{s.asset_tag}}</a></td>
  114. </tr>
  115. {% endfor %}
  116. {% else %}
  117. <p>No units.</p>
  118. {% endif %}
  119. {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement