Commit 9ed462b9 by Kálmán Viktor

request: accept/decline requests

parent 291e2a3c
...@@ -55,10 +55,13 @@ class Request(TimeStampedModel): ...@@ -55,10 +55,13 @@ class Request(TimeStampedModel):
object_id = IntegerField() object_id = IntegerField()
action = GenericForeignKey("content_type", "object_id") 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): def get_readable_status(self):
return self.STATUSES[self.status] return self.STATUSES[self.status]
def get_icon(self): def get_request_icon(self):
return { return {
'resource': "tasks", 'resource': "tasks",
'lease': "clock-o", 'lease': "clock-o",
...@@ -73,6 +76,22 @@ class Request(TimeStampedModel): ...@@ -73,6 +76,22 @@ class Request(TimeStampedModel):
"DECLINED": "danger", "DECLINED": "danger",
}.get(self.status) }.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): class LeaseType(RequestType):
lease = ForeignKey(Lease) lease = ForeignKey(Lease)
......
...@@ -15,12 +15,13 @@ ...@@ -15,12 +15,13 @@
{% trans "Back" %} {% trans "Back" %}
</a> </a>
<h3 class="no-margin"> <h3 class="no-margin">
<i class="fa fa-{{ object.get_icon }}"></i> <i class="fa fa-{{ object.get_request_icon }}"></i>
{% trans "Request" %} {% trans "Request" %}
</h3> </h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="label label-{{ object.get_effect }} pull-right" style="font-size: 1.5em; margin-top: 10px;"> <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 }} {{ object.get_readable_status|upper }}
</div> </div>
<p> <p>
...@@ -79,18 +80,30 @@ ...@@ -79,18 +80,30 @@
{% else %} {% else %}
hacks!!! hacks!!!
{% endif %} {% endif %}
{% if object.status == "PENDING" %}
<hr /> <hr />
<div class="pull-right"> <div class="pull-right">
<button class="btn btn-danger"> <form method="POST" style="display: inline;">
{% csrf_token %}
<button class="btn btn-danger" type="submit">
<i class="fa fa-thumbs-down"></i> <i class="fa fa-thumbs-down"></i>
nope nope
</button> </button>
</form>
<form method="POST" style="display: inline;">
{% csrf_token %}
<input type="hidden" name="accept" value="1"/>
<button class="btn btn-success"> <button class="btn btn-success">
<i class="fa fa-thumbs-up"></i> <i class="fa fa-thumbs-up"></i>
yep yep
</button> </button>
</form>
</div> </div>
{% else %}
close date
{% endif %}
</div><!-- .panel-body --> </div><!-- .panel-body -->
</div> </div>
</div> </div>
......
...@@ -46,6 +46,16 @@ class RequestDetail(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -46,6 +46,16 @@ class RequestDetail(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
model = Request model = Request
template_name = "request/detail.html" 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): def get_context_data(self, **kwargs):
request = self.object request = self.object
context = super(RequestDetail, self).get_context_data(**kwargs) 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