wcs: add a tracking code input cell (#6630)

This commit is contained in:
Frédéric Péters 2015-04-29 15:21:58 +02:00
parent aeb9f4e78a
commit b611d57e98
3 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('auth', '0001_initial'),
('data', '0005_auto_20150226_0903'),
('wcs', '0006_categoriescell'),
]
operations = [
migrations.CreateModel(
name='TrackingCodeInputCell',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('placeholder', models.CharField(max_length=20)),
('order', models.PositiveIntegerField()),
('slug', models.SlugField(verbose_name='Slug', blank=True)),
('public', models.BooleanField(default=True, verbose_name='Public')),
('wcs_site', models.CharField(max_length=50, verbose_name='Site', blank=True)),
('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
('page', models.ForeignKey(to='data.Page')),
],
options={
'abstract': False,
'verbose_name': 'Tracking Code Input',
},
bases=(models.Model,),
),
]

View File

@ -294,3 +294,28 @@ class CategoriesCell(WcsDataBaseCell):
template = renderer.render_template()
context = renderer.render(context)
return template.render(context)
@register_cell_class
class TrackingCodeInputCell(CellBase):
is_enabled = classmethod(is_wcs_enabled)
wcs_site = models.CharField(_('Site'), max_length=50, blank=True)
template_name = 'combo/wcs/tracking_code_input.html'
class Meta:
verbose_name = _('Tracking Code Input')
def get_default_form_class(self):
if len(settings.COMBO_WCS_SITES) == 1:
return None
combo_wcs_sites = [(x, y.get('title')) for x, y in settings.COMBO_WCS_SITES.items()]
return model_forms.modelform_factory(self.__class__,
fields=['wcs_site'],
widgets={'wcs_site': Select(choices=combo_wcs_sites)})
def render(self, context):
tmpl = template.loader.get_template(self.template_name)
if not self.wcs_site:
self.wcs_site = settings.COMBO_WCS_SITES.keys()[0]
context['url'] = settings.COMBO_WCS_SITES.get(self.wcs_site).get('url')
return tmpl.render(context)

View File

@ -0,0 +1,24 @@
{% load i18n %}
<div class="wcs-tracking-code-input">
<h2>{% trans 'Tracking Code' %}</h2>
<form data-wcs-url="{{ url }}">
<p>
{% blocktrans %}
A tracking code is attached to all your forms, it is there to help you in
dealing with the administration. To find the details of a form linked to
a tracking code, you can enter the code in the entry below:
{% endblocktrans %}
</p>
<input id="tracking-code" placeholder="{% trans 'ex: CNPHNTFB' %}"/>
<input type="submit" value="{% trans 'Submit' %}"/>
</form>
<script type="text/javascript">
$(function() {
$('.wcs-tracking-code-input form').on('submit', function() {
var url = $(this).data('wcs-url');
window.location = url + 'code/' + $(this).find('input').val() + '/load';
return false;
});
});
</script>
</div>