コード例 #1
0
# -*- coding: utf-8 -*-
import logging
from django.apps import AppConfig, apps

import swapper
from django.conf import settings
from django.utils.functional import SimpleLazyObject

log = logging.getLogger(__name__)

swapper.set_app_prefix("django_input_collection", "input")


class InputConfig(AppConfig):
    name = "django_input_collection"
    verbose_name = "Input Collection"


class InputConfigApp:

    # Note this can be a callable to get data (print)
    VERBOSE_LOGGING = getattr(settings, "VERBOSE_INPUT_DEBUGGING", False)

    @classmethod
    def get_config(cls):
        """Returns an importable lazy wrapper for the appconfig of an app by its name."""
        return SimpleLazyObject(lambda: apps.get_app_config(cls.app_name()))

    @classmethod
    def app_name(cls):
        """Return app name without a package prefix."""
コード例 #2
0
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Case, Value, When
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _

import swapper

from wagtail.admin.utils import send_mail
from wagtail.core.models import UserPagePermissionsProxy

# make the setting name WAGTAILREVIEW_REVIEW_MODEL rather than WAGTAIL_REVIEW_REVIEW_MODEL
swapper.set_app_prefix('wagtail_review', 'wagtailreview')

REVIEW_STATUS_CHOICES = [
    ('open', _("Open")),
    ('closed', _("Closed")),
]


class BaseReview(models.Model):
    """
    Abstract base class for Review models. Can be subclassed to specify application-specific fields, e.g. review type
    """
    page_revision = models.ForeignKey('wagtailcore.PageRevision',
                                      related_name='+',
                                      on_delete=models.CASCADE,
                                      editable=False)
コード例 #3
0
ファイル: models.py プロジェクト: harshalgalgale/wq.db
from django.db import models
from django import forms
from django.conf import settings
import swapper
from wq.db.patterns.models import AnnotatedModel

from wq.io.util import guess_type

swapper.set_app_prefix('files', 'WQ')


# Custom FileField handles both images and files
class FileField(models.ImageField):
    # Use base forms.FileField to skip ImageField validation
    def formfield(self, **kwargs):
        kwargs['form_class'] = forms.FileField
        return super(FileField, self).formfield(**kwargs)

    # Only update_dimension_fields for images
    def update_dimension_fields(self, instance, force=False, *args, **kwargs):
        if (getattr(instance, 'mimetype', None) is not None
                and 'image' in instance.mimetype):
            super(FileField, self).update_dimension_fields(instance, force,
                                                           *args, **kwargs)
        else:
            pass

    # Allow model to specify upload directory
    def generate_filename(self, instance, filename):
        if hasattr(instance, 'get_directory'):
            self.upload_to = instance.get_directory()
コード例 #4
0
ファイル: models.py プロジェクト: TipOfit/vera
from wq.db.patterns import models
import swapper
from django.db.models.signals import post_save
from django.core.exceptions import ImproperlyConfigured
from django.dispatch import receiver
from django.utils.timezone import now
from django.utils.six import string_types
from django.conf import settings
from collections import OrderedDict
from .compat import clone_field

swapper.set_app_prefix('vera', 'WQ')
MODELS = swapper.get_model_names(
    'vera', ('Site', 'Event', 'Report', 'ReportStatus', 'Parameter', 'Result')
)

VALID_REPORT_ORDER = getattr(settings, "WQ_VALID_REPORT_ORDER", ('-entered',))
# Base classes for Site-Event-Report-Attribute-Value pattern
# Extend these when swapping out default implementation (below)


class BaseSite(models.NaturalKeyModel):
    @property
    def valid_events(self):
        events = self.event_set.filter(
            report_set__status__is_valid=True
        ).values_list('pk', flat=True)
        # FIXME: events may be duplicated
        return self.event_set.filter(pk__in=events)

    class Meta:
コード例 #5
0
ファイル: models.py プロジェクト: shaneramey/wq.db
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import (GenericForeignKey,
                                                GenericRelation)
from django.utils.translation import get_language_from_request

import swapper
swapper.set_app_prefix('mark', 'WQ')

from django.conf import settings
INSTALLED = ('wq.db.patterns.mark' in settings.INSTALLED_APPS)


class BaseMarkdownType(models.Model):
    name = models.CharField(max_length=100)

    @classmethod
    def get_current(cls, request=None):
        if request:
            try:
                kwargs = cls.get_current_filter(request)
                return cls.objects.get(**kwargs)
            except cls.DoesNotExist:
                pass
        return cls.get_default()

    @classmethod
    def get_current_filter(cls, request):
        raise NotImplementedError()

    @classmethod
コード例 #6
0
from django.db import models
from wq.db.patterns import models as patterns
import swapper

swapper.set_app_prefix('params', 'WQ')


# Base metadata classes (Site, ReportStatus, Parameter)
class BaseSite(patterns.IdentifiedModel):
    @property
    def valid_events(self):
        events = self.event_set.filter(
            report_set__status__is_valid=True
        ).values_list('pk', flat=True)
        # FIXME: events may be duplicated
        return self.event_set.filter(pk__in=events)

    class Meta(patterns.IdentifiedModel.Meta):
        abstract = True


class BaseReportStatus(patterns.IdentifiedModel):
    is_valid = models.BooleanField(default=False)

    class Meta(patterns.IdentifiedModel.Meta):
        abstract = True


class BaseParameter(patterns.IdentifiedModel):
    is_numeric = models.BooleanField(default=False)
    units = models.CharField(max_length=50, null=True, blank=True)
コード例 #7
0
ファイル: models.py プロジェクト: harshalgalgale/wq.db
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import (
    GenericForeignKey, GenericRelation
)
from django.utils.translation import get_language_from_request

import swapper
swapper.set_app_prefix('mark', 'WQ')

from django.conf import settings
INSTALLED = ('wq.db.patterns.mark' in settings.INSTALLED_APPS)


class BaseMarkdownType(models.Model):
    name = models.CharField(max_length=100)

    @classmethod
    def get_current(cls, request=None):
        if request:
            try:
                kwargs = cls.get_current_filter(request)
                return cls.objects.get(**kwargs)
            except cls.DoesNotExist:
                pass
        return cls.get_default()

    @classmethod
    def get_current_filter(cls, request):
        raise NotImplementedError()
コード例 #8
0
ファイル: models.py プロジェクト: tubaman/vera
from django.db import models
import swapper
from django.db.models.signals import post_save
from django.core.exceptions import ImproperlyConfigured
from django.dispatch import receiver
from django.utils.six import string_types
from .compat import clone_field

from vera.series.models import (Event, BaseEvent, BaseReport,
                                VALID_REPORT_ORDER)

swapper.set_app_prefix('results', 'WQ')

# Base classes for Result and EventResult
# Extend these when swapping out default implementation (below)


class ResultManager(models.Manager):
    def valid_results(self, **filter):
        Parameter = swapper.load_model('params', 'Parameter')

        filter['report__status__is_valid'] = True
        filter['empty'] = False

        # DISTINCT ON event, then parameter, collapsing results from different
        # reports into one
        distinct = ['report__event__id'] + nest_ordering(
            'type', Parameter._meta.ordering) + ['type__id']

        # ORDER BY distinct fields, then valid report order
        order = distinct + nest_ordering('report', VALID_REPORT_ORDER)
コード例 #9
0
ファイル: models.py プロジェクト: wq/vera
import swapper
from django.db.models.signals import post_save
from django.core.exceptions import ImproperlyConfigured
from django.dispatch import receiver
from django.utils.six import string_types
from .compat import clone_field


from vera.series.models import (
    Event,
    BaseEvent,
    BaseReport,
    VALID_REPORT_ORDER
)

swapper.set_app_prefix('results', 'WQ')


# Base classes for Result and EventResult
# Extend these when swapping out default implementation (below)

class ResultManager(models.Manager):
    def valid_results(self, **filter):
        Parameter = swapper.load_model('params', 'Parameter')

        filter['report__status__is_valid'] = True
        filter['empty'] = False

        # DISTINCT ON event, then parameter, collapsing results from different
        # reports into one
        distinct = ['report__event__id'] + nest_ordering(
コード例 #10
0
ファイル: models.py プロジェクト: tubaman/vera
from django.db import models
from natural_keys import NaturalKeyModel
from wq.db.patterns.models import LabelModel
import swapper
from django.utils.timezone import now
from django.conf import settings
from collections import OrderedDict

swapper.set_app_prefix('series', 'WQ')

VALID_REPORT_ORDER = getattr(settings, "WQ_VALID_REPORT_ORDER", ('-entered',))
# Base classes for Event-Report pattern
# Extend these when swapping out default implementation (below)


class BaseEvent(NaturalKeyModel, LabelModel):
    site = models.ForeignKey(
        swapper.get_model_name('params', 'Site'),
        null=True, blank=True, related_name="event_set",
    )

    @property
    def valid_reports(self):
        return self.report_set.filter(status__is_valid=True).order_by(
            *VALID_REPORT_ORDER
        )

    @property
    def vals(self):
        return OrderedDict([
            (a.type.natural_key()[0], a.value)
コード例 #11
0
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django import forms
from django.conf import settings
import swapper
from wq.db.patterns.models import AnnotatedModel

from wq.io.util import guess_type

swapper.set_app_prefix('files', 'WQ')


# Custom FileField handles both images and files
class FileField(models.ImageField):
    # Use base forms.FileField to skip ImageField validation
    def formfield(self, **kwargs):
        kwargs['form_class'] = forms.FileField
        return super(FileField, self).formfield(**kwargs)

    # Only update_dimension_fields for images
    def update_dimension_fields(self, instance, force=False, *args, **kwargs):
        if (getattr(instance, 'mimetype', None) is not None
                and 'image' in instance.mimetype):
            super(FileField,
                  self).update_dimension_fields(instance, force, *args,
                                                **kwargs)
        else:
            pass

    # Allow model to specify upload directory
コード例 #12
0
from django.db import models
from wq.db.patterns import models as patterns
import swapper
from django.db.models.signals import post_save
from django.core.exceptions import ImproperlyConfigured
from django.dispatch import receiver
from django.utils.timezone import now
from django.utils.six import string_types
from django.conf import settings
from collections import OrderedDict
from .compat import clone_field

swapper.set_app_prefix('vera', 'WQ')
MODELS = swapper.get_model_names(
    'vera', ('Site', 'Event', 'Report', 'ReportStatus', 'Parameter', 'Result'))

VALID_REPORT_ORDER = getattr(settings, "WQ_VALID_REPORT_ORDER", ('-entered', ))
# Base classes for Site-Event-Report-Attribute-Value pattern
# Extend these when swapping out default implementation (below)


class BaseSite(patterns.NaturalKeyModel):
    @property
    def valid_events(self):
        events = self.event_set.filter(
            report_set__status__is_valid=True).values_list('pk', flat=True)
        # FIXME: events may be duplicated
        return self.event_set.filter(pk__in=events)

    class Meta:
        abstract = True