Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put the update request form in the request detail page, so that updates can be made there, and hence removed the update request buttons from the main request table. #901

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ __pycache__
.env
staticfiles/
mysite.log
settings.py
Copy link

@biswaz biswaz Aug 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do this.
(Thank GOD I'm not Linus Torvalds 😄 )

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad :33, I did it for my convenience, forgot to change back.
Just fixed it.

urls.py
venv
.idea/*
media/
5 changes: 2 additions & 3 deletions floodrelief/settings.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""
Django settings for floodrelief project.

Generated by 'django-admin startproject' using Django 2.1.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
Expand All @@ -16,6 +13,8 @@
import raven
import datetime



def get_list(text):
return [item.strip() for item in text.split(',')]

Expand Down
1 change: 1 addition & 0 deletions floodrelief/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
path('api/1/rest-auth/', include('rest_auth.urls')),
path('api/1/', include('mainapp.api_urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
#CHANGED MEDIA_ROOT to STATIC_ROOT and STATIC_URL to MEDIA_URL
60 changes: 48 additions & 12 deletions mainapp/templates/mainapp/request_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,45 @@
{{ filter.form.as_p }}
<input value="View requests" class="btn btn-primary" type="submit" />
</form>

<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th colspan="2" style="text-align:center;">Request details for #{{ req.id }}</th>
<th colspan="2" style="text-align:center;">Request Updates</th>
</tr>
</thead>

<tbody>
<tr>
<td><b> District : </b></td><td>{{ req.get_district_display }}</td>
<td><b> District : </b></td><td>{{ view.original_request.get_district_display }}</td>
</tr>
<tr>
<td><b> Location : </b></td><td>{{ req.location }}</td>
<td><b> Location : </b></td><td>{{ view.original_request.location }}</td>
</tr>
<tr>
<td><b> GPS Location : </b></td>
<td>
{% if req.latlng %}
<a class="btn btn-sm btn-success" href="https://maps.google.com/?q={{ req.latlng }}" target="_blank">Open in maps</a>
{% if view.original_request.latlng %}
<a class="btn btn-sm btn-success" href="https://maps.google.com/?q={{ view.original_request.latlng }}" target="_blank">Open in maps</a>
<br>
Accuracy: {{ req.latlng_accuracy }}
Accuracy: {{ view.original_request.latlng_accuracy }}
{% else %}
NA
{% endif %}
</td>
</tr>
<tr>
<td><b> Requestee : </b></td><td>{{ req.requestee }}</td>
</tr>
<td><b> Requestee : </b></td><td>{{ view.original_request.requestee }}</td>
</tr>
<tr>
<td><b> Contact number : </b></td><td><a href="tel:{{ req.requestee_phone }}" >{{ req.requestee_phone }}</a></td>
<td><b> Contact number : </b></td><td><a href="tel:{{ req.requestee_phone }}" >{{ view.original_request.requestee_phone }}</a></td>
</tr>
<tr>
<td><b> Summary of request : </b></td><td>{{ req.summarise | linebreaks }}</td>
<td><b> Summary of request : </b></td><td>{{ view.original_request.summarise | linebreaks }}</td>
</tr>
<tr>
<td><b> Date : </b></td><td>{{ req.dateadded }}</td>
<td><b> Date : </b></td><td>{{ view.original_request.dateadded }}</td>
</tr>
</tbody>
</table>
Expand All @@ -68,7 +69,7 @@ <h3 style="text-align:center;">Updates</h3>

<tbody>

{% for update in updates %}
{% for update in view.updates %}
<tr>
<td>{{ update.status }} {{ update.other_status }}</td>
<td>{{ update.updater_name }}</td>
Expand All @@ -84,4 +85,39 @@ <h3 style="text-align:center;">Updates</h3>
</table>

</div>

<h1 class="text-center">Request Updates</h1>
<h2 class="text-center">placeholder for malayalam ‍</h2>
<form method="post" class="simple-form" id="request_update_form">
{% csrf_token %}
{% bootstrap_form form %}

{% buttons %}
<button type="submit" class="btn btn-primary">
{% bootstrap_icon "star" %} Submit
</button>
{% endbuttons %}
</form>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("[name=other_status]").attr('type', 'hidden');
$("[name=other_status]").attr('required', false)
$("[for=id_other_status]").hide();

})
$("[name=status]").change(function() {
var value = this.value;
if(value !== 'otr') {
$("[name=other_status]").attr('type', 'hidden')
$("[name=other_status]").attr('required', false)
// $("[for=id_other_status]").hide();
} else {
$("[name=other_status]").attr('type', 'text')
// $("[for=id_other_status]").show();
}
})

</script>
{% endblock %}
9 changes: 5 additions & 4 deletions mainapp/templates/mainapp/request_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ <h2 class="text-center">ഇതു വരെ ആവശ്യപ്പെട്ട
<th>Requestee - അപേക്ഷകന്‍റെ പേര</th>
<th>Phone - ഫോണ്‍ നമ്പര്‍</th>
<th>Date - തീയതി</th>
<th>More details - കൂടുതൽ വിശദാംശങ്ങൾ</th>
<th>Update</th>
<th>More details/ update a request -
കൂടുതൽ വിവരങ്ങൾ / ഒരു അപേക്ഷ സമർപ്പിക്കുക</th>

</tr>
</thead>
<tbody>
Expand All @@ -104,8 +105,8 @@ <h2 class="text-center">ഇതു വരെ ആവശ്യപ്പെട്ട
<td>{{ req.requestee }}</td>
<td><a href="tel:{{ req.requestee_phone }}" >{{ req.requestee_phone }}</a></td>
<td>{{ req.dateadded }}</td>
<td><a class="btn btn-sm btn-success" href="{%url 'requestdetailsview' req.id %}" target="_blank">More details</a>
<td><a class="btn btn-sm btn-success" href="{%url 'requestupdateview' req.id %}" target="_blank">Update</a></td>
<td><a class="btn btn-sm btn-success" href="{%url 'requestdetailsview' req.id %}" target="_blank">More details/ Update Request</a>

</tr>
{% endfor %}
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion mainapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
path('ngoview/', views.ngo_list, name='ngoview'),
path('NGO/download/', views.download_ngo_list, name='ngo_download_view'),
path('requests/', views.request_list, name='requestlistview'),
url(r'request_details/(?P<request_id>\d+)/$', views.request_details, name='requestdetailsview'),
url(r'request_details/(?P<request_id>\d+)/$', views.RequestDetails.as_view(), name='requestdetailsview'),
path('contactus/', views.districtmanager_list, name='contactus'),
path('reg_success/', views.RegSuccess.as_view(), name='reg_successview'),
path('req_sucess/', views.ReqSuccess.as_view(), name='req_sucessview'),
Expand Down
38 changes: 38 additions & 0 deletions mainapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,45 @@ def request_details(request, request_id=None):
except:
return HttpResponseRedirect("/error?error_text={}".format('Sorry, we couldnt fetch details for that request'))
return render(request, 'mainapp/request_details.html', {'filter' : filter, 'req': req_data, 'updates': updates })
class RequestDetails(CreateView):
model = RequestUpdate
template_name='mainapp/request_details.html'
fields = [
'status',
'other_status',
'updater_name',
'updater_phone',
'notes'
]
success_url = '/req_update_success/'

def original_request(self):
return self.original_request

def updates(self):
return self.updates
def get_context_data(self, **kwargs):
context= super().get_context_data()
filter=RequestFilter(None)
context['filter']= filter
return context

#@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
#could not use login_required decorator because it redirects to /accounts/login and we need /login
#disable authentication
# if not request.user.is_authenticated:
# return redirect('/login'+'?next=request_updates/'+kwargs['request_id']+'/')

self.original_request = get_object_or_404(Request, pk=kwargs['request_id'])
self.updates = RequestUpdate.objects.all().filter(request_id=kwargs['request_id']).order_by('-update_ts')
return super().dispatch(request, *args, **kwargs)

def form_valid(self, form):
self.object = form.save(commit=False)
self.object.request = self.original_request
self.object = form.save()
return HttpResponseRedirect(self.get_success_url())
class DistrictManagerFilter(django_filters.FilterSet):
class Meta:
model = DistrictManager
Expand Down