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
|
|
|
|
from django.contrib.contenttypes import generic
|
2015-10-09 18:01:00 +02:00
|
|
|
from django.core.urlresolvers 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):
|
|
|
|
source_type = models.ForeignKey(ContentType)
|
|
|
|
source_pk = models.PositiveIntegerField()
|
|
|
|
source = generic.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)
|
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['channel'] = self.source._meta.app_label
|
|
|
|
context['summary_url'] = request.build_absolute_uri(
|
|
|
|
reverse('wcs-summary', kwargs={'source_type': self.source_type_id,
|
|
|
|
'source_pk': self.source_pk}))
|
2015-10-09 14:59:29 +02:00
|
|
|
self.formdata_id = push_wcs_formdata(request, self.formdef_reference, context)
|
|
|
|
self.save()
|
2015-07-15 16:40:37 +02:00
|
|
|
|
2015-10-09 14:01:59 +02:00
|
|
|
@property
|
|
|
|
def formdef_name(self):
|
|
|
|
return get_wcs_formdef_details(self.formdef_reference).get('title')
|
|
|
|
|
|
|
|
@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)
|