2015-07-08 21:36:05 +02:00
|
|
|
# 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
|
2016-05-16 15:22:39 +02:00
|
|
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
2020-04-02 21:10:49 +02:00
|
|
|
from django.urls import reverse
|
2015-07-08 21:36:05 +02:00
|
|
|
from django.db import models
|
2015-09-21 14:19:04 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2015-07-08 21:36:05 +02:00
|
|
|
|
2015-09-28 15:33:59 +02:00
|
|
|
from welco.utils import get_wcs_formdef_details, push_wcs_formdata, get_wcs_services
|
2015-07-15 14:09:20 +02:00
|
|
|
|
2015-07-08 21:36:05 +02:00
|
|
|
|
|
|
|
class Association(models.Model):
|
2020-04-02 21:32:42 +02:00
|
|
|
source_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
2015-07-08 21:36:05 +02:00
|
|
|
source_pk = models.PositiveIntegerField()
|
2016-05-16 15:22:39 +02:00
|
|
|
source = GenericForeignKey('source_type', 'source_pk')
|
2015-09-21 14:19:04 +02:00
|
|
|
comments = models.TextField(blank=True, verbose_name=_('Comments'))
|
2015-10-09 14:01:59 +02:00
|
|
|
formdef_reference = models.CharField(max_length=250, null=True)
|
|
|
|
formdata_id = models.CharField(max_length=250, null=True)
|
2018-05-19 16:41:16 +02:00
|
|
|
formdata_url_backoffice = models.URLField(null=True)
|
2015-07-08 21:36:05 +02:00
|
|
|
|
2015-10-09 18:01:00 +02:00
|
|
|
def push(self, request):
|
2015-09-21 10:53:21 +02:00
|
|
|
# push validated request to wcs
|
2015-10-09 18:01:00 +02:00
|
|
|
context = {}
|
2016-02-08 18:22:20 +01:00
|
|
|
if self.source.contact_id:
|
|
|
|
context['user_id'] = self.source.contact_id
|
2015-10-09 18:01:00 +02:00
|
|
|
context['summary_url'] = request.build_absolute_uri(
|
|
|
|
reverse('wcs-summary', kwargs={'source_type': self.source_type_id, 'source_pk': self.source_pk})
|
|
|
|
)
|
2016-03-28 17:13:11 +02:00
|
|
|
context.update(self.source.get_source_context(request))
|
2018-05-19 16:41:16 +02:00
|
|
|
self.formdata_id, self.formdata_url_backoffice = push_wcs_formdata(
|
|
|
|
request, self.formdef_reference, context
|
|
|
|
)
|
2015-10-09 14:59:29 +02:00
|
|
|
self.save()
|
2015-07-15 16:40:37 +02:00
|
|
|
|
2015-10-09 14:01:59 +02:00
|
|
|
@property
|
|
|
|
def formdef_name(self):
|
2016-11-12 21:03:10 +01:00
|
|
|
try:
|
|
|
|
return get_wcs_formdef_details(self.formdef_reference).get('title')
|
|
|
|
except AttributeError:
|
|
|
|
return '?'
|
2015-10-09 14:01:59 +02:00
|
|
|
|
2016-03-22 13:25:48 +01:00
|
|
|
@property
|
|
|
|
def formdef_category(self):
|
2016-11-14 12:16:17 +01:00
|
|
|
try:
|
|
|
|
return get_wcs_formdef_details(self.formdef_reference).get('category')
|
|
|
|
except AttributeError:
|
|
|
|
return '?'
|
2016-03-22 13:25:48 +01:00
|
|
|
|
2015-10-09 14:01:59 +02:00
|
|
|
@property
|
|
|
|
def formdata_url(self):
|
|
|
|
site, formdef = self.formdef_reference.split(':')
|
|
|
|
wcs_site = get_wcs_services().get(site)
|
2015-10-11 17:23:37 +02:00
|
|
|
return '%sbackoffice/management/%s/%s/' % (wcs_site.get('url'), formdef, self.formdata_id)
|