Commit 9ed462b9 by Kálmán Viktor

request: accept/decline requests

parent 291e2a3c
......@@ -55,10 +55,13 @@ class Request(TimeStampedModel):
object_id = IntegerField()
action = GenericForeignKey("content_type", "object_id")
def get_absolute_url(self):
return reverse("request.views.request-detail", kwargs={'pk': self.pk})
def get_readable_status(self):
return self.STATUSES[self.status]
def get_icon(self):
def get_request_icon(self):
return {
'resource': "tasks",
'lease': "clock-o",
......@@ -73,6 +76,22 @@ class Request(TimeStampedModel):
"DECLINED": "danger",
}.get(self.status)
def get_status_icon(self):
return {
"UNSEEN": "eye-slash",
"PENDING": "exclamation-triangle",
"ACCEPTED": "check",
"DECLINED": "times",
}.get(self.status)
def accept(self):
self.status = "ACCEPTED"
self.save()
def decline(self):
self.status = "DECLINED"
self.save()
class LeaseType(RequestType):
lease = ForeignKey(Lease)
......
......@@ -15,12 +15,13 @@
{% trans "Back" %}
</a>
<h3 class="no-margin">
<i class="fa fa-{{ object.get_icon }}"></i>
<i class="fa fa-{{ object.get_request_icon }}"></i>
{% trans "Request" %}
</h3>
</div>
<div class="panel-body">
<div class="label label-{{ object.get_effect }} pull-right" style="font-size: 1.5em; margin-top: 10px;">
<i class="fa fa-{{ object.get_status_icon }}"></i>
{{ object.get_readable_status|upper }}
</div>
<p>
......@@ -79,18 +80,30 @@
{% else %}
hacks!!!
{% endif %}
<hr />
<div class="pull-right">
<button class="btn btn-danger">
<i class="fa fa-thumbs-down"></i>
nope
</button>
<button class="btn btn-success">
<i class="fa fa-thumbs-up"></i>
yep
</button>
</div>
{% if object.status == "PENDING" %}
<hr />
<div class="pull-right">
<form method="POST" style="display: inline;">
{% csrf_token %}
<button class="btn btn-danger" type="submit">
<i class="fa fa-thumbs-down"></i>
nope
</button>
</form>
<form method="POST" style="display: inline;">
{% csrf_token %}
<input type="hidden" name="accept" value="1"/>
<button class="btn btn-success">
<i class="fa fa-thumbs-up"></i>
yep
</button>
</form>
</div>
{% else %}
close date
{% endif %}
</div><!-- .panel-body -->
</div>
</div>
......
......@@ -46,6 +46,16 @@ class RequestDetail(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
model = Request
template_name = "request/detail.html"
def post(self, *args, **kwargs):
accept = self.request.POST.get("accept")
request = self.get_object() # not self.request!
if accept:
request.accept()
else:
request.decline()
return redirect(request.get_absolute_url())
def get_context_data(self, **kwargs):
request = self.object
context = super(RequestDetail, self).get_context_data(**kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment