Skip to content

Commit

Permalink
En route to #129.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgets committed Jul 4, 2019
1 parent 8392989 commit 1615a2e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions subadd/templates/subadd/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h3>There are no database entries</h3>
<div class="botnav">
<a href="{% url 'subadd:add' %}">Add new substance</a>
<a href="{% url 'subadd:add_sub_class' %}">Substance classes</a>
<a href="{% url 'subadd:edit_sub' %}">Edit Substance</a>
<a href="/accounts/logout">Log out</a>
</div>
{% else %}
Expand Down
1 change: 1 addition & 0 deletions subadd/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
path('<int:substance_id>/', views.detail, name='detail'),
path('add_class', views.add_sub_class, name='add_sub_class'),
path('class_details/<int:class_id>/', views.sub_class_details, name='sub_class_details'),
path('edit', views.edit_sub, name='edit_sub'),
]

25 changes: 25 additions & 0 deletions subadd/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ def addentry(request):
return render(request, 'subadd/index.html', MiscMethods.add_header_info({'all_subs': Substance.objects.all()}))


@login_required
def edit_sub(request):
"""
View provides the capability to edit a substance's details.
:param request:
:param substance_id:
:return:
"""

if request.method != 'POST':
# substance = Substance.objects.get(pk=substance_id)
substance_form = Substance.objects.get(pk=request.POST['substance_id']) # SubstanceForm

# substance_form = substance
context['substance_form'] = substance_form

return render(request, 'subadd/edit_sub.html', MiscMethods.add_header_info(context))

else:
context['substances'] = Substance.objects.all()

return render(request, 'subadd/edit_sub.html', MiscMethods.add_header_info(context))


@login_required
def detail(request, substance_id):
"""
Expand Down

0 comments on commit 1615a2e

Please sign in to comment.