Beispiel #1
0
    def test_manager_only_create(self):
        class UserEavConfig(EavConfig):
            manager_only = True

        eav.register(User, UserEavConfig)

        c = User.objects.create(username='******')
Beispiel #2
0
    def setUp(self):
        eav.register(Encounter)
        eav.register(Patient)

        Attribute.objects.create(name='age', datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name='height', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='weight', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='city', datatype=Attribute.TYPE_TEXT)
        Attribute.objects.create(name='country', datatype=Attribute.TYPE_TEXT)

        self.yes = EnumValue.objects.create(value='yes')
        self.no = EnumValue.objects.create(value='no')
        self.unknown = EnumValue.objects.create(value='unknown')

        ynu = EnumGroup.objects.create(name='Yes / No / Unknown')
        ynu.values.add(self.yes)
        ynu.values.add(self.no)
        ynu.values.add(self.unknown)

        Attribute.objects.create(name='fever', datatype=Attribute.TYPE_ENUM, enum_group=ynu)

        self.cashback = EnumValue.objects.create(value='cashback')
        self.petrol = EnumValue.objects.create(value='petrol')
        self.lounge = EnumValue.objects.create(value='lounge')

        card_facilities = EnumGroup.objects.create(name='card_facilities')
        card_facilities.values.add(self.cashback)
        card_facilities.values.add(self.petrol)
        card_facilities.values.add(self.lounge)

        Attribute.objects.create(name='card_facilities', datatype=Attribute.TYPE_M2M, enum_group=card_facilities)
Beispiel #3
0
 def register_encounter(self):
     class EncounterEav(EavConfig):
         manager_attr = 'eav_objects'
         eav_attr = 'eav_field'
         generic_relation_attr = 'encounter_eav_values'
         generic_relation_related_name = 'encounters'
     eav.register(Encounter, EncounterEav)
Beispiel #4
0
    def test_manager_only_create(self):
        class UserEavConfig(EavConfig):
            manager_only = True

        eav.register(User, UserEavConfig)

        c = User.objects.create(username="******", email="*****@*****.**")
 def test_setting_to_none_deletes_value(self):
     eav.register(Patient)
     Attribute.objects.create(name="age", datatype=Attribute.TYPE_INT)
     p = Patient.objects.create(name="Bob", eav__age=5)
     self.assertEqual(Value.objects.count(), 1)
     p.eav.age = None
     p.save()
     self.assertEqual(Value.objects.count(), 0)
Beispiel #6
0
 def setUp(self):
     unregister(Encounter)
     unregister(Patient)
     register(Encounter, filter_by_parent=True)
     register(Patient, filter_by_parent=True)
     Attribute.objects.create(name='age', parent=Patient, datatype=Attribute.TYPE_INT)
     Attribute.objects.create(name='date', parent=Encounter, datatype=Attribute.TYPE_DATE)
     Attribute.objects.create(name='cost', parent=Encounter, datatype=Attribute.TYPE_FLOAT)
Beispiel #7
0
 def test_setting_to_none_deletes_value(self):
     eav.register(Patient)
     Attribute.objects.create(name='age', datatype=Attribute.TYPE_INT)
     p = Patient.objects.create(name='Bob', eav__age=5)
     self.assertEqual(Value.objects.count(), 1)
     p.eav.age = None
     p.save()
     self.assertEqual(Value.objects.count(), 0)
Beispiel #8
0
 def test_unregistering(self):
     old_mgr = Patient.objects
     eav.register(Patient)
     self.assertTrue(Patient.objects.__class__.__name__ == 'EntityManager')
     eav.unregister(Patient)
     self.assertFalse(Patient.objects.__class__.__name__ == 'EntityManager')
     self.assertEqual(Patient.objects, old_mgr)
     self.assertFalse(hasattr(Patient, '_eav_config_cls'))
Beispiel #9
0
    def setUp(self):
        eav.register(Patient)

        Attribute.objects.create(name="Age", datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name="DoB", datatype=Attribute.TYPE_DATE)
        Attribute.objects.create(name="Height", datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name="City", datatype=Attribute.TYPE_TEXT)
        Attribute.objects.create(name="Pregnant?", datatype=Attribute.TYPE_BOOLEAN)
        Attribute.objects.create(name="User", datatype=Attribute.TYPE_OBJECT)
Beispiel #10
0
    def setUp(self):
        eav.register(Patient)

        Attribute.objects.create(name='Age', datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name='DoB', datatype=Attribute.TYPE_DATE)
        Attribute.objects.create(name='Height', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='City', datatype=Attribute.TYPE_TEXT)
        Attribute.objects.create(name='Pregnant?', datatype=Attribute.TYPE_BOOLEAN)
        Attribute.objects.create(name='User', datatype=Attribute.TYPE_OBJECT)
Beispiel #11
0
 def test_registering_with_defaults(self):
     eav.register(Patient)
     self.assertTrue(hasattr(Patient, "_eav_config_cls"))
     self.assertEqual(Patient._eav_config_cls.manager_attr, "objects")
     self.assertFalse(Patient._eav_config_cls.manager_only)
     self.assertEqual(Patient._eav_config_cls.eav_attr, "eav")
     self.assertEqual(Patient._eav_config_cls.generic_relation_attr, "eav_values")
     self.assertEqual(Patient._eav_config_cls.generic_relation_related_name, None)
     eav.unregister(Patient)
    def test_order_by_with_custom_config(self):
        class CustomConfig(EavConfig):
            eav_attr = "data"
            generic_relation_attr = "data_values"

        self.init_data()
        eav.unregister(Patient)
        eav.register(Patient, config_cls=CustomConfig)
        self.assert_order_by_results(eav_attr='data')
Beispiel #13
0
    def setUp(self):
        eav.register(Patient)

        Attribute.objects.create(name='Age', datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name='DoB', datatype=Attribute.TYPE_DATE)
        Attribute.objects.create(name='Height', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='City', datatype=Attribute.TYPE_TEXT)
        Attribute.objects.create(name='Pregnant?', datatype=Attribute.TYPE_BOOLEAN)
        Attribute.objects.create(name='User', datatype=Attribute.TYPE_OBJECT)
    def test_model_without_local_managers(self):
        """Test when a model doesn't have local_managers."""
        # Check just in case test model changes in the future
        assert bool(User._meta.local_managers) is False
        eav.register(User)
        assert isinstance(User.objects, eav.managers.EntityManager)

        # Reverse check: managers should be empty again
        eav.unregister(User)
        assert bool(User._meta.local_managers) is False
Beispiel #15
0
 def test_registering_with_defaults(self):
     register(Patient)
     self.assertTrue(hasattr(Patient, '_eav_config_cls'))
     self.assertEqual(Patient._eav_config_cls.manager_attr, 'objects')
     self.assertFalse(Patient._eav_config_cls.manager_only)
     self.assertEqual(Patient._eav_config_cls.eav_attr, 'eav')
     self.assertEqual(Patient._eav_config_cls.generic_relation_attr,
                      'eav_values')
     self.assertEqual(Patient._eav_config_cls.generic_relation_related_name,
                      None)
     unregister(Patient)
Beispiel #16
0
 def test_registering_with_defaults(self):
     eav.register(Patient)
     self.assertTrue(hasattr(Patient, '_eav_config_cls'))
     self.assertEqual(Patient._eav_config_cls.manager_attr, 'objects')
     self.assertFalse(Patient._eav_config_cls.manager_only)
     self.assertEqual(Patient._eav_config_cls.eav_attr, 'eav')
     self.assertEqual(Patient._eav_config_cls.generic_relation_attr,
                      'eav_values')
     self.assertEqual(Patient._eav_config_cls.generic_relation_related_name,
                      None)
     eav.unregister(Patient)
Beispiel #17
0
    def register_encounter(self):
        class EncounterEav(EavConfig):
            manager_attr = 'eav_objects'
            eav_attr = 'eav_field'
            generic_relation_attr = 'encounter_eav_values'
            generic_relation_related_name = 'encounters'

            @classmethod
            def get_attributes(cls, entity=None):
                return 'testing'

        eav.register(Encounter, EncounterEav)
Beispiel #18
0
    def setUp(self):
        eav.register(Patient)

        Attribute.objects.create(name='Age', datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name='DoB', datatype=Attribute.TYPE_DATE)
        Attribute.objects.create(name='Height', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='Money', datatype=Attribute.TYPE_DECIMAL)
        Attribute.objects.create(name='City', datatype=Attribute.TYPE_TEXT)
        Attribute.objects.create(name='Pregnant?', datatype=Attribute.TYPE_BOOLEAN)
        Attribute.objects.create(name='User', datatype=Attribute.TYPE_OBJECT)
        Attribute.objects.create(name='Address', datatype=Attribute.TYPE_POINT)
        Attribute.objects.create(name='Zone', datatype=Attribute.TYPE_MULTIPOLYGON)
Beispiel #19
0
    def register_encounter(self):
        class EncounterEav(EavConfig):
            manager_attr = "eav_objects"
            eav_attr = "eav_field"
            generic_relation_attr = "encounter_eav_values"
            generic_relation_related_name = "encounters"

            @classmethod
            def get_attributes(cls):
                return "testing"

        eav.register(Encounter, EncounterEav)
Beispiel #20
0
    def register_encounter(self):
        class EncounterEav(EavConfig):
            manager_attr = 'eav_objects'
            eav_attr = 'eav_field'
            generic_relation_attr = 'encounter_eav_values'
            generic_relation_related_name = 'encounters'

            @classmethod
            def get_attributes(cls):
                return 'testing'

        eav.register(Encounter, EncounterEav)
Beispiel #21
0
    def test_registering_overriding_defaults(self):
        eav.register(Patient)
        self.register_encounter()
        self.assertTrue(hasattr(Patient, '_eav_config_cls'))
        self.assertEqual(Patient._eav_config_cls.manager_attr, 'objects')
        self.assertEqual(Patient._eav_config_cls.eav_attr, 'eav')

        self.assertTrue(hasattr(Encounter, '_eav_config_cls'))
        self.assertEqual(Encounter._eav_config_cls.manager_attr, 'eav_objects')
        self.assertEqual(Encounter._eav_config_cls.eav_attr, 'eav_field')
        eav.unregister(Patient)
        eav.unregister(Encounter)
Beispiel #22
0
    def test_registering_overriding_defaults(self):
        eav.register(Patient)
        self.register_encounter()
        self.assertTrue(hasattr(Patient, "_eav_config_cls"))
        self.assertEqual(Patient._eav_config_cls.manager_attr, "objects")
        self.assertEqual(Patient._eav_config_cls.eav_attr, "eav")

        self.assertTrue(hasattr(Encounter, "_eav_config_cls"))
        self.assertEqual(Encounter._eav_config_cls.get_attributes(), "testing")
        self.assertEqual(Encounter._eav_config_cls.manager_attr, "eav_objects")
        self.assertEqual(Encounter._eav_config_cls.eav_attr, "eav_field")
        eav.unregister(Patient)
        eav.unregister(Encounter)
    def test_illegal_assignemnt(self):
        class EncounterEavConfig(EavConfig):
            @classmethod
            def get_attributes(cls, instance=None):
                return Attribute.objects.filter(datatype=Attribute.TYPE_INT)

        eav.unregister(Encounter)
        eav.register(Encounter, EncounterEavConfig)

        p = Patient.objects.create(name='Jon')
        e = Encounter.objects.create(patient=p, num=1)

        with self.assertRaises(IllegalAssignmentException):
            e.eav.color = 'red'
            e.save()
 def test_string_enum_value_assignment(self):
     yes = EnumValue.objects.create(value='yes')
     no = EnumValue.objects.create(value='no')
     ynu = EnumGroup.objects.create(name='Yes / No / Unknown')
     ynu.values.add(yes)
     ynu.values.add(no)
     Attribute.objects.create(name='is_patient',
                              datatype=Attribute.TYPE_ENUM,
                              enum_group=ynu)
     eav.register(Patient)
     p = Patient.objects.create(name='Joe')
     p.eav.is_patient = 'yes'
     p.save()
     p = Patient.objects.get(name='Joe')  # get from DB again
     self.assertEqual(p.eav.is_patient, yes)
Beispiel #25
0
    def setUp(self):
        eav.register(Patient)
        Attribute.objects.create(name='weight', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='color', datatype=Attribute.TYPE_TEXT)

        self.female = EnumValue.objects.create(value='Female')
        self.male = EnumValue.objects.create(value='Male')
        gender_group = EnumGroup.objects.create(name='Gender')
        gender_group.values.add(self.female, self.male)

        Attribute.objects.create(name='gender',
                                 datatype=Attribute.TYPE_ENUM,
                                 enum_group=gender_group)

        self.instance = Patient.objects.create(name='Jim Morrison')
        self.site = AdminSite()
Beispiel #26
0
    def setUp(self):
        eav.register(Patient)

        Attribute.objects.create(name='Age', datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name='DoB', datatype=Attribute.TYPE_DATE)
        Attribute.objects.create(name='Height', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='City', datatype=Attribute.TYPE_TEXT)
        Attribute.objects.create(name='Pregnant?', datatype=Attribute.TYPE_BOOLEAN)

        yes = EnumValue.objects.create(value='yes')
        no = EnumValue.objects.create(value='no')
        unkown = EnumValue.objects.create(value='unkown')
        ynu = EnumGroup.objects.create(name='Yes / No / Unknown')
        ynu.enums.add(yes)
        ynu.enums.add(no)
        ynu.enums.add(unkown)
        Attribute.objects.create(name='Fever?', datatype=Attribute.TYPE_ENUM, enum_group=ynu, required=True)
    def setUp(self):
        class EncounterEavConfig(EavConfig):
            manager_attr = 'eav_objects'
            eav_attr = 'eav_field'
            generic_relation_attr = 'encounter_eav_values'
            generic_relation_related_name = 'encounters'

            @classmethod
            def get_attributes(cls):
                return Attribute.objects.filter(slug__contains='a')

        eav.register(Encounter, EncounterEavConfig)
        eav.register(Patient)

        Attribute.objects.create(name='age', datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name='height', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='weight', datatype=Attribute.TYPE_FLOAT)
Beispiel #28
0
    def setUp(self):
        class EncounterEavConfig(EavConfig):
            manager_attr = 'eav_objects'
            eav_attr = 'eav_field'
            generic_relation_attr = 'encounter_eav_values'
            generic_relation_related_name = 'encounters'

            @classmethod
            def get_attributes(cls):
                return Attribute.objects.filter(slug__contains='a')

        eav.register(Encounter, EncounterEavConfig)
        eav.register(Patient)

        Attribute.objects.create(name='age', datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name='height', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='weight', datatype=Attribute.TYPE_FLOAT)
Beispiel #29
0
    def setUp(self):
        eav.register(Encounter)
        eav.register(Patient)

        Attribute.objects.create(name="age", datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name="height", datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name="weight", datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name="city", datatype=Attribute.TYPE_TEXT)
        Attribute.objects.create(name="country", datatype=Attribute.TYPE_TEXT)

        self.yes = EnumValue.objects.create(value="yes")
        self.no = EnumValue.objects.create(value="no")
        self.unkown = EnumValue.objects.create(value="unkown")
        ynu = EnumGroup.objects.create(name="Yes / No / Unknown")
        ynu.enums.add(self.yes)
        ynu.enums.add(self.no)
        ynu.enums.add(self.unkown)
        Attribute.objects.create(name="fever", datatype=Attribute.TYPE_ENUM, enum_group=ynu)
Beispiel #30
0
    def setUp(self):
        eav.register(Encounter)
        eav.register(Patient)

        Attribute.objects.create(name='age', datatype=Attribute.TYPE_INT)
        Attribute.objects.create(name='height', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='weight', datatype=Attribute.TYPE_FLOAT)
        Attribute.objects.create(name='city', datatype=Attribute.TYPE_TEXT)
        Attribute.objects.create(name='country', datatype=Attribute.TYPE_TEXT)

        self.yes = EnumValue.objects.create(value='yes')
        self.no = EnumValue.objects.create(value='no')
        self.unkown = EnumValue.objects.create(value='unkown')
        ynu = EnumGroup.objects.create(name='Yes / No / Unknown')
        ynu.enums.add(self.yes)
        ynu.enums.add(self.no)
        ynu.enums.add(self.unkown)
        Attribute.objects.create(name='fever', datatype=Attribute.TYPE_ENUM, enum_group=ynu)
Beispiel #31
0
    """
    message = models.ForeignKey(Message, null=True, related_name='poll_responses')
    poll = models.ForeignKey(Poll, related_name='responses')
    contact = models.ForeignKey(Contact, null=True, blank=True, related_name='responses')
    date = models.DateTimeField(auto_now_add=True)
    has_errors = models.BooleanField(default=False)

    def update_categories(self, categories, user):
        for c in categories:
            if not self.categories.filter(category=c).count():
                ResponseCategory.objects.create(response=self, category=c, is_override=True, user=user)
        for rc in self.categories.all():
            if not rc.category in categories:
                rc.delete()

register(Response)

class Rule(models.Model):
    """
    A rule is a regular expression that an incoming message text might
    satisfy to belong in a particular category.  A message must satisfy
    one or more rules to belong to a category.
    """

    contains_all_of=1
    contains_one_of=2



    TYPE_STARTSWITH = 'sw'
    TYPE_CONTAINS = 'c'
Beispiel #32
0
class Survey(models.Model):
    edx_project = models.ForeignKey(EdxProject)
    is_draft = models.BooleanField(default=True)
    logo = models.ImageField(upload_to='images', blank=True)
    timestamp = models.DateTimeField(auto_now_add=True, blank=True, null=True)

    def __unicode__(self):
        if self.timestamp:
            return u"Survey for %s from %s" % (self.edx_project.name,
                                               self.timestamp.date())
        else:
            return u"Survey for %s" % self.edx_project.name


eav.register(Survey)
pre_save.disconnect(eav.models.Entity.pre_save_handler, sender=Survey)


class FormStep(SortableMixin):
    name = models.CharField(max_length=32)
    description = models.TextField(blank=True)
    order = models.PositiveIntegerField(default=0,
                                        editable=False,
                                        db_index=True)

    class Meta:
        ordering = ['order']

    def __unicode__(self):
        return self.name
Beispiel #33
0
# vim: ai ts=4 sts=4 et sw=4

from django.contrib import admin
from .models import *
import eav

admin.site.register(Report)
admin.site.register(Record)  

admin.site.register(Parameter)
admin.site.register(ReportView)

admin.site.register(SelectedIndicator)

admin.site.register(Indicator)
admin.site.register(ValueIndicator)
admin.site.register(SumIndicator)
admin.site.register(RatioIndicator)
admin.site.register(RateIndicator)
admin.site.register(AverageIndicator)
admin.site.register(ProductIndicator)
admin.site.register(DifferenceIndicator)
admin.site.register(DateIndicator)
admin.site.register(LocationIndicator)

admin.site.register(Aggregator)
admin.site.register(DateAggregator)
admin.site.register(LocationAggregator)

eav.register(Record)
Beispiel #34
0
    @property
    def review_count(self):
        from review.models import Review

        return Review.objects.filter(item__category=self).count()

    @property
    def vote_count(self):
        from vote.models import Vote

        return Vote.objects.filter(review__item__category=self).count()

    @property
    def attachment_count(self):
        """
        Return the number of attachments for all Items belonging to this Category
        """
        from attachment.models import Attachment

        return Attachment.objects.filter(
            content_type=ContentType.objects.get(app_label="item",
                                                 model="item"),
            object_id__in=[
                str(x) for x in self.items.all().values_list("uuid", flat=True)
            ],
        ).count()


# register Category model with django-eav2
eav.register(Category, CategoryEavConfig)
Beispiel #35
0
        return None


    class Meta:
        ordering = ['title']
        get_latest_by = 'id'
    
    def __unicode__(self):
        
        return self.title
        
    @models.permalink
    def get_absolute_url(self):
        return ("package", [self.slug])

eav.register(Package)

        

class PackageExample(BaseModel):
    
    package = models.ForeignKey(Package)
    title = models.CharField(_("Title"), max_length="100")
    url = models.URLField(_("URL"))
    active = models.BooleanField(_("Active"), default=True, help_text="Moderators have to approve links before they are provided")
    
    class Meta:
        ordering = ['title']
    
    def __unicode__(self):
        return self.title
Beispiel #36
0
import eav
from django.db import models

class Product(models.Model):
    title = models.CharField(max_length=150)
    price = models.DecimalField(max_digits=20,decimal_places=4)

    def __unicode__(self):
        return self.title


eav.register(Product)


Beispiel #37
0
    cm_enabled = models.BooleanField(default=False)
    # here also configuration management (cm) related values or specific table
    # for cm values?
    ping_status = models.NullBooleanField()
    ping_last_checked = models.DateField(null=True)
    tags = TaggableManager(through=GestioIPTaG)

    def __str__(self):
        return self.ip_address


class Line(models.Model):
    client = models.ForeignKey(Client, on_delete=models.CASCADE)
    provider = models.ForeignKey(Company, blank=True, null=True)
    phone_number = models.CharField(max_length=254, validators=[phone_regex],
                                    blank=True)  # validators should be a list
    number = models.IntegerField(unique=True, blank=False)
    name = models.CharField(unique=True, max_length=254)
    comment = models.CharField(blank=True, max_length=254,
                               help_text="Short comment")
    description = models.TextField(blank=True, help_text="Descriptive text")
    tags = TaggableManager(through=GestioIPTaG)

    # custom columns

    def __str__(self):
        return self.name


eav.register(IP)
eav.register(Network)
Beispiel #38
0
# vim: ai ts=4 sts=4 et sw=4

from django.contrib import admin
from .models import *
import eav

admin.site.register(Report)
admin.site.register(Record)

admin.site.register(Parameter)
admin.site.register(ReportView)

admin.site.register(SelectedIndicator)

admin.site.register(Indicator)
admin.site.register(ValueIndicator)
admin.site.register(SumIndicator)
admin.site.register(RatioIndicator)
admin.site.register(RateIndicator)
admin.site.register(AverageIndicator)
admin.site.register(ProductIndicator)
admin.site.register(DifferenceIndicator)
admin.site.register(DateIndicator)
admin.site.register(LocationIndicator)

admin.site.register(Aggregator)
admin.site.register(DateAggregator)
admin.site.register(LocationAggregator)

eav.register(Record)
import eav
from risks.models import Risk
from eav.models import Value, Attribute, EnumValue, EnumGroup
from django.utils import timezone

eav.register(Risk)

# create attributes
# text, number, date, or enum
weight_att = Attribute.objects.create(name='Weight',
                                      datatype=Attribute.TYPE_FLOAT)
height_att = Attribute.objects.create(name='Height',
                                      datatype=Attribute.TYPE_INT)
birth_att = Attribute.objects.create(name='Birthdate',
                                     datatype=Attribute.TYPE_DATE)
breed_att = Attribute.objects.create(name='Breed',
                                     datatype=Attribute.TYPE_TEXT)

yes = EnumValue.objects.create(value='Yes')  # doctest: SKIP
no = EnumValue.objects.create(value='No')
unkown = EnumValue.objects.create(value='Unkown')
ynu = EnumGroup.objects.create(name='Yes / No / Unkown')
ynu.enums.add(yes, no, unkown)

castrated_att = Attribute.objects.create(name='Is castrated?',
                                         datatype=Attribute.TYPE_ENUM,
                                         enum_group=ynu)

risk = Risk()
risk.name = 'Cat'
risk.eav.weight = 5.25
Beispiel #40
0
    # link = None


class Survey(models.Model):
    edx_project = models.ForeignKey(EdxProject)
    is_draft = models.BooleanField(default=True)
    logo = models.ImageField(upload_to='images',blank=True)
    timestamp = models.DateTimeField(auto_now_add=True, blank=True, null=True)

    def __unicode__(self):
        if self.timestamp:
            return u"Survey for %s from %s" % (self.edx_project.name, self.timestamp.date())
        else:
            return u"Survey for %s" % self.edx_project.name

eav.register(Survey)
pre_save.disconnect(eav.models.Entity.pre_save_handler, sender=Survey)


class FormStep(SortableMixin):
    name = models.CharField(max_length=32)
    description = models.TextField(blank=True)
    order = models.PositiveIntegerField(
        default=0,
        editable=False,
        db_index=True
    )

    class Meta:
        ordering = ['order']
Beispiel #41
0
signals.pre_save.connect(pre_save_layer, sender=Layer)
signals.pre_save.connect(resourcebase_pre_save, sender=Layer)
signals.post_save.connect(resourcebase_post_save, sender=Layer)
signals.post_save.connect(post_save_layer_type, sender=LayerType)
signals.pre_delete.connect(pre_delete_layer, sender=Layer)
signals.post_delete.connect(post_delete_layer, sender=Layer)
signals.post_save.connect(share, sender=Layer)
#signals.post_delete.connect(unshare, sender=Layer)

from eav.registry import EavConfig
class EavConfigClass(EavConfig):
    manager_attr = 'eav_objects'
    object_type = 'layer_type'
    attribute_relation='layer_metadata_type_attribute'

eav.register(Layer, EavConfigClass)


#from geonode.geoserver.helpers import set_styles
from geonode.geoserver.signals import gs_catalog

def save_style(gs_style):
    style, created = Style.objects.get_or_create(name=gs_style.sld_name)
    style.sld_title = gs_style.sld_title
    style.sld_body = gs_style.sld_body
    style.sld_url = gs_style.body_href()
    style.save()
    return style

def set_styles(layer, gs_catalog):
    style_set = []
Beispiel #42
0
class PersonaForm(BaseDynamicEntityForm):
	#nascita = forms.DateField(label='Data di nascita', required=False, widget=widgets.AdminDateWidget)
	def __init__(self, *args, **kwargs):
		super(PersonaForm, self).__init__(*args, **kwargs)
		lista_attributi = eav.models.Entity(Persona).get_all_attributes()
		#pdb.set_trace()
		# da finire
		for attributo in lista_attributi:
			if attributo.datatype == 'date':
	       			self.fields[attributo.slug].widget.attrs['class'] = 'campo_tipo_data'
	class Meta:
		model = Persona
		widgets = {'competenze': forms.CheckboxSelectMultiple}

eav.register(Persona) #registro il Model Persona come associazione a eav

class Gruppo(models.Model):
	nome = models.CharField('Nome',max_length=30)
	componenti = models.ManyToManyField(Persona, blank=True, null=True, related_name='componenti_gruppo')
	note = models.TextField( blank=True, null=True, )
	def numero_componenti(self):
		n=0
		for c in self.componenti.all():
			n+=1
		return n
	def __unicode__(self):
		return '%s' % (self.nome)

class GruppoForm(forms.ModelForm):
	#nascita = forms.DateField(label='Data di nascita', required=False, widget=widgets.AdminDateWidget)
Beispiel #43
0
        app = app_member.app
        alter_ego = app.get_alter_ego()

        if not alter_ego:
            continue 

        if (instance.tabular_type 
            and instance.tabular_type.name.lower() in app.keyword_list()
            and alter_ego.has_perm('view_resourcebase', resource)
        ):
            remove_perm('view_resourcebase', alter_ego, resource)


signals.post_delete.connect(delete_table, sender=Tabular)
signals.pre_save.connect(pre_save_document, sender=Tabular)
signals.post_save.connect(create_thumbnail, sender=Tabular)
signals.post_save.connect(insert_data, sender=Tabular)
signals.pre_save.connect(resourcebase_pre_save, sender=Tabular)
signals.post_save.connect(resourcebase_post_save, sender=Tabular)
map_changed_signal.connect(update_documents_extent)
signals.post_save.connect(share, sender=Tabular)
signals.post_delete.connect(unshare, sender=Tabular)

from eav.registry import EavConfig
class EavConfigClass(EavConfig):
    manager_attr = 'eav_objects'
    object_type = 'tabular_type'
    attribute_relation='tabular_metadata_type_attribute'

eav.register(Tabular, EavConfigClass)
Beispiel #44
0
                last_submission = self.xform.submissions.all().order_by('-confirmation_id')
                if last_submission and last_submission[0].confirmation_id:
                    last_confirmation = last_submission[0].confirmation_id

                self.confirmation_id = last_confirmation + 1
            finally:
                XFormSubmission.confirmation_lock.release()

        super(XFormSubmission, self).save(force_insert, force_update, using)

    def __unicode__(self): # pragma: no cover
        return "%s (%s) - %s" % (self.xform, self.type, self.raw)

# This sets up XForm as an EAV-able model (its attributes will in fact be
# XFormFields
register(XFormSubmission)

class XFormSubmissionValue(Value):
    """
    Stores a value for a field that was submitted.  Note that this is a rather inelegant
    representation of the data, in that nothing is typed.  This is by design.  It isn't
    the job of XForms to store your cannonical version of the data, only to allow easy
    collection and validation.
    """

    submission = models.ForeignKey(XFormSubmission, related_name='values', on_delete=models.CASCADE)

    def cleaned(self):
        return self.field.clean_submission(self.value, self.submission.type)
    
    def value_formatted(self):
Beispiel #45
0
from django.db import models
import eav


class Table_Manager(models.Model):
    schema = models.CharField(max_length=50)
    table = models.CharField(max_length=50)


class Table(models.Model):
    ...


eav.register(Table)
Beispiel #46
0
 def _model_eav_wrapper(model_class):
     if not issubclass(model_class, Model):
         raise ValueError('Wrapped class must subclass Model.')
     register(model_class, **kwargs)
     return model_class
Beispiel #47
0
                last_submission = self.xform.submissions.all().order_by('-confirmation_id')
                if last_submission and last_submission[0].confirmation_id:
                    last_confirmation = last_submission[0].confirmation_id

                self.confirmation_id = last_confirmation + 1
            finally:
                XFormSubmission.confirmation_lock.release()

        super(XFormSubmission, self).save(force_insert, force_update, using)

    def __unicode__(self): # pragma: no cover
        return "%s (%s) - %s" % (self.xform, self.type, self.raw)

# This sets up XForm as an EAV-able model (its attributes will in fact be
# XFormFields
register(XFormSubmission)

class XFormSubmissionValue(Value):
    """
    Stores a value for a field that was submitted.  Note that this is a rather inelegant
    representation of the data, in that nothing is typed.  This is by design.  It isn't
    the job of XForms to store your cannonical version of the data, only to allow easy
    collection and validation.
    """

    submission = models.ForeignKey(XFormSubmission, related_name='values')

    def cleaned(self):
        return self.field.clean_submission(self.value, self.submission.type)
    
    def value_formatted(self):
Beispiel #48
0
        """
        attrs = self.type.parts.all()
        return dict((a.slug, getattr(self.status, a.slug)) for a in attrs)
        
        
    def is_outdated(self, delta=None):
        """
            Check if the last part of the report have been made a certain time
            ago.
        """
        t = delta or self.type.delay 
        try:
            return datetime.datetime.now() > self.updated + t
        except TypeError:
            return False
    
    
    def reset_delay(self, d=None):
        """
            Change the updated datetime so the delay will be calculted from
            here. Calls save()
        """
        self.updated = d or datetime.datetime.now()
        self.save()
    
    
class ReportEavConfig(EavConfig):
    eav_attr = 'status'

eav.register(Report, ReportEavConfig)
Beispiel #49
0
 def test_double_registering_model_is_harmless(self):
     eav.register(Patient)
     eav.register(Patient)
Beispiel #50
0
        return None

    class Meta:
        ordering = ['title']
        get_latest_by = 'id'

    def __unicode__(self):

        return self.title

    @models.permalink
    def get_absolute_url(self):
        return ("package", [self.slug])


eav.register(Package)


class PackageExample(BaseModel):

    package = models.ForeignKey(Package)
    title = models.CharField(_("Title"), max_length="100")
    url = models.URLField(_("URL"))
    active = models.BooleanField(
        _("Active"),
        default=True,
        help_text="Moderators have to approve links before they are provided")

    class Meta:
        ordering = ['title']
Beispiel #51
0
    def get_absolute_url(self):
        return reverse_lazy('team:category:detail',
                            kwargs={
                                'team_slug': self.team.slug,
                                'category_slug': self.slug
                            })

    def save(self, **kwargs):
        self.slug = slugify(self.name)
        super().save(**kwargs)

    def create_fact_slug(self, fact_name):
        """
        Use the EavSlugField.create_slug_from_name to convert the name (including
        category id to make them unique) to a format which can be used as a Django field name
        """
        return eav.fields.EavSlugField.create_slug_from_name(
            "category%s_%s" % (self.pk, fact_name))

    @property
    def facts(self):
        """
        We use the term "fact" as another word for EAV attributes.
        """
        return self.eav.get_all_attributes()


# register models with eav
eav.register(Category)
Beispiel #52
0
 def setUp(self):
     eav.register(Patient)
     Attribute.objects.create(name='weight', datatype=Attribute.TYPE_FLOAT)
     Attribute.objects.create(name='color', datatype=Attribute.TYPE_TEXT)
     self.instance = Patient.objects.create(name='Jim Morrison')
     self.site = AdminSite()