mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-22 22:38:24 +00:00
Add asset duplication
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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 %}
|
||||
@@ -8,8 +8,10 @@
|
||||
|
||||
<h4>
|
||||
Asset
|
||||
{% if object %}
|
||||
{% if object.id %}
|
||||
| {{ object.asset_id }}
|
||||
{% elif duplicate %}
|
||||
Duplication of {{ object.asset_id }}
|
||||
{% else %}
|
||||
Create
|
||||
{% endif %}
|
||||
@@ -28,10 +30,17 @@
|
||||
{% if edit %}
|
||||
{# <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">
|
||||
|
||||
1
urls.py
1
urls.py
@@ -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'),
|
||||
|
||||
15
views.py
15
views.py
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user