diff options
| -rw-r--r-- | ishtar_common/forms.py | 3 | ||||
| -rw-r--r-- | ishtar_common/migrations/0069_userprofile_show_field_number.py | 20 | ||||
| -rw-r--r-- | ishtar_common/models.py | 22 | ||||
| -rw-r--r-- | ishtar_common/templates/blocks/bs_field_snippet.html | 3 | ||||
| -rw-r--r-- | ishtar_common/templatetags/table_form.py | 18 | ||||
| -rw-r--r-- | scss/custom.scss | 6 | 
6 files changed, 66 insertions, 6 deletions
| diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 412adaf91..433562f72 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -169,10 +169,13 @@ class CustomForm(object):              for k in sorted(new_fields.keys()):                  if idx - 10 <= k < idx:                      alt_key, alt_field = new_fields.pop(k) +                    alt_field.order_number = k                      fields[alt_key] = alt_field +            c_field.order_number = idx              fields[key] = c_field          for k in sorted(new_fields.keys()):              alt_key, alt_field = new_fields.pop(k) +            alt_field.order_number = k              fields[alt_key] = alt_field          self.fields = fields diff --git a/ishtar_common/migrations/0069_userprofile_show_field_number.py b/ishtar_common/migrations/0069_userprofile_show_field_number.py new file mode 100644 index 000000000..5704b9f69 --- /dev/null +++ b/ishtar_common/migrations/0069_userprofile_show_field_number.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-23 12:51 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0068_ishtarsiteprofile_config'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='userprofile', +            name='show_field_number', +            field=models.BooleanField(default=False, verbose_name='Show field number'), +        ), +    ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index d14e9b346..51d3550e9 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2997,6 +2997,8 @@ class UserProfile(models.Model):      areas = models.ManyToManyField("Area", verbose_name=_(u"Areas"),                                     blank=True, related_name='profiles')      current = models.BooleanField(_(u"Current profile"), default=False) +    show_field_number = models.BooleanField( +        _(u"Show field number"), default=False)      person = models.ForeignKey(          Person, verbose_name=_(u"Person"), related_name='profiles') @@ -3062,6 +3064,16 @@ class UserProfile(models.Model):              p.save() +def post_save_userprofile(sender, **kwargs): +    if not kwargs.get('instance'): +        return +    instance = kwargs.get('instance') +    instance.person.ishtaruser.show_field_number(update=True) + + +post_save.connect(post_save_userprofile, sender=UserProfile) + +  class IshtarUser(FullSearch):      TABLE_COLS = ('username', 'person__name', 'person__surname',                    'person__email', 'person__person_types_list', @@ -3123,6 +3135,16 @@ class IshtarUser(FullSearch):      def __unicode__(self):          return unicode(self.person) +    def show_field_number(self, update=False): +        cache_key, value = get_cache(self.__class__, ['show_field_number']) +        if not update and value is not None: +            return value +        value = False +        if self.current_profile: +            value = self.current_profile.show_field_number +        cache.set(cache_key, value, settings.CACHE_TIMEOUT) +        return value +      @property      def current_profile_name(self):          q = UserProfile.objects.filter(current=True, person__ishtaruser=self) diff --git a/ishtar_common/templates/blocks/bs_field_snippet.html b/ishtar_common/templates/blocks/bs_field_snippet.html index 6a6ea5360..c7b97c6de 100644 --- a/ishtar_common/templates/blocks/bs_field_snippet.html +++ b/ishtar_common/templates/blocks/bs_field_snippet.html @@ -2,6 +2,9 @@      <div class="form-group {% if field.field.widget.attrs.cols %}col-lg-12{% else %}col-lg-6{% endif %}{% if field.errors %} is-invalid{% endif %}{% if field.field.required %} required{% endif %}"           data-alt-name="{{field.field.alt_name}}">          {% if field.label %}{{ field.label_tag }}{% endif %} +        {% if show_field_number %}<span class="badge badge-pill badge-success field-tip"> +            {{field.field.order_number}} +        </span>{% endif %}          {% if field.help_text %}          <div class="input-group">          {% endif %} diff --git a/ishtar_common/templatetags/table_form.py b/ishtar_common/templatetags/table_form.py index 0aee9919b..9fcfdfd4f 100644 --- a/ishtar_common/templatetags/table_form.py +++ b/ishtar_common/templatetags/table_form.py @@ -7,9 +7,12 @@ from django.utils.translation import ugettext_lazy as _  register = Library() -@register.inclusion_tag('blocks/bs_form_snippet.html') -def bs_form(form, position=0): -    return {'form': form, 'odd': position % 2} +@register.inclusion_tag('blocks/bs_form_snippet.html', takes_context=True) +def bs_form(context, form, position=0): +    user = context['user'] +    show_field_number = user.ishtaruser and user.ishtaruser.show_field_number() +    return {'form': form, 'odd': position % 2, +            'show_field_number': show_field_number}  @register.inclusion_tag('blocks/table_form_snippet.html') @@ -17,11 +20,14 @@ def table_form(form):      return {'form': form} -@register.inclusion_tag('blocks/bs_field_snippet.html') -def bs_field(field, required=False, label=None): +@register.inclusion_tag('blocks/bs_field_snippet.html', takes_context=True) +def bs_field(context, field, required=False, label=None): +    user = context['user'] +    show_field_number = user.ishtaruser and user.ishtaruser.show_field_number()      if label:          label = _(label) -    return {'field': field, 'required': required, 'label': label} +    return {'field': field, 'required': required, 'label': label, +            'show_field_number': show_field_number}  @register.inclusion_tag('blocks/table_field.html') diff --git a/scss/custom.scss b/scss/custom.scss index 7ccc8dbc6..e0b9cbe74 100644 --- a/scss/custom.scss +++ b/scss/custom.scss @@ -76,6 +76,12 @@ pre {      padding: 0.5rem 2rem;  } +.field-tip{ +    position: absolute; +    right: 10px; +    top: 5px; +    opacity: 0.7; +}  .form-group .select2-container--default .select2-selection--multiple {      border: $input-border-width solid $input-border-color; | 
