Skip to content

Commit

Permalink
Display transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
the-glu committed Jan 10, 2014
1 parent e3c67cf commit 6106824
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 21 deletions.
4 changes: 2 additions & 2 deletions server/configs/templates/configs/configs/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2>{% trans "Configs management" %}</h2>
<ol class="breadcrumb">
<li><a href="{% url 'main.views.home' %}"><i class="fa fa-home"></i> {% trans "Home" %}</a></li>
<li><a href="{% url 'configs.views.list' %}"><i class="fa fa-cogs"></i> {% trans "Configs" %}</a></li>
<li class="active"><i class="fa fa-cog"></i> {{object|safe}}</a></li>
<li class="active"><i class="fa fa-cog"></i> {{object|safe}}</li>

</ol>

Expand Down Expand Up @@ -129,7 +129,7 @@ <h3 class="panel-title">{% trans "Details of a config" %}</h3>

<div class="row-fluid box-section" style="text-align: right;">
<a href="{% url 'configs.views.list' %}" class="btn btn-default"><i class="glyphicon glyphicon-list"></i> {% trans "Back to the list" %}</a>
<a href="{% url 'configs.views.show_logs' elem.pk %}" class="btn btn-default"><i class="glyphicon glyphicon-list-alt"></i> {% trans "Logs" %}</a>
<a href="{% url 'configs.views.show_logs' object.pk %}" class="btn btn-default"><i class="glyphicon glyphicon-list-alt"></i> {% trans "Logs" %}</a>
<a href="{% url 'configs.views.edit' object.pk %}" class="btn btn-primary"><i class="glyphicon glyphicon-pencil"></i> {% trans "Edit" %}</a>
</div>

Expand Down
21 changes: 11 additions & 10 deletions server/configs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _

from configs.models import Config, ConfigLogs
from configs.forms import ConfigForm
Expand Down Expand Up @@ -55,7 +56,7 @@ def edit(request, pk):
object = form.save(commit=False)

if not create:
ConfigLogs(config=object, user=request.user, text='Config has been updated: ' + object.generate_diff(Config.objects.get(pk=pk))).save()
ConfigLogs(config=object, user=request.user, text=_('Config has been updated: ') + object.generate_diff(Config.objects.get(pk=pk))).save()

object.save() # To use allowed_users

Expand All @@ -67,9 +68,9 @@ def edit(request, pk):
object.save()

if create:
ConfigLogs(config=object, user=request.user, text='Config has been created: ' + object.generate_diff(Config())).save()
ConfigLogs(config=object, user=request.user, text=_('Config has been created: ') + object.generate_diff(Config())).save()

messages.success(request, 'The config has been saved.')
messages.success(request, _('The config has been saved.'))

return redirect('configs.views.list')
else:
Expand All @@ -89,7 +90,7 @@ def edit(request, pk):
# raise Http404

# object.delete()
# messages.success(request, 'Config has been deleted.')
# messages.success(request, _('Config has been deleted.'))

# return redirect('configs.views.list')

Expand Down Expand Up @@ -118,9 +119,9 @@ def new_ipn_key(request, pk):
object.gen_key_ipn()
object.save()

ConfigLogs(config=object, user=request.user, text='A new IPN key has been generated.').save()
ConfigLogs(config=object, user=request.user, text=_('A new IPN key has been generated.')).save()

messages.success(request, 'A new IPN key has been generated !')
messages.success(request, _('A new IPN key has been generated !'))

return redirect('configs.views.show', pk=pk)

Expand All @@ -137,9 +138,9 @@ def new_requests_key(request, pk):
object.gen_key_request()
object.save()

ConfigLogs(config=object, user=request.user, text='A new requests key has been generated.').save()
ConfigLogs(config=object, user=request.user, text=_('A new requests key has been generated.')).save()

messages.success(request, 'A new requests key has been generated !')
messages.success(request, _('A new requests key has been generated !'))

return redirect('configs.views.show', pk=pk)

Expand All @@ -156,9 +157,9 @@ def new_api_key(request, pk):
object.gen_key_api()
object.save()

ConfigLogs(config=object, user=request.user, text='A new api key has been generated.').save()
ConfigLogs(config=object, user=request.user, text=_('A new api key has been generated.')).save()

messages.success(request, 'A new api key has been generated !')
messages.success(request, _('A new api key has been generated !'))

return redirect('configs.views.show', pk=pk)

Expand Down
1 change: 1 addition & 0 deletions server/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _


@login_required
Expand Down
3 changes: 3 additions & 0 deletions server/paiements/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def internal_status_good(self):
"""Return true if the internal status of the transaction if good (user back from postfinance)"""
return self.internal_status == 'fb'

def __unicode__(self):
return self.reference


class TransactionLog(models.Model):
"""A transaction log"""
Expand Down
4 changes: 2 additions & 2 deletions server/paiements/templates/paiements/transactions/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ <h3 class="panel-title">
<tbody>
{% for elem in list %}
<tr>
<td><a href="{% url 'configs.views.show' elem.pk %}">{{elem.reference}}</a></td>
<td><a href="{% url 'paiements.views.transactions_show' elem.pk %}">{{elem.reference}}</a></td>
<td>{{elem.amount_chf|floatformat:"2"}} CHF</td>
<td><span class="label label-{{elem.postfinance_status_good|yesno:"success,danger"}}">{{elem.get_postfinance_status_display}}</span></td>
<td><span class="label label-{{elem.internal_status_good|yesno:"success,danger"}}">{{elem.get_internal_status_display}}</span></td>
<td>{{elem.creation_date|date}} {{elem.creation_date|time}} ({{elem.creation_date|timesince}})</td>
<td>
<a href="{% url 'configs.views.show_logs' elem.pk %}" class="btn btn-xs btn-default"><i class="glyphicon glyphicon-list-alt"></i> {% trans "Logs" %}</a>
<a href="{% url 'paiements.views.transactions_show_logs' elem.pk %}" class="btn btn-xs btn-default"><i class="glyphicon glyphicon-list-alt"></i> {% trans "Logs" %}</a>
</td>
</tr>
{% endfor %}
Expand Down
61 changes: 61 additions & 0 deletions server/paiements/templates/paiements/transactions/logs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends "base.html" %}
{% load i18n %}
{% load bootstrap3 %}

{% block title %}{{block.super}} :: {% trans "Transactions" %} :: {% trans "Logs" %}{% endblock %}

{% block content %}

<script type="text/javascript">$('#nav-transactions').addClass('active');</script>

<h2>{% trans "Transactions" %}</h2>

<ol class="breadcrumb">
<li><a href="{% url 'main.views.home' %}"><i class="fa fa-home"></i> {% trans "Home" %}</a></li>
<li><a href="{% url 'configs.views.show' object.config.pk %}"><i class="fa fa-cog"></i> {{object.config|safe}}</a></li>
<li><a href="{% url 'paiements.views.transactions_list' %}"><i class="fa fa-money"></i> {% trans "Transactions" %}</a></li>
<li><a href="{% url 'paiements.views.transactions_show' object.pk %}"><i class="fa fa-dollar"></i> {{object}}</a></li>
<li class="active"><i class="glyphicon glyphicon-list-alt"></i> {% trans "Logs" %}</li>

</ol>

<div class="row-fluid">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Logs for" %} {{object|safe}}</h3>
</div>
<div class="panel-body">

<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered table-to-sort-but-not-automaticaly">
<thead>
<tr>
<th>{% trans "When" %}</th>
<th>{% trans "What" %}</th>
<th>{% trans "Extra data" %}</th>
</tr>
</thead>
<tbody>
{% for elem in list %}
<tr>
<td>{{elem.when|date}} {{elem.when|time}} ({{elem.when|timesince}} {% trans "ago" %})</td>
<td>{{elem.get_log_type_display}}</td>
<td>{{elem.extra_data}}</td>
</tr>
{% endfor %}

</tbody>
</table>


<div class="row-fluid box-section" style="text-align: right;">
<a href="{% url 'configs.views.list' %}" class="btn btn-default"><i class="glyphicon glyphicon-list"></i> {% trans "Back to the list" %}</a>
<a href="{% url 'configs.views.show' object.pk %}" class="btn btn-primary"> {% trans "Back to the config" %}</a>
</div>

</div>
</div>

</div>


{% endblock %}
135 changes: 135 additions & 0 deletions server/paiements/templates/paiements/transactions/show.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{% extends "base.html" %}
{% load i18n %}
{% load bootstrap3 %}

{% block title %}{{block.super}} :: {% trans "Transactions" %} :: {% trans "Details" %}{% endblock %}

{% block content %}

<script type="text/javascript">$('#nav-transactions').addClass('active');</script>

<h2>{% trans "Transactions" %}</h2>

<ol class="breadcrumb">
<li><a href="{% url 'main.views.home' %}"><i class="fa fa-home"></i> {% trans "Home" %}</a></li>
<li><a href="{% url 'configs.views.show' object.config.pk %}"><i class="fa fa-cog"></i> {{object.config|safe}}</a></li>
<li><a href="{% url 'paiements.views.transactions_list' %}"><i class="fa fa-money"></i> {% trans "Transactions" %}</a></li>
<li class="active"><i class="fa fa-dollar"></i> {{object}}</li>
</ol>

<div class="row-fluid">

<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Details of a transaction" %}</h3>
</div>
<div class="panel-body">

<form>

<div class="form-group">
<label>{% trans "Reference" %}</label>
<p class="form-control-static">{{object.reference}}</p>
</div>

<div class="form-group">
<label>{% trans "Postfinance ID" %}</label>
<p class="form-control-static">{{object.postfinance_id}}</p>
</div>

{% if object.extra_data %}
<div class="form-group">
<label>{% trans "Extra data" %}</label>
<p class="form-control-static">{{object.extra_data}}</p>
</div>
{% endif %}

<div class="form-group">
<label>{% trans "Amount" %}</label>
<p class="form-control-static">{{object.amount_chf|floatformat:"2"}} CHF</p>
</div>


<div class="form-group">
<label>{% trans "Test mode ?" %}</label>
<p class="form-control-static"><span class="label label-{{object.postfinance_status_good|yesno:"success,danger"}}">{{object.get_postfinance_status_display}}</span></p>
</div>

<div class="form-group">
<label>{% trans "Is active ?" %}</label>
<p class="form-control-static"><span class="label label-{{object.internal_status_good|yesno:"success,danger"}}">{{object.get_internal_status_display}}</span></p>
</div>

<div class="form-group">
<label>{% trans "Ipn needed ?" %}</label>
<p class="form-control-static"><span class="label label-{{object.ipn_needed|yesno:"danger,success"}}">{{object.ipn_needed|yesno}}</span></p>
</div>

<div class="form-group">
<label>{% trans "Creation date" %}</label>
<p class="form-control-static">{{object.creation_date|date}} {{object.creation_date|time}} ({{object.creation_date|timesince}})</p>
</div>

{% if object.last_userforwarded_date %}
<div class="form-group">
<label>{% trans "Last user forwarder to Postfinance" %}</label>
<p class="form-control-static">{{object.last_userforwarded_date|date}} {{object.last_userforwarded_date|time}} ({{object.last_userforwarded_date|timesince}})</p>
</div>
{% endif %}

{% if object.last_user_back_from_postfinance_date %}
<div class="form-group">
<label>{% trans "Last user return from Postfinance" %}</label>
<p class="form-control-static">{{object.last_user_back_from_postfinance_date|date}} {{object.last_user_back_from_postfinance_date|time}} ({{object.last_user_back_from_postfinance_date|timesince}})</p>
</div>
{% endif %}

{% if object.last_postfinance_ipn_date %}
<div class="form-group">
<label>{% trans "Last postfinance IPN reception" %}</label>
<p class="form-control-static">{{object.last_postfinance_ipn_date|date}} {{object.last_postfinance_ipn_date|time}} ({{object.last_postfinance_ipn_date|timesince}})</p>
</div>
{% endif %}

{% if object.last_ipn_date %}
<div class="form-group">
<label>{% trans "Last IPN date" %}</label>
<p class="form-control-static">{{object.last_ipn_date|date}} {{object.last_ipn_date|time}} ({{object.last_ipn_date|timesince}})</p>
</div>
{% endif %}

</form>

<div class="row-fluid box-section" style="text-align: right;">
<a href="{% url 'paiements.views.transactions_list' %}" class="btn btn-default"><i class="glyphicon glyphicon-list"></i> {% trans "Back to the list" %}</a>
<a href="{% url 'paiements.views.transactions_show_logs' object.pk %}" class="btn btn-default"><i class="glyphicon glyphicon-list-alt"></i> {% trans "Logs" %}</a>
</div>

</div>
</div>

</div>

<script type="text/javascript" src="{{MEDIA_URL}}ZeroClipboard.js"></script>

<script type="text/javascript">

$(document).ready(function(){

$(".btn-key").zclip({
path: "{{MEDIA_URL}}ZeroClipboard.swf",
copy: function(){
return $(this).attr('x-key');
},
afterCopy: function() {
$('.btn-key').removeClass('btn-success');
$('.btn-key').html('{% trans "Copy" %}');
$(this).addClass('btn-success');

$(this).html('{% trans "Copied !" %}');
}
});
});
</script>

{% endblock %}
2 changes: 2 additions & 0 deletions server/paiements/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
url(r'^return$', 'return_from_postfinance'),

url(r'^transactions/list$', 'transactions_list'),
url(r'^transactions/(?P<pk>[0-9]+)/$', 'transactions_show'),
url(r'^transactions/(?P<pk>[0-9]+)/logs$', 'transactions_show_logs'),

)
33 changes: 32 additions & 1 deletion server/paiements/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _

import json
import uuid
Expand Down Expand Up @@ -228,7 +229,11 @@ def transactions_list(request):
configPk = available_configs[0]

if configPk != 'all' or not request.user.is_superuser:
config = get_object_or_404(Config, pk=configPk)
try:
config = get_object_or_404(Config, pk=configPk)
except:
config = None

transactions = Transaction.objects.filter(config=config)
else:
transactions = Transaction.objects
Expand All @@ -237,3 +242,29 @@ def transactions_list(request):
transactions = transactions.order_by('-creation_date').all()

return render_to_response('paiements/transactions/list.html', {'list': transactions, 'available_configs': available_configs, 'configPk': configPk, 'config': config}, context_instance=RequestContext(request))


@login_required
def transactions_show_logs(request, pk):
"""Show logs of transactions"""

object = get_object_or_404(Transaction, pk=pk)

if not request.user.is_superuser and not request.user in object.allowed_users:
raise Http404

list = object.transactionlog_set.order_by('-when').all()

return render_to_response('paiements/transactions/logs.html', {'object': object, 'list': list}, context_instance=RequestContext(request))


@login_required
def transactions_show(request, pk):
"""Display details of a transaction"""

object = get_object_or_404(Transaction, pk=pk)

if not request.user.is_superuser and not request.user in object.allowed_users:
raise Http404

return render_to_response('paiements/transactions/show.html', {'object': object}, context_instance=RequestContext(request))
2 changes: 1 addition & 1 deletion server/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

</div><!-- /#page-wrapper -->

<div class="copy">&copy; Maximilien Cuony - 2013 - <a href="http://agepoly.epfl.ch">AGEPoly</a>/<a href="http://polylan.ch">PolyLAN</a></div>
<div class="copy">&copy; Maximilien Cuony - 2014 - <a href="http://agepoly.epfl.ch">AGEPoly</a>/<a href="http://polylan.ch">PolyLAN</a></div>

</div><!-- /#wrapper -->

Expand Down
Loading

0 comments on commit 6106824

Please sign in to comment.