| author | ymh <ymh.work@gmail.com> |
| Sat, 05 Apr 2014 23:29:54 +0200 | |
| changeset 168 | ac755301cea3 |
| parent 131 | f1854630734f |
| permissions | -rw-r--r-- |
|
114
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
| 126 | 2 |
# |
| 131 | 3 |
# Copyright IRI (c) 2013 |
| 126 | 4 |
# |
5 |
# contact@iri.centrepompidou.fr |
|
6 |
# |
|
7 |
# This software is governed by the CeCILL-B license under French law and |
|
8 |
# abiding by the rules of distribution of free software. You can use, |
|
9 |
# modify and/ or redistribute the software under the terms of the CeCILL-B |
|
10 |
# license as circulated by CEA, CNRS and INRIA at the following URL |
|
11 |
# "http://www.cecill.info". |
|
12 |
# |
|
13 |
# As a counterpart to the access to the source code and rights to copy, |
|
14 |
# modify and redistribute granted by the license, users are provided only |
|
15 |
# with a limited warranty and the software's author, the holder of the |
|
16 |
# economic rights, and the successive licensors have only limited |
|
17 |
# liability. |
|
18 |
# |
|
19 |
# In this respect, the user's attention is drawn to the risks associated |
|
20 |
# with loading, using, modifying and/or developing or reproducing the |
|
21 |
# software by the user in light of its specific status of free software, |
|
22 |
# that may mean that it is complicated to manipulate, and that also |
|
23 |
# therefore means that it is reserved for developers and experienced |
|
24 |
# professionals having in-depth computer knowledge. Users are therefore |
|
25 |
# encouraged to load and test the software's suitability as regards their |
|
26 |
# requirements in conditions enabling the security of their systems and/or |
|
27 |
# data to be ensured and, more generally, to use and operate it in the |
|
28 |
# same conditions as regards security. |
|
29 |
# |
|
30 |
# The fact that you are presently reading this means that you have had |
|
31 |
# knowledge of the CeCILL-B license and that you accept its terms. |
|
32 |
# |
|
|
114
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
|
| 126 | 34 |
|
| 119 | 35 |
from django.conf import settings |
|
114
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
from django.db import models |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
from haystack import signals |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
|
| 119 | 39 |
import p4l.models.signals |
40 |
||
|
114
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
|
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
class P4lSignalProcessor(signals.BaseSignalProcessor): |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
|
| 119 | 44 |
def handle_delete(self, sender, instance, **kwargs): |
45 |
if getattr(settings, "REALTIME_INDEXING", True): |
|
46 |
signals.BaseSignalProcessor.handle_delete(self, sender, instance, **kwargs) |
|
47 |
||
48 |
def handle_save(self, sender, instance, **kwargs): |
|
49 |
if getattr(settings, "REALTIME_INDEXING", True): |
|
50 |
signals.BaseSignalProcessor.handle_save(self, sender, instance, **kwargs) |
|
51 |
||
52 |
def __connect_signals(self, klass): |
|
53 |
p4l.models.signals.record_saved.connect(self.handle_save, sender=klass) |
|
|
114
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
models.signals.post_delete.connect(self.handle_delete, sender=klass) |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
|
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
def __disconnect_signals(self, klass): |
| 119 | 57 |
p4l.models.signals.record_saved.disconnect(self.handle_save, sender=klass) |
|
114
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
models.signals.post_delete.disconnect(self.handle_delete, sender=klass) |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
|
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
|
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
def setup(self): |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
#put import here to avoid circular |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
from p4l.models.data import Record |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
self.__connect_signals(Record) |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
|
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
|
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
|
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
def teardown(self): |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
|
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
from p4l.models.data import Record |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
self.__disconnect_signals(Record) |
|
93b45b4f423c
add corporate authors and small adjustments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |