Add asset duplication

This commit is contained in:
Johnathan Graydon
2019-01-13 15:28:37 +00:00
parent 2717133d1c
commit c0a7e962b7
5 changed files with 263 additions and 224 deletions

View File

@@ -8,6 +8,7 @@ class AssetCategory(models.Model):
class Meta:
verbose_name = 'Asset Category'
verbose_name_plural = 'Asset Categories'
name = models.CharField(max_length=80)
def __str__(self):
@@ -18,6 +19,7 @@ class AssetStatus(models.Model):
class Meta:
verbose_name = 'Asset Status'
verbose_name_plural = 'Asset Statuses'
name = models.CharField(max_length=80)
def __str__(self):

View File

@@ -8,6 +8,7 @@
<td>
<a href="{% url 'asset_detail' item.pk %}"><i class="material-icons">visibility</i></a>
<a href="{% url 'asset_update' item.pk %}"><i class="material-icons">edit</i></a>
<a href="{% url 'asset_duplicate' item.pk %}"><i class="material-icons">content_copy</i></a>
</td>
</tr>
{% endfor %}

View File

@@ -8,8 +8,10 @@
<h4>
Asset
{% if object %}
{% if object.id %}
| {{ object.asset_id }}
{% elif duplicate %}
Duplication of {{ object.asset_id }}
{% else %}
Create
{% endif %}
@@ -26,12 +28,19 @@
<div class="col s12">
<div class="button-group right">
{% if edit %}
{# <input type="submit" class="btn" value="Save">#}
{# <input type="submit" class="btn" value="Save">#}
<button type="button" class="btn" onclick="updateAsset()">Save</button>
<a class="waves-effect waves-light btn"
href="{% url 'asset_duplicate' object.pk %}">Duplicate</a>
{% elif duplicate %}
<button type="button" class="btn" onclick="updateAsset()">Create Duplicate</button>
<a href="{% url 'index' %}" class="btn">Cancel</a>
{% else %}
<a href="{% url 'asset_update' object.pk %}" class="btn">Edit</a>
<a class="waves-effect waves-light btn"
href="{% url 'asset_duplicate' object.pk %}">Duplicate</a>
{% endif %}
{% if object %}
{% if object and not duplicate %}
<a class="waves-effect waves-light btn modal-trigger" href="#confirm_delete_modal">Delete</a>
{% endif %}
</div>
@@ -45,10 +54,12 @@
</div>
<div class="panel-body">
<dl class="dl-horizontal">
{% if edit %}
{% if edit or duplicate %}
<div class="row">
<div class="input-field col s12">
{% if object.asset_id %}
{% if duplicate %}
{% render_field form.asset_id value=object.asset_id %}
{% elif object.asset_id %}
{% render_field form.asset_id|attr:'readonly'|add_class:'disabled_input' value=object.asset_id %}
{% else %}
{% render_field form.asset_id %}
@@ -58,13 +69,16 @@
<div class="input-field col s12">
{% render_field form.description value=object.description %}
<label for="{{ form.description.id_for_label }}" class="bold-text">Description</label>
<label for="{{ form.description.id_for_label }}"
class="bold-text">Description</label>
</div>
<div class="input-field col s12">
<select name="{{ form.category.name }}" id="{{ form.category.id_for_label }}" required>
<select name="{{ form.category.name }}" id="{{ form.category.id_for_label }}"
required>
{% for id, choice in form.category.field.choices %}
<option value="{{ id }}" {% if object.category.id == id %}selected{% endif %}>{{ choice }}</option>
<option value="{{ id }}"
{% if object.category.id == id %}selected{% endif %}>{{ choice }}</option>
{% endfor %}
</select>
<label for="{{ form.category.id_for_label }}" class="bold-text">Category</label>
@@ -73,7 +87,8 @@
<div class="input-field col s12">
<select name="{{ form.status.name }}" id="{{ form.status.id_for_label }}" required>
{% for id, choice in form.status.field.choices %}
<option value="{{ id }}" {% if object.status.id == id %}selected{% endif %}>{{ choice }}</option>
<option value="{{ id }}"
{% if object.status.id == id %}selected{% endif %}>{{ choice }}</option>
{% endfor %}
</select>
<label for="{{ form.status.id_for_label }}" class="bold-text">Status</label>
@@ -121,12 +136,14 @@
</div>
<div class="panel-body">
<dl class="dl-horizontal">
{% if edit %}
{% if edit or duplicate %}
<div class="row">
<div class="input-field col s12">
<select name="{{ form.purchased_from.name }}" id="{{ form.purchased_from.id_for_label }}">
<select name="{{ form.purchased_from.name }}"
id="{{ form.purchased_from.id_for_label }}">
{% for id, choice in form.purchased_from.field.choices %}
<option value="{{ id }}" {% if object.purchased_from.id == id %}selected{% endif %}>{{ choice }}</option>
<option value="{{ id }}"
{% if object.purchased_from.id == id %}selected{% endif %}>{{ choice }}</option>
{% endfor %}
</select>
<label for="{{ form.purchased_from.id_for_label }}">Purchased From</label>
@@ -144,7 +161,8 @@
<div class="input-field col s12">
{% render_field form.date_acquired|add_class:'datepicker' value=object.date_acquired|date %}
<label for="{{ form.date_acquired.id_for_label }}" class="bold-text">Date Acquired</label>
<label for="{{ form.date_acquired.id_for_label }}" class="bold-text">Date
Acquired</label>
</div>
<div class="input-field col s12">
@@ -202,12 +220,14 @@
</div>
<div class="panel-body">
<dl class="dl-horizontal">
{% if edit %}
{% if edit or duplicate %}
<div class="row">
<div class="input-field col s10">
<input type="hidden" name="{{ form.parent.html_name }}" id="hidden_parent_id" value="{{ object.parent.id }}">
<input type="text" id="parent_id" value="{{ object.parent|default:'' }}" disabled="">
<input type="hidden" name="{{ form.parent.html_name }}" id="hidden_parent_id"
value="{{ object.parent.id }}">
<input type="text" id="parent_id" value="{{ object.parent|default:'' }}"
disabled="">
<label for="parent_id">Parent</label>
</div>
<div class="col s2">
@@ -218,7 +238,7 @@
<div class="input-field col s10">
<input type="text" id="parent_search">
<label for="parent_search">Search for asset</label>
{# {% render_field form.parent value=object.parent %}#}
{# {% render_field form.parent value=object.parent %}#}
</div>
<div class="col s2">
<button type="button" class="btn btn-flat" onclick="formAssetSearch()">
@@ -246,7 +266,7 @@
{% if object.asset_parent.all %}
{% for child in object.asset_parent.all %}
<dd>
<a href="{% url 'asset_detail' child.pk %}" >
<a href="{% url 'asset_detail' child.pk %}">
{{ child.asset_id }} - {{ child.description }}
</a>
</dd>
@@ -267,14 +287,14 @@
{% block script %}
{# <script>#}
{# $('#asset_update_form').on('submit', function(event){#}
{# <script>#}
{# $('#asset_update_form').on('submit', function(event){#}
{#console.log($('#asset_update_form').serialize());#}
{# event.preventDefault();#}
{# updateAsset();#}
{# return false;#}
{# });#}
{# </script>#}
{# event.preventDefault();#}
{# updateAsset();#}
{# return false;#}
{# });#}
{# </script>#}
<script>
function clearParent() {
@@ -285,7 +305,7 @@
</script>
<script>
$(document).ready(function() {
$(document).ready(function () {
{% if edit %}
var comments_id = '#{{ form.comments.id_for_label }}';
$(comments_id).val('{{ object.comments|linebreaksn }}');

View File

@@ -12,6 +12,7 @@ urlpatterns = [
path('asset/<int:pk>/', views.AssetDetail.as_view(), name='asset_detail'),
path('asset/create/', views.AssetEdit.as_view(), name='asset_create'),
path('asset/<int:pk>/edit/', views.AssetEdit.as_view(), name='asset_update'),
path('asset/<int:pk>/duplicate/', views.AssetDuplicate.as_view(), name='asset_duplicate'),
path('asset/delete/', views.asset_delete, name='ajax_asset_delete'),
path('asset/filter/', views.asset_filter, name='ajax_asset_filter'),
path('asset/update/', views.asset_update, name='ajax_asset_update'),

View File

@@ -65,6 +65,21 @@ class AssetEdit(LoginRequiredMixin, generic.TemplateView):
return context
class AssetDuplicate(LoginRequiredMixin, generic.TemplateView):
template_name = 'asset_update.html'
def get_context_data(self, **kwargs):
context = super(AssetDuplicate, self).get_context_data(**kwargs)
if self.kwargs:
context['object'] = get_object_or_404(models.Asset, pk=self.kwargs['pk'])
context['object'].pk = None
context['form'] = forms.AssetForm
# context['asset_names'] = models.Asset.objects.values_list('asset_id', 'description').order_by('-date_acquired')[]
context['duplicate'] = True
return context
@login_required()
def asset_update(request):
context = dict()