Add amount and total to requests

This commit is contained in:
Oliver Marks 2018-02-24 19:24:52 +00:00
parent b151889518
commit e6c2d60fc1
4 changed files with 43 additions and 1 deletions

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2018-02-03 20:19
from __future__ import unicode_literals
from django.db import migrations
import martor.models
class Migration(migrations.Migration):
dependencies = [
('requests', '0012_auto_20180115_1425'),
]
operations = [
migrations.AlterField(
model_name='userrequest',
name='description',
field=martor.models.MartorField(help_text="detail of what's being requested and where it can be purchased"),
),
migrations.AlterField(
model_name='userrequestscomment',
name='comment',
field=martor.models.MartorField(help_text='Your comments'),
),
]

View File

@ -4,6 +4,7 @@ from django.conf import settings
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.contrib.sites.models import Site
from django.db.models.signals import post_save from django.db.models.signals import post_save
from martor.models import MartorField from martor.models import MartorField
from mhackspace.base.tasks import matrix_message from mhackspace.base.tasks import matrix_message
@ -53,7 +54,10 @@ class UserRequestsComment(models.Model):
def send_topic_update_email(sender, instance, **kwargs): def send_topic_update_email(sender, instance, **kwargs):
matrix_message.delay( matrix_message.delay(
prefix=' - REQUEST', prefix=' - REQUEST',
message='%s - %s' % (instance.title, instance.get_absolute_url())) message='%s - https://%s%s' % (
Site.objects.get_current().domain,
instance.title,
instance.get_absolute_url()))
post_save.connect(send_topic_update_email, sender=UserRequest) post_save.connect(send_topic_update_email, sender=UserRequest)

View File

@ -67,4 +67,5 @@ class RequestsList(LoginRequiredMixin, ListView):
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super(RequestsList, self).get_context_data(*args, **kwargs) context = super(RequestsList, self).get_context_data(*args, **kwargs)
context['requests_history'] = UserRequest.objects.filter(acquired=True)[:50] context['requests_history'] = UserRequest.objects.filter(acquired=True)[:50]
context['total'] = sum([r.cost for r in UserRequest.objects.filter(acquired=True)])
return context return context

View File

@ -44,6 +44,7 @@
<th>#</th> <th>#</th>
<th>Type</th> <th>Type</th>
<th>Date</th> <th>Date</th>
<th>Cost</th>
<th>Detail</th> <th>Detail</th>
</tr> </tr>
</thead> </thead>
@ -56,6 +57,9 @@
<td> <td>
{{ request.created_date }} {{ request.created_date }}
</td> </td>
<td>
{{ request.cost }}
</td>
<td> <td>
<a href="{% url 'requests_detail' request.id %}">{{ request.title }}</a> <a href="{% url 'requests_detail' request.id %}">{{ request.title }}</a>
</td> </td>
@ -68,6 +72,13 @@
</tr> </tr>
{% endfor %} {% endfor %}
<tr>
<th colspan="3">Total</th>
<td>{{ total }}</td>
<td></td>
<td></td>
</tr>
</table> </table>