qualif: mark triaged sources
This commit is contained in:
parent
20ea668258
commit
caa9ceafae
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('qualif', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='association',
|
||||
name='triaged',
|
||||
field=models.BooleanField(default=False),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -17,6 +17,8 @@
|
|||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from welco.utils import get_wcs_formdef_details
|
||||
|
||||
|
@ -37,9 +39,19 @@ class Association(models.Model):
|
|||
source_type = models.ForeignKey(ContentType)
|
||||
source_pk = models.PositiveIntegerField()
|
||||
source = generic.GenericForeignKey('source_type', 'source_pk')
|
||||
triaged = models.BooleanField(default=False)
|
||||
|
||||
formdefs = models.ManyToManyField(FormdefReference)
|
||||
formdatas = models.ManyToManyField(FormdataReference)
|
||||
|
||||
# +avis a (roles or users?)
|
||||
# +info a (roles or users?)
|
||||
|
||||
|
||||
@receiver(post_save)
|
||||
def association_triaged(sender, instance, **kwargs):
|
||||
if not sender is Association:
|
||||
return
|
||||
if instance.source.triaged != instance.triaged:
|
||||
instance.source.triaged = instance.triaged
|
||||
instance.source.save()
|
||||
|
|
|
@ -23,6 +23,7 @@ class Mail(models.Model):
|
|||
verbose_name = _('Mail')
|
||||
|
||||
content = models.FileField(_('Content'))
|
||||
triaged = models.BooleanField(default=False)
|
||||
|
||||
creation_timestamp = models.DateTimeField(auto_now_add=True)
|
||||
last_update_timestamp = models.DateTimeField(auto_now=True)
|
||||
|
|
|
@ -21,7 +21,7 @@ $(function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
$('.qualif').delegate('button', 'click', function() {
|
||||
$('.qualif').delegate('button.add', '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');
|
||||
|
@ -36,6 +36,29 @@ $(function() {
|
|||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.qualif').delegate('button.done', '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: $(this).data('action-url'),
|
||||
data: {formdef_reference: formdef_reference,
|
||||
source_type: source_type,
|
||||
source_pk: source_pk},
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
if (data.result == 'ok') {
|
||||
window.location.reload();
|
||||
} else {
|
||||
/* TODO: display error notification */
|
||||
}
|
||||
},
|
||||
error: function(error) { console.log(':(', error); }
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.qualif').delegate('a.plus', 'click', function() {
|
||||
$(this).parents('li').hide();
|
||||
$('.qualif .add-formdef-reference').show();
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<button class="add">{% trans 'Add' %}</button>
|
||||
</div>
|
||||
{% if association %}
|
||||
<button class="done">{% trans 'Done' %}</button>
|
||||
<button class="done" data-action-url="{% url 'qualif-done' %}">{% trans 'Done' %}</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -23,6 +23,7 @@ from . import apps
|
|||
urlpatterns = patterns('',
|
||||
url(r'^$', 'welco.views.home', name='home'),
|
||||
url(r'^ajax/qualification$', 'welco.views.qualification', name='qualif-zone'),
|
||||
url(r'^ajax/qualification-done$', 'welco.views.qualification_done', name='qualif-done'),
|
||||
|
||||
url(r'^ajax/kb$', 'welco.kb.views.zone', name='kb-zone'),
|
||||
url(r'^kb/$', 'welco.kb.views.page_list', name='kb-home'),
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
# 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/>.
|
||||
|
||||
import json
|
||||
|
||||
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.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import resolve_url
|
||||
from django import template
|
||||
from django.template import RequestContext
|
||||
|
@ -96,3 +98,15 @@ class Home(TemplateView):
|
|||
return context
|
||||
|
||||
home = Home.as_view()
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def qualification_done(request):
|
||||
association = Association.objects.get(
|
||||
source_type=ContentType.objects.get(id=request.POST['source_type']),
|
||||
source_pk=request.POST['source_pk'])
|
||||
association.triaged = True
|
||||
association.save()
|
||||
response = HttpResponse(content_type='application/json')
|
||||
json.dump({'result': 'ok'}, response, indent=2)
|
||||
return response
|
||||
|
|
Loading…
Reference in New Issue