How to use the rdmo.core.models.TranslationMixin function in rdmo

To help you get started, we’ve selected a few rdmo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rdmorganiser / rdmo / rdmo / tasks / models.py View on Github external
from datetime import date, timedelta

from django.db import models
from django.utils.translation import ugettext_lazy as _

from rdmo.core.utils import get_uri_prefix
from rdmo.core.models import TranslationMixin
from rdmo.domain.models import Attribute
from rdmo.conditions.models import Condition
from rdmo.projects.models import Value

from .managers import TaskManager
from .validators import TaskUniqueKeyValidator


class Task(TranslationMixin, models.Model):

    objects = TaskManager()

    uri = models.URLField(
        max_length=640, blank=True,
        verbose_name=_('URI'),
        help_text=_('The Uniform Resource Identifier of this task (auto-generated).')
    )
    uri_prefix = models.URLField(
        max_length=256,
        verbose_name=_('URI Prefix'),
        help_text=_('The prefix for the URI of this task.')
    )
    key = models.SlugField(
        max_length=128, blank=True,
        verbose_name=_('Key'),
github rdmorganiser / rdmo / rdmo / accounts / migrations / 0007_additional_fields.py View on Github external
fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('key', models.SlugField()),
                ('type', models.CharField(choices=[('text', 'Text'), ('textarea', 'Textarea')], max_length=11)),
                ('text_en', models.CharField(max_length=256)),
                ('text_de', models.CharField(max_length=256)),
                ('help_en', models.TextField(blank=True, help_text='Enter a help text to be displayed next to the input element', null=True)),
                ('help_de', models.TextField(blank=True, help_text='Enter a help text to be displayed next to the input element', null=True)),
                ('required', models.BooleanField()),
            ],
            options={
                'ordering': ('key',),
                'verbose_name': 'Additional field',
                'verbose_name_plural': 'Additional fields',
            },
            bases=(models.Model, rdmo.core.models.TranslationMixin),
        ),
        migrations.CreateModel(
            name='AdditionalFieldValue',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('value', models.CharField(max_length=256)),
                ('field', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='accounts.AdditionalField')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='additional_fields', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ('user', 'field'),
                'verbose_name': 'Additional field value',
                'verbose_name_plural': 'Additional field values',
            },
        ),
        migrations.DeleteModel(
github rdmorganiser / rdmo / rdmo / questions / migrations / 0001_initial_after_reset.py View on Github external
name='Subsection',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('created', models.DateTimeField(verbose_name='created', editable=False)),
                ('updated', models.DateTimeField(verbose_name='updated', editable=False)),
                ('order', models.IntegerField(null=True)),
                ('title_en', models.CharField(max_length=256)),
                ('title_de', models.CharField(max_length=256)),
                ('section', models.ForeignKey(related_name='subsections', to='questions.Section', on_delete=models.CASCADE)),
            ],
            options={
                'ordering': ('section__catalog__order', 'section__order', 'order'),
                'verbose_name': 'Subsection',
                'verbose_name_plural': 'Subsections',
            },
            bases=(models.Model, rdmo.core.models.TranslationMixin),
        ),
        migrations.CreateModel(
            name='Question',
            fields=[
                ('questionentity_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='questions.QuestionEntity', on_delete=models.CASCADE)),
                ('text_en', models.TextField()),
                ('text_de', models.TextField()),
                ('widget_type', models.CharField(max_length=12, choices=[('text', 'Text'), ('textarea', 'Textarea'), ('yesno', 'Yes/No'), ('checkbox', 'Checkboxes'), ('radio', 'Radio buttons'), ('select', 'Select drop-down'), ('range', 'Range slider'), ('date', 'Date picker')])),
            ],
            options={
                'ordering': ('subsection__section__catalog__order', 'subsection__section__order', 'subsection__order'),
                'verbose_name': 'Question',
                'verbose_name_plural': 'Questions',
            },
            bases=('questions.questionentity',),
        ),
github rdmorganiser / rdmo / rdmo / views / models.py View on Github external
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.template import Context, Template

from rdmo.core.utils import get_uri_prefix
from rdmo.core.models import TranslationMixin
from rdmo.conditions.models import Condition

from .validators import ViewUniqueKeyValidator


class View(models.Model, TranslationMixin):

    uri = models.URLField(
        max_length=640, blank=True,
        verbose_name=_('URI'),
        help_text=_('The Uniform Resource Identifier of this view (auto-generated).')
    )
    uri_prefix = models.URLField(
        max_length=256,
        verbose_name=_('URI Prefix'),
        help_text=_('The prefix for the URI of this view.')
    )
    key = models.SlugField(
        max_length=128, blank=True,
        verbose_name=_('Key'),
        help_text=_('The internal identifier of this view.')
    )
github rdmorganiser / rdmo / rdmo / accounts / models.py View on Github external
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _

from rdmo.core.models import TranslationMixin


class ProxyUser(User):

    class Meta:
        proxy = True
        default_permissions = ()
        permissions = (('view_user', 'Can view user'),)


class AdditionalField(models.Model, TranslationMixin):

    TYPE_CHOICES = (
        ('text', 'Text'),
        ('textarea', 'Textarea'),
    )

    key = models.SlugField()
    type = models.CharField(max_length=11, choices=TYPE_CHOICES)

    text_lang1 = models.CharField(
        max_length=256, blank=True,
        verbose_name=_('Text (primary)'),
        help_text=_('The text for this additional field in the primary language.')
    )
    text_lang2 = models.CharField(
        max_length=256, blank=True,
github rdmorganiser / rdmo / rdmo / questions / models.py View on Github external
from django.utils.translation import ugettext_lazy as _

from rdmo.conditions.models import Condition
from rdmo.core.constants import VALUE_TYPE_CHOICES
from rdmo.core.models import Model, TranslationMixin
from rdmo.core.utils import get_uri_prefix
from rdmo.domain.models import Attribute

from .managers import QuestionSetManager
from .validators import (CatalogUniqueKeyValidator,
                         QuestionSetUniquePathValidator,
                         QuestionUniquePathValidator,
                         SectionUniquePathValidator)


class Catalog(Model, TranslationMixin):

    uri = models.URLField(
        max_length=640, blank=True,
        verbose_name=_('URI'),
        help_text=_('The Uniform Resource Identifier of this catalog (auto-generated).')
    )
    uri_prefix = models.URLField(
        max_length=256,
        verbose_name=_('URI Prefix'),
        help_text=_('The prefix for the URI of this catalog.')
    )
    key = models.SlugField(
        max_length=128, blank=True,
        verbose_name=_('Key'),
        help_text=_('The internal identifier of this catalog.')
    )
github rdmorganiser / rdmo / rdmo / questions / models.py View on Github external
return self.trans('verbose_name')

    @property
    def verbose_name_plural(self):
        return self.trans('verbose_name_plural')

    @classmethod
    def build_path(cls, key, section):
        return '%s/%s/%s' % (
            section.catalog.key,
            section.key,
            key
        )


class Question(Model, TranslationMixin):

    WIDGET_TYPE_CHOICES = (
        ('text', 'Text'),
        ('textarea', 'Textarea'),
        ('yesno', 'Yes/No'),
        ('checkbox', 'Checkboxes'),
        ('radio', 'Radio buttons'),
        ('select', 'Select drop-down'),
        ('range', 'Range slider'),
        ('date', 'Date picker'),
    )

    uri = models.URLField(
        max_length=640, blank=True, null=True,
        verbose_name=_('URI'),
        help_text=_('The Uniform Resource Identifier of this question (auto-generated).')
github rdmorganiser / rdmo / rdmo / domain / migrations / 0001_initial_after_reset.py View on Github external
bases=(models.Model, rdmo.core.models.TranslationMixin),
        ),
        migrations.CreateModel(
            name='Range',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('minimum', models.FloatField()),
                ('maximum', models.FloatField()),
                ('step', models.FloatField()),
            ],
            options={
                'ordering': ('attribute',),
                'verbose_name': 'Range',
                'verbose_name_plural': 'Ranges',
            },
            bases=(models.Model, rdmo.core.models.TranslationMixin),
        ),
        migrations.CreateModel(
            name='Attribute',
            fields=[
                ('attributeentity_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='domain.AttributeEntity', on_delete=models.CASCADE)),
                ('value_type', models.CharField(max_length=8, choices=[('text', 'Text'), ('integer', 'Integer'), ('float', 'Float'), ('boolean', 'Boolean'), ('datetime', 'Datetime'), ('options', 'Options')])),
                ('unit', models.CharField(max_length=64, null=True, blank=True)),
            ],
            options={
                'verbose_name': 'Attribute',
                'verbose_name_plural': 'Attributes',
            },
            bases=('domain.attributeentity',),
        ),
        migrations.AddField(
            model_name='condition',
github rdmorganiser / rdmo / rdmo / domain / migrations / 0004_verbosename.py View on Github external
operations = [
        migrations.CreateModel(
            name='VerboseName',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('name_en', models.CharField(max_length=256)),
                ('name_de', models.CharField(max_length=256)),
                ('name_plural_en', models.CharField(max_length=256)),
                ('name_plural_de', models.CharField(max_length=256)),
                ('attribute_entity', models.OneToOneField(to='domain.AttributeEntity', on_delete=models.CASCADE)),
            ],
            options={
                'verbose_name': 'VerboseName',
                'verbose_name_plural': 'VerboseNames',
            },
            bases=(models.Model, rdmo.core.models.TranslationMixin),
        ),
github rdmorganiser / rdmo / rdmo / questions / models.py View on Github external
def save(self, *args, **kwargs):
        self.uri = get_uri_prefix(self) + '/questions/%s' % self.key
        super(Catalog, self).save(*args, **kwargs)

        for section in self.sections.all():
            section.save()

    def clean(self):
        CatalogUniqueKeyValidator(self)()

    @property
    def title(self):
        return self.trans('title')


class Section(Model, TranslationMixin):

    uri = models.URLField(
        max_length=640, blank=True,
        verbose_name=_('URI'),
        help_text=_('The Uniform Resource Identifier of this section (auto-generated).')
    )
    uri_prefix = models.URLField(
        max_length=256,
        verbose_name=_('URI Prefix'),
        help_text=_('The prefix for the URI of this section.')
    )
    key = models.SlugField(
        max_length=128, blank=True,
        verbose_name=_('Key'),
        help_text=_('The internal identifier of this section.')
    )