mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 18:44:23 +00:00
Fixed markdown api issue
This commit is contained in:
parent
d23e07363d
commit
78bf4b7b84
@ -1,14 +1,20 @@
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.decorators import api_view, renderer_classes
|
||||
from rest_framework.renderers import StaticHTMLRenderer
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from core.templatetags.renderer import markdown
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@renderer_classes((StaticHTMLRenderer,))
|
||||
def RenderMarkdown(request):
|
||||
"""
|
||||
Render Markdown
|
||||
"""
|
||||
if request.method == 'GET':
|
||||
return Response(markdown(request.GET['text']))
|
||||
try:
|
||||
data = markdown(request.GET['text'])
|
||||
except:
|
||||
data = 'Error'
|
||||
return Response(data)
|
||||
|
||||
|
@ -95,6 +95,29 @@
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
<h4>{% trans %}Account buyings{% endtrans %}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Year{% endtrans %}</td>
|
||||
<td>{% trans %}Month{% endtrans %}</td>
|
||||
<td>{% trans %}Total{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for array in selling_months %}
|
||||
{% for tuple in array %}
|
||||
{% if tuple[0] != 0 %}
|
||||
<tr>
|
||||
<td>{{ tuple[1].year }}</td>
|
||||
<td>{{ tuple[1]|date("E") }}</td>
|
||||
<td>{{ tuple[0] }} €</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>{% trans %}User has no account{% endtrans %}</p>
|
||||
{% endif %}
|
||||
|
@ -12,7 +12,8 @@ from django.forms import CheckboxSelectMultiple
|
||||
from django.template.response import TemplateResponse
|
||||
from django.conf import settings
|
||||
|
||||
from datetime import timedelta
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta, datetime, date
|
||||
import logging
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
|
||||
@ -316,11 +317,38 @@ class UserAccountView(UserTabsMixin, DetailView):
|
||||
return res
|
||||
raise PermissionDenied
|
||||
|
||||
def expense_by_month(self):
|
||||
stats = []
|
||||
joined = self.object.date_joined.year
|
||||
|
||||
years = datetime.now().year - joined
|
||||
|
||||
years = range(0, years + 1)
|
||||
months = range(1, 12)
|
||||
|
||||
for y in years:
|
||||
stats.append([])
|
||||
for m in months:
|
||||
q = self.object.customer.buyings.filter(
|
||||
date__year=joined + y,
|
||||
date__month=m,
|
||||
)
|
||||
stats[y].append(
|
||||
(
|
||||
sum([p.unit_price * p.quantity for p in q]),
|
||||
date(joined + y, m, 17)
|
||||
)
|
||||
)
|
||||
|
||||
print(stats)
|
||||
return stats
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(UserAccountView, self).get_context_data(**kwargs)
|
||||
kwargs['profile'] = self.object
|
||||
try:
|
||||
kwargs['customer'] = self.object.customer
|
||||
kwargs['selling_months'] = self.expense_by_month()
|
||||
except:
|
||||
pass
|
||||
# TODO: add list of month where account has activity
|
||||
|
@ -7,3 +7,5 @@ pyopenssl
|
||||
pytz
|
||||
djangorestframework
|
||||
django-phonenumber-field
|
||||
django-ajax-selects
|
||||
mysqlclient
|
||||
|
Loading…
Reference in New Issue
Block a user