CRUD fonctionnel

This commit is contained in:
Michel Roux 2016-02-14 21:40:28 +01:00
parent 1039d1e6d6
commit 43182c04aa
9 changed files with 89 additions and 12 deletions

View File

@ -26,8 +26,11 @@ router.register(r'orders', OrderViewSet)
urlpatterns = [ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^create/', views.OrderCreateView.as_view(), name='create'),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^$', views.OrderIndexView.as_view(), name='index'), url(r'^$', views.OrderIndexView.as_view(), name='index'),
url(r'^(?P<pk>[-\w]+)/$', views.OrderDetailView.as_view(), name='detail'), url(r'^(?P<pk>[-\w]+)/$', views.OrderDetailView.as_view(), name='detail'),
url(r'^api/', include(router.urls)), url(r'^(?P<pk>[-\w]+)/delete/$', views.OrderDeleteView.as_view(), name='delete'),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) url(r'^(?P<pk>[-\w]+)/update/$', views.OrderUpdateView.as_view(), name='update'),
] ]

View File

@ -13,15 +13,15 @@ class Order(models.Model):
order_id = models.CharField(max_length=20, primary_key=True) order_id = models.CharField(max_length=20, primary_key=True)
order_mrid = models.CharField(max_length=20) order_mrid = models.CharField(max_length=20)
order_refid = models.CharField(max_length=20) order_refid = models.CharField(max_length=20)
order_external_id = models.CharField(max_length=20, null=True) order_external_id = models.CharField(max_length=20, null=True, blank=True)
# Colonne unique pour le order_purchase_date et order_purchase_heure because DateTime # Colonne unique pour le order_purchase_date et order_purchase_heure because DateTime
order_purchase = models.DateTimeField(null=True) order_purchase = models.DateTimeField(null=True, blank=True)
order_amount = models.FloatField() order_amount = models.FloatField()
order_tax = models.FloatField(null=True) order_tax = models.FloatField(null=True, blank=True)
order_shipping = models.FloatField() order_shipping = models.FloatField()
order_commission = models.FloatField() order_commission = models.FloatField()
order_processing_fee = models.FloatField() order_processing_fee = models.FloatField()
order_comments = models.TextField(null=True) order_comments = models.TextField(null=True, blank=True)
customer_id = models.CharField(max_length=20, null=True) customer_id = models.CharField(max_length=20, null=True, blank=True)
order_ip = models.GenericIPAddressField(null=True) order_ip = models.GenericIPAddressField(null=True, blank=True)
order_items = models.IntegerField() order_items = models.IntegerField()

View File

@ -1,4 +1,5 @@
from django.views.generic import ListView, DetailView from django.core.urlresolvers import reverse_lazy
from django.views.generic import ListView, DetailView, DeleteView, UpdateView, CreateView
from rest_framework import serializers, viewsets from rest_framework import serializers, viewsets
@ -15,6 +16,30 @@ class OrderDetailView(DetailView):
model = Order model = Order
class OrderDeleteView(DeleteView):
template_name = 'orders/order/delete.html'
model = Order
success_url = reverse_lazy('index')
class OrderUpdateView(UpdateView):
template_name = 'orders/order/update.html'
model = Order
success_url = reverse_lazy('index')
fields = ['marketplace', 'idFlux', 'order_mrid', 'order_refid', 'order_external_id',
'order_purchase', 'order_amount', 'order_tax', 'order_shipping', 'order_commission',
'order_processing_fee', 'order_comments', 'customer_id', 'order_ip', 'order_items']
class OrderCreateView(CreateView):
template_name = 'orders/order/create.html'
model = Order
success_url = reverse_lazy('index')
fields = ['marketplace', 'idFlux', 'order_mrid', 'order_refid', 'order_external_id',
'order_purchase', 'order_amount', 'order_tax', 'order_shipping', 'order_commission',
'order_processing_fee', 'order_comments', 'customer_id', 'order_ip', 'order_items']
class OrderSerializer(serializers.HyperlinkedModelSerializer): class OrderSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Order model = Order

View File

@ -14,6 +14,14 @@
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet"> <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
</head> </head>
<body> <body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/">Orders Management</a>
</div>
</div>
</nav>
{% block body %}{% endblock %} {% block body %}{% endblock %}
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->

View File

@ -0,0 +1,12 @@
{% extends 'orders/base.html' %}
{% block title %}Create an order{% endblock %}
{% block body %}
<div class="container-fluid">
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Create"/>
</form>
</div>
{% endblock %}

View File

@ -0,0 +1,12 @@
{% extends 'orders/base.html' %}
{% block title %}Confirm deletion of {{ object.order_id }}'s order{% endblock %}
{% block body %}
<div class="container-fluid">
<form action="" method="post">{% csrf_token %}
<p>Are you sure you want to delete order "{{ object.order_id }}"?</p>
<input type="submit" value="Confirm"/>
</form>
</div>
{% endblock %}

View File

@ -4,7 +4,6 @@
{% block body %} {% block body %}
<div class="container-fluid"> <div class="container-fluid">
<h2>Order {{ object.order_id }}</h2> <h2>Order {{ object.order_id }}</h2>
<ul> <ul>

View File

@ -4,7 +4,11 @@
{% block body %} {% block body %}
<div class="container-fluid"> <div class="container-fluid">
<h1>Orders</h1> <p>
<a href="/create">
<i class="glyphicon glyphicon-plus"></i> Create new order
</a>
</p>
<table class="table table-bordered table-hover"> <table class="table table-bordered table-hover">
<thead> <thead>
@ -49,7 +53,7 @@
<td>{{ order.order_ip }}</td> <td>{{ order.order_ip }}</td>
<td>{{ order.order_items }}</td> <td>{{ order.order_items }}</td>
<td> <td>
<a href="/{{ order.order_id }}/edit"> <a href="/{{ order.order_id }}/update">
<i class="glyphicon glyphicon-pencil"></i> <i class="glyphicon glyphicon-pencil"></i>
</a> </a>
</td> </td>

View File

@ -0,0 +1,14 @@
{% extends 'orders/base.html' %}
{% block title %}Update {{ object.order_id }}'s order{% endblock %}
{% block body %}
<div class="container-fluid">
<h2>Order {{ object.order_id }}</h2>
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update"/>
</form>
</div>
{% endblock %}