Add destination functionality (models + views (view / add / confirm delete)
This commit is contained in:
parent
df46114725
commit
1381df71d9
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('passerelle_imio_ts1_datasources', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='DestinationTerm',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('text', models.CharField(max_length=100)),
|
||||
('price', models.DecimalField(max_digits=6, decimal_places=2)),
|
||||
('description', models.TextField(max_length=500)),
|
||||
('paymentrequired', models.BooleanField(default=True)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['text'],
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
|
@ -33,6 +33,19 @@ class MotivationTerm(models.Model):
|
|||
return super(MotivationTerm, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class DestinationTerm(models.Model):
|
||||
text = models.CharField(max_length=100)
|
||||
price = models.DecimalField(decimal_places=2, max_digits=6)
|
||||
description = models.TextField(max_length=500)
|
||||
paymentrequired = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['text']
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
return super(DestinationTerm, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class ImioTs1Datasources(BaseResource):
|
||||
|
||||
lst_motivations_terms = [{'text': u'mon motif', 'price': 0.0, 'id': 'mon-motif', 'description': u''},
|
||||
|
@ -80,6 +93,9 @@ class ImioTs1Datasources(BaseResource):
|
|||
def get_motivation_terms(self):
|
||||
return MotivationTerm.objects.all()
|
||||
|
||||
def get_destination_terms(self):
|
||||
return DestinationTerm.objects.all()
|
||||
|
||||
@endpoint()
|
||||
def motivationterms(self, request, **kwargs):
|
||||
motivation_terms = []
|
||||
|
@ -88,3 +104,13 @@ class ImioTs1Datasources(BaseResource):
|
|||
"text": motivation.text,
|
||||
"price": str(motivation.price)})
|
||||
return {"data": motivation_terms}
|
||||
|
||||
@endpoint()
|
||||
def destinationterms(self, request, **kwargs):
|
||||
destination_terms = []
|
||||
for destination in self.get_destination_terms():
|
||||
destination_terms.append({"id": destination.id,
|
||||
"text": destination.text,
|
||||
"price": str(destination.price),
|
||||
"paymentrequired" : str(destination.paymentrequired)})
|
||||
return {"data": destination_terms}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{% extends "passerelle/manage.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>{% trans 'Removing Destinationterm' %}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<div class="buttons">
|
||||
<button>{% trans 'Confirm Deletion' %}</button>
|
||||
<a class="cancel" href="#">{% trans 'Cancel' %}</a>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -0,0 +1,30 @@
|
|||
{% extends "passerelle/manage.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{{ block.super }}
|
||||
<a href="{{ resource.get_absolute_url }}">{{ resource.title }}</a>
|
||||
{% if object.id %}
|
||||
<a href="{{ object.id }}">{{ object.slug }}</a>
|
||||
{% else %}
|
||||
<a href="#">{% trans 'Add Query' %}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div id="form-content">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
</div>
|
||||
{% block buttons %}
|
||||
<div class="buttons">
|
||||
<button>{% trans "Save" %}</button>
|
||||
<button>{% trans "Cancel" %}</button>
|
||||
</div>
|
||||
{% endblock %}
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -3,6 +3,25 @@
|
|||
|
||||
{% block content %}
|
||||
{% if object.description %}{{object.description|linebreaks}}{% endif %}
|
||||
<h3>{%trans 'Destinations list' %}</h3>
|
||||
<table class="main">
|
||||
<thead>
|
||||
<tr><th>{% trans 'Label' %}</th><th>{% trans 'Price' %}</th><th>{% trans 'Description' %}</th><th>{% trans 'Payment required' %}</th><th> </th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for destination in object.get_destination_terms %}
|
||||
<tr><td>{{destination.text}}</td><td>{{destination.price}}</td><td>{{destination.description}}</td>
|
||||
<td>{{destination.paymentrequired}}</td>
|
||||
<td><a rel="popup" href="{% url 'destinationterm-delete' pk=destination.id connector_slug=object.slug %}" class="icon-remove-sign"></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
<a class="icon-plus button" href="{% url 'destinationterm-add' connector_slug=object.slug %}">{% trans 'Add new destination' %}</a>
|
||||
</p>
|
||||
<hr />
|
||||
|
||||
<h3>{%trans 'Motivations list' %}</h3>
|
||||
<table class="main">
|
||||
<thead>
|
||||
|
@ -18,8 +37,7 @@
|
|||
</table>
|
||||
|
||||
<p>
|
||||
<!--csv-new-query-->
|
||||
<a class="icon-plus button" href="{% url 'motivationterm-add' connector_slug=object.slug %}">{% trans 'Add new record' %}</a>
|
||||
<a class="icon-plus button" href="{% url 'motivationterm-add' connector_slug=object.slug %}">{% trans 'Add new motivation' %}</a>
|
||||
</p>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
from django.conf.urls import patterns, include, url
|
||||
from .views import DatasourcesView, MotivationtermAddView, MotivationtermDeleteView
|
||||
from .views import (DatasourcesView,
|
||||
MotivationtermAddView,
|
||||
MotivationtermDeleteView,
|
||||
DestinationtermAddView,
|
||||
DestinationtermDeleteView)
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^(?P<slug>[\w,-]+)/data$', DatasourcesView.as_view(), name='DatasourcesView-data'),
|
||||
|
@ -10,4 +15,8 @@ management_urlpatterns = patterns('',
|
|||
MotivationtermAddView.as_view(), name='motivationterm-add'),
|
||||
url(r'^(?P<connector_slug>[\w,-]+)/motivationterm/(?P<pk>[\w,-]+)/delete/',
|
||||
MotivationtermDeleteView.as_view(), name='motivationterm-delete'),
|
||||
url(r'^(?P<connector_slug>[\w,-]+)/destinationterm/add/',
|
||||
DestinationtermAddView.as_view(), name='destinationterm-add'),
|
||||
url(r'^(?P<connector_slug>[\w,-]+)/destinationterm/(?P<pk>[\w,-]+)/delete/',
|
||||
DestinationtermDeleteView.as_view(), name='destinationterm-delete')
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.views.generic import View, CreateView, DeleteView
|
|||
from django.views.generic.detail import SingleObjectMixin
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from .models import ImioTs1Datasources, MotivationTerm
|
||||
from .models import ImioTs1Datasources, MotivationTerm, DestinationTerm
|
||||
|
||||
|
||||
class DatasourcesView(View, SingleObjectMixin):
|
||||
|
@ -29,3 +29,25 @@ class MotivationtermDeleteView(DeleteView):
|
|||
return reverse('view-connector',
|
||||
kwargs={'connector': connector.get_connector_slug(),
|
||||
'slug': connector.slug})
|
||||
|
||||
|
||||
class DestinationtermAddView(CreateView):
|
||||
model = DestinationTerm
|
||||
fields = '__all__'
|
||||
template_name = 'passerelle_imio_ts1_datasources/destinationterm_form.html'
|
||||
|
||||
def get_success_url(self):
|
||||
connector = ImioTs1Datasources.objects.get(slug=self.kwargs['connector_slug'])
|
||||
return reverse('view-connector',
|
||||
kwargs={'connector': connector.get_connector_slug(),
|
||||
'slug': connector.slug})
|
||||
|
||||
|
||||
class DestinationtermDeleteView(DeleteView):
|
||||
model = DestinationTerm
|
||||
|
||||
def get_success_url(self):
|
||||
connector = ImioTs1Datasources.objects.get(slug=self.kwargs['connector_slug'])
|
||||
return reverse('view-connector',
|
||||
kwargs={'connector': connector.get_connector_slug(),
|
||||
'slug': connector.slug})
|
||||
|
|
Loading…
Reference in New Issue