general: make it possible to associate formdefs to a mail
This commit is contained in:
parent
9e42a5d069
commit
737ffffd7f
|
@ -0,0 +1,62 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contenttypes', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Association',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('source_pk', models.PositiveIntegerField()),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='FormdataReference',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('reference', models.CharField(max_length=250)),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='FormdefReference',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('reference', models.CharField(max_length=250)),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='association',
|
||||
name='formdatas',
|
||||
field=models.ManyToManyField(to='qualif.FormdataReference'),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='association',
|
||||
name='formdefs',
|
||||
field=models.ManyToManyField(to='qualif.FormdefReference'),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='association',
|
||||
name='source_type',
|
||||
field=models.ForeignKey(to='contenttypes.ContentType'),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -0,0 +1,39 @@
|
|||
# welco - multichannel request processing
|
||||
# Copyright (C) 2015 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.db import models
|
||||
|
||||
|
||||
class FormdefReference(models.Model):
|
||||
reference = models.CharField(max_length=250)
|
||||
|
||||
|
||||
class FormdataReference(models.Model):
|
||||
reference = models.CharField(max_length=250)
|
||||
|
||||
|
||||
class Association(models.Model):
|
||||
source_type = models.ForeignKey(ContentType)
|
||||
source_pk = models.PositiveIntegerField()
|
||||
source = generic.GenericForeignKey('source_type', 'source_pk')
|
||||
|
||||
formdefs = models.ManyToManyField(FormdefReference)
|
||||
formdatas = models.ManyToManyField(FormdataReference)
|
||||
|
||||
# +avis a (roles or users?)
|
||||
# +info a (roles or users?)
|
|
@ -39,6 +39,7 @@ INSTALLED_APPS = (
|
|||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'welco.sources.mail',
|
||||
'welco.qualif',
|
||||
'gadjo',
|
||||
)
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{% load i18n %}
|
||||
<h2>{% trans 'Mails' %}</h2>
|
||||
<div>
|
||||
<div data-source-type="{{ source_type.id }}">
|
||||
<div class="mails">
|
||||
<ul>
|
||||
{% for mail in mails %}
|
||||
<li data-pdf-href="{{ mail.content.url }}">{{ mail.creation_timestamp }}</li>
|
||||
<li data-source-pk="{{ mail.id }}" data-pdf-href="{{ mail.content.url }}">{{ mail.creation_timestamp }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django import template
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.template import RequestContext
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
|
||||
|
@ -35,5 +36,6 @@ class Home(object):
|
|||
def render(self):
|
||||
context = RequestContext(self.request)
|
||||
context['mails'] = Mail.objects.all()
|
||||
context['source_type'] = ContentType.objects.get_for_model(Mail)
|
||||
tmpl = template.loader.get_template('welco/mail_home.html')
|
||||
return tmpl.render(context)
|
||||
|
|
|
@ -100,9 +100,8 @@ div#content .cell form div.sep {
|
|||
background: #ccc;
|
||||
}
|
||||
|
||||
div#content .cell.qualif form button.done {
|
||||
div#content .cell.qualif form button.add {
|
||||
position: absolute;
|
||||
bottom: 1ex;
|
||||
right: 1ex;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,30 @@ $(function() {
|
|||
window.location.protocol + '//' + window.location.host);
|
||||
$(this).parent().find('li').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
var source_type = $('div.source div[data-source-type]').data('source-type');
|
||||
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
|
||||
$.ajax({url: $('.cell.qualif').data('zone-url'),
|
||||
data: {source_type: source_type,
|
||||
source_pk: source_pk},
|
||||
async: true,
|
||||
dataType: 'html',
|
||||
success: function(data) { $('.cell.qualif > div').replaceWith(data); },
|
||||
error: function(error) { console.log(':(', error); }
|
||||
});
|
||||
|
||||
});
|
||||
$('.qualif').delegate('button', 'click', function() {
|
||||
var formdef_reference = $('#id_formdef_reference').val();
|
||||
var source_type = $('div.source div[data-source-type]').data('source-type');
|
||||
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
|
||||
$.ajax({url: $('.cell.qualif').data('zone-url'),
|
||||
data: {formdef_reference: formdef_reference,
|
||||
source_type: source_type,
|
||||
source_pk: source_pk},
|
||||
method: 'POST',
|
||||
dataType: 'html',
|
||||
success: function(data) { $('.cell.qualif > div').replaceWith(data); },
|
||||
error: function(error) { console.log(':(', error); }
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
{% block content %}
|
||||
<div class="all">
|
||||
<div class="cell document top">
|
||||
<div class="cell document source top">
|
||||
{{ source.render }}
|
||||
</div>
|
||||
<div class="cell knowledgedb">
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
{% load i18n %}
|
||||
<div>
|
||||
<form>
|
||||
<p>{% trans 'Associated Form' %}</p>
|
||||
{% if association %}
|
||||
<ul>
|
||||
{% for formdef in association.formdefs.all %}
|
||||
<li> {{formdef.reference}} </li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
<div>
|
||||
{{form.as_p}}
|
||||
{{form.formdef_reference}}
|
||||
</div>
|
||||
<div class="sep">
|
||||
</div>
|
||||
<div>
|
||||
<label>{% trans 'Object:' %}</label>
|
||||
<input type="text"/>
|
||||
</div>
|
||||
<div>
|
||||
<label>{% trans 'Tag:' %}</label>
|
||||
<input type="text"/>
|
||||
</div>
|
||||
<button class="done">{% trans 'Done' %}</button>
|
||||
<button class="add">{% trans 'Add' %}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -16,10 +16,13 @@
|
|||
|
||||
from django.contrib.auth import logout as auth_logout
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import resolve_url
|
||||
from django import template
|
||||
from django.template import RequestContext
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
try:
|
||||
|
@ -28,6 +31,7 @@ except ImportError:
|
|||
get_idps = lambda: []
|
||||
|
||||
from sources.mail.views import Home as MailHome
|
||||
from .qualif.models import Association, FormdefReference
|
||||
from .forms import QualificationForm
|
||||
|
||||
|
||||
|
@ -56,9 +60,29 @@ class Qualification(TemplateView):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super(Qualification, self).get_context_data(**kwargs)
|
||||
context['form'] = QualificationForm()
|
||||
try:
|
||||
context['association'] = Association.objects.get(
|
||||
source_type=ContentType.objects.get(id=self.request.GET['source_type']),
|
||||
source_pk=self.request.GET['source_pk'])
|
||||
except Association.DoesNotExist:
|
||||
pass
|
||||
return context
|
||||
|
||||
qualification = Qualification.as_view()
|
||||
def post(self, request, *args, **kwargs):
|
||||
association, created = Association.objects.get_or_create(
|
||||
source_type=ContentType.objects.get(id=request.POST['source_type']),
|
||||
source_pk=request.POST['source_pk'])
|
||||
if created:
|
||||
association.save()
|
||||
formdef_ref, created = FormdefReference.objects.get_or_create(
|
||||
reference=request.POST['formdef_reference'])
|
||||
if created:
|
||||
formdef_ref.save()
|
||||
association.formdefs.add(formdef_ref)
|
||||
request.GET = request.POST
|
||||
return self.get(request)
|
||||
|
||||
qualification = csrf_exempt(Qualification.as_view())
|
||||
|
||||
|
||||
class Home(TemplateView):
|
||||
|
|
Loading…
Reference in New Issue