Exemple #1
0
class Revenue(models.NodeModel):
    _topic = u'energy'
    _parent = u'Amount'
    _description = u''
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    currency = models.StringProperty(
        null=True,
        help_text=
        u'The currency of the amount, using its 3-letter ISO-4217 code, e.g. USD, EUR, GBP etc.',
        verbose_name=u'Currency')
    year = models.DateTimeProperty(null=True,
                                   help_text=u'',
                                   verbose_name=u'Year')
    source = models.URLProperty(
        null=True,
        help_text=
        u'The URL (starting with http://) to your source. If the source is a book, enter the URL to the book at Google Books or Amazon.',
        verbose_name=u'Source')
    units = models.IntegerProperty(null=True,
                                   help_text=u'The value of the amount.',
                                   verbose_name=u'Value')

    class Meta:
        pass
Exemple #2
0
class EnergyProduct(models.NodeModel):
    _topic = u'energy'
    _description = u'An energy Product represents the concrete emanation of an energy Project. It can be a mass-produced device or a power plant.'
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    power_generation_per_unit_in_watt = models.IntegerProperty(
        null=True,
        help_text=
        u'The amount of energy, in watts, that can be generated by each unit of the product.',
        verbose_name=u'Power generation per unit (in watts)')
    households_served = models.StringProperty(
        null=True,
        help_text=
        u'The number of households that can use the product. E.g. an oven is for 1 household, a lamp is for 0.25 households, a power plant is for (power / average household consumption in the region) households. Leave blank if you\'re unsure.',
        verbose_name=u'Households served')
    source = models.URLProperty(
        null=True,
        help_text=
        u'The URL (starting with http://) to your source. If the source is a book, enter the URL to the book at Google Books or Amazon.',
        verbose_name=u'Source')
    name = models.StringProperty(null=True, help_text=u'')
    image = models.URLProperty(
        null=True,
        help_text=u'The URL (starting with http://) where the image is hosted.',
        verbose_name=u'Image URL')
    distribution = models.Relationship(
        "Distribution",
        null=True,
        rel_type='energy_product_has_distribution+',
        help_text=
        u'A Distribution represents the batch sales or gift of a product. Companies often communicate in terms of "in year X, Y units of Product Z were sold/distributed in Country A".',
        verbose_name=u'Distribution')
    operator = models.Relationship(
        "Organization",
        null=True,
        rel_type='energy_product_has_operator+',
        help_text=
        u'Products, especially large ones such as power plants, have an Operator, usually a company.',
        verbose_name=u'Operator')
    price = models.Relationship(
        "Price",
        null=True,
        rel_type='energy_product_has_price+',
        help_text=
        u'The price (use only digits, i.e. 8.99) of the Product at the date considered.',
        verbose_name=u'Price')

    class Meta:
        verbose_name = u'Energy product'
        verbose_name_plural = u'Energy products'

    def __unicode__(self):
        return self.name or u"Unkown"
Exemple #3
0
class FundraisingRound(models.NodeModel):
    _topic = u'energy'
    _parent = u'Amount'
    _description = u''
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    currency = models.StringProperty(
        null=True,
        help_text=
        u'The currency of the amount, using its 3-letter ISO-4217 code, e.g. USD, EUR, GBP etc.',
        verbose_name=u'Currency')
    raise_type = models.StringProperty(
        null=True,
        help_text=
        u'Type of the transaction, e.g. equity contribution (cash), preproject expenses, loan.',
        verbose_name=u'Type of transaction')
    year = models.DateTimeProperty(null=True,
                                   help_text=u'',
                                   verbose_name=u'Year')
    source = models.URLProperty(
        null=True,
        help_text=
        u'The URL (starting with http://) to your source. If the source is a book, enter the URL to the book at Google Books or Amazon.',
        verbose_name=u'Source')
    units = models.IntegerProperty(null=True,
                                   help_text=u'The value of the amount.',
                                   verbose_name=u'Value')
    payer = models.Relationship(
        "Organization",
        null=True,
        rel_type='fundraising_round_has_payer+',
        help_text=
        u'The Organization that actually pays the amount or contributes the asset considered.',
        verbose_name=u'Payer')
    personal_payer = models.Relationship(
        "Person",
        null=True,
        rel_type='fundraising_round_has_personal_payer+',
        help_text=
        u'The Person that contributes the amount or the asset considered.',
        verbose_name=u'Physical payer')

    class Meta:
        pass
Exemple #4
0
 class ChoiceDelete(models.NodeModel):
     poll = models.Relationship(PollDelete,
                                rel_type=neo4django.Incoming.OWNS,
                                single=True,
                                related_name='choices')
     choice = models.StringProperty()
     votes = models.IntegerProperty()
Exemple #5
0
class Commentary(models.NodeModel):
    _topic = u'energy'
    _description = u''
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    year = models.DateTimeProperty(null=True,
                                   help_text=u'',
                                   verbose_name=u'Year')
    article_url = models.URLProperty(
        null=True, help_text=u'The URL (starting with http://) of the link.')
    title = models.StringProperty(
        null=True,
        help_text=u'Title of the article or report of this commentary.',
        verbose_name=u'Title')
    author = models.Relationship(
        "Person",
        null=True,
        rel_type='commentary_has_author+',
        help_text=u'The author or authors of the document.',
        verbose_name=u'Author')

    class Meta:
        pass
Exemple #6
0
class FieldSource(models.NodeModel):
    # binding to entity
    individual = models.IntegerProperty()
    # actual source value
    reference  = models.StringProperty()
    field      = models.StringProperty()

    class Meta:
        verbose_name = u'Source'
        verbose_name_plural = u'Sources'

    def __unicode__(self):
        return self.reference or "Unkown"
Exemple #7
0
class Distribution(models.NodeModel):
    _topic = u'energy'
    _parent = u'Amount'
    _description = u''
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    sold = models.StringProperty(
        null=True,
        help_text=u'The type of distribution can be donated, sold, loaned.',
        verbose_name=u'Type of distribution')
    year = models.DateTimeProperty(null=True,
                                   help_text=u'',
                                   verbose_name=u'Year')
    source = models.URLProperty(
        null=True,
        help_text=
        u'The URL (starting with http://) to your source. If the source is a book, enter the URL to the book at Google Books or Amazon.',
        verbose_name=u'Source')
    units = models.IntegerProperty(null=True,
                                   help_text=u'The value of the amount.',
                                   verbose_name=u'Value')
    activity_in_country = models.Relationship(
        Country,
        null=True,
        rel_type='distribution_has_activity_in_country+',
        help_text=
        u'The list of countries or territories the entity is active in. ',
        verbose_name=u'Active in countries')

    class Meta:
        pass
Exemple #8
0
class Amount(models.NodeModel):
    _topic = u'energy'
    _description = u''
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    year = models.DateTimeProperty(null=True,
                                   help_text=u'',
                                   verbose_name=u'Year')
    source = models.URLProperty(
        null=True,
        help_text=
        u'The URL (starting with http://) to your source. If the source is a book, enter the URL to the book at Google Books or Amazon.',
        verbose_name=u'Source')
    units = models.IntegerProperty(null=True,
                                   help_text=u'The value of the amount.',
                                   verbose_name=u'Value')

    class Meta:
        pass
Exemple #9
0
class Country(models.NodeModel):
    _description = u''
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    name = models.StringProperty(null=True, help_text=u'')
    isoa3 = models.StringProperty(
        null=True,
        help_text=
        u'The 3-letter ISO code for the country or territory (e.g. FRA for France, DEU for Germany etc.)',
        verbose_name=u'ISO alpha-3 code')

    class Meta:
        verbose_name = u'Country'
        verbose_name_plural = u'Countries'

    def __unicode__(self):
        return self.name or u"Unkown"
Exemple #10
0
 class Knight(models.NodeModel):
     number_of_limbs = models.IntegerProperty(indexed=True)
Exemple #11
0
def parse(ontology, module='', app_label=None):
    app_label = app_label if app_label is not None else module.split(".")[-1]
    # Deduce the path to the ontology
    if type(ontology) is FieldFile:
        raw = ontology.read()
        # Open the ontology file and returns the root
        root = ET.fromstring(raw)
    else:
        tree = ET.parse(str(ontology))
        # Get the root of the xml
        root = tree.getroot()
    # Where record the new classes
    classes = dict()
    # List classes
    for clss in root.findall("owl:Class", namespaces=NAMESPACES):
        # Extract the class name
        class_name = attr(clss, "rdf:about", "").split('#')[-1]
        # Format the class name to be PEP compliant
        class_name = to_class_name(class_name)
        # Get all special attributes for this class
        class_specials = get_class_specials(clss)
        # Every class fields are recorded into an objects
        class_fields = {
            # Additional informations
            "_description":
            class_specials["help_text"],
            "_topic":
            class_specials["scope"],
            # Default fields
            "_author":
            models.IntArrayProperty(
                null=True,
                help_text=u'People that edited this entity.',
                verbose_name=u'author'),
            "_status":
            models.IntegerProperty(null=True,
                                   help_text=u'',
                                   verbose_name=u'status')
        }
        # Pick some options (Meta class)
        class_options = {}
        for f in ["verbose_name", "verbose_name_plural"]:
            if class_specials[f] is not None:
                class_options[f] = class_specials[f]
        # List all fields
        for field in clss.findall("rdfs:subClassOf//owl:Restriction",
                                  namespaces=NAMESPACES):
            # All field's options
            field_opts = dict(null=True)
            # Get the name tag
            field_name = field.find("owl:onProperty", namespaces=NAMESPACES)
            # We didn't found a name
            if field_name is None: continue
            # Get the complete field name using the rdf:resource attribute
            field_name = attr(field_name, "rdf:resource")
            # Get field's special properties
            field_opts = dict(field_opts.items() +
                              get_field_specials(root, field_name).items())
            # Convert the name to a python readable format
            field_name = to_underscores(field_name.split("#")[-1])
            if "related_name" in field_opts and field_opts[
                    "related_name"] is not None:
                # Convert related_name to the same format
                field_opts["related_name"] = to_underscores(
                    field_opts["related_name"])
            # It might be a relationship
            on_class = field.find("owl:onClass", namespaces=NAMESPACES)
            # It's a relationship!
            if on_class is not None:
                field_opts["target"] = to_class_name(
                    attr(on_class, "rdf:resource").split("#")[-1])
                # Remove "has_" from the begining of the name
                if field_name.startswith("has_"): field_name = field_name[4:]
                # Build rel_type using the name and the class name
                field_opts["rel_type"] = "%s_has_%s+" % (
                    to_underscores(class_name), field_name)
                field_type = "Relationship"
            else:
                # Get the type tag
                data_range = field.find("owl:onDataRange",
                                        namespaces=NAMESPACES)
                # It might be another tag
                values_from = field.find("owl:someValuesFrom",
                                         namespaces=NAMESPACES)
                # Picks one of the two tags type
                field_type = data_range if data_range is not None else values_from
                # It might be nothing!
                if field_type is None: continue
                # Convert the type to a python readable format
                field_type = OWLTYPES[attr(field_type,
                                           "rdf:resource").split("#")[-1]]
            # Record the field
            class_fields[field_name] = getattr(models,
                                               field_type)(**field_opts)
        # Record the class with this fields
        classes[class_name] = create_node_model(class_name,
                                                class_fields,
                                                app_label=app_label,
                                                options=class_options,
                                                module=module)

        # Prevent a bug with select_related when using neo4django and virtual models
        if not hasattr(classes[class_name]._meta, '_relationships'):
            classes[class_name]._meta._relationships = {}
    return classes
Exemple #12
0
 class TestSubclass(models.NodeModel):
     age = models.IntegerProperty()
Exemple #13
0
class Person(models.NodeModel):
    name = models.StringProperty()
    age = models.IntegerProperty()

    friends = models.Relationship('self', rel_type='friends_with')
Exemple #14
0
class Order(models.NodeModel):

    trader = models.Relationship(User, rel_type='owns', related_name='orders')
    _type = models.StringProperty(max_length=4)
    quantity = models.IntegerProperty()
    amount = FloatProperty()
Exemple #15
0
 class Person(models.NodeModel):
     name = models.StringProperty()
     age = models.IntegerProperty(indexed=True)
Exemple #16
0
class EnergyProject(models.NodeModel):
    _topic = u'energy'
    _description = u'An energy Project represents an endeavor to reach a particular aim (e.g. improve access to electricity, produce electricity in a certain way, improve energy efficiency, etc.). A project is the child of an Organization and takes its concrete form most often through Products.'
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    source = models.URLProperty(
        null=True,
        help_text=
        u'The URL (starting with http://) to your source. If the source is a book, enter the URL to the book at Google Books or Amazon.',
        verbose_name=u'Source')
    twitter_handle = models.StringProperty(
        null=True,
        help_text=u'The Twitter name of the entity (without the @)',
        verbose_name=u'Twitter handle')
    ended = models.DateTimeProperty(
        null=True,
        help_text=u'The date when the project or organization ended.',
        verbose_name=u'End date')
    started = models.DateTimeProperty(
        null=True,
        help_text=
        u'Date when the project was started. Can be anterior to the date when the parent organization was created.',
        verbose_name=u'Start date')
    comment = models.StringProperty(
        null=True,
        help_text=
        u'Enter a short comment to the entity you are reporting on (max. 500 characters).',
        verbose_name=u'Comment')
    image = models.URLProperty(
        null=True,
        help_text=u'The URL (starting with http://) where the image is hosted.',
        verbose_name=u'Image URL')
    name = models.StringProperty(null=True, help_text=u'')
    product = models.Relationship(
        "EnergyProduct",
        null=True,
        rel_type='energy_project_has_product+',
        help_text=
        u'A Product represents the concrete emanation of an energy Project. It can be a mass-produced device or a power plant.'
    )
    partner = models.Relationship(
        "Organization",
        null=True,
        related_name="partner_projects ",
        rel_type='energy_project_has_partner+',
        help_text=
        u'An entity can have Partners, i.e. Organizations that help without making a financial contribution (if financial or substancial help is involved, use Fundraising Round instead).'
    )
    commentary = models.Relationship(
        "Commentary",
        null=True,
        rel_type='energy_project_has_commentary+',
        help_text=
        u'A Commentary is an article, a blog post or a report that assesses the quality of the Project.'
    )
    activity_in_country = models.Relationship(
        Country,
        null=True,
        rel_type='energy_project_has_activity_in_country+',
        help_text=
        u'The list of countries or territories the entity is active in. ')
    owner = models.Relationship("Organization",
                                null=True,
                                rel_type='energy_project_has_owner+',
                                help_text=u'The formal Owner of the entity.')

    class Meta:
        verbose_name = u'Energy project'
        verbose_name_plural = u'Energy projects'

    def __unicode__(self):
        return self.name or u"Unkown"
Exemple #17
0
class Person(models.NodeModel):
    _topic = u'energy'
    _description = u'A Person represents a physical man or woman that is involved in an Organization, a Project or a Commentary.'
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    position = models.StringProperty(
        null=True,
        help_text=
        u'Current position within the Organization (e.g. CEO, CFO, spokesperson etc.)',
        verbose_name=u'Position')
    twitter_handle = models.StringProperty(
        null=True,
        help_text=u'The Twitter name of the entity (without the @)',
        verbose_name=u'Twitter handle')
    name = models.StringProperty(null=True, help_text=u'')
    source = models.URLProperty(
        null=True,
        help_text=
        u'The URL (starting with http://) to your source. If the source is a book, enter the URL to the book at Google Books or Amazon.',
        verbose_name=u'Source')
    website_url = models.StringProperty(null=True,
                                        help_text=u'',
                                        verbose_name=u'Website URL')
    image = models.URLProperty(
        null=True,
        help_text=u'The URL (starting with http://) where the image is hosted.',
        verbose_name=u'Image URL')
    previous_activity_in_organization = models.Relationship(
        "Organization",
        null=True,
        rel_type='person_has_previous_activity_in_organization+',
        help_text=
        u'Has the entity been active in a specific Organization previsously?',
        verbose_name=u'Previous activity in')
    educated_in = models.Relationship(Country,
                                      null=True,
                                      rel_type='person_has_educated_in+',
                                      help_text=u'',
                                      verbose_name=u'Educated in')
    based_in = models.Relationship(Country,
                                   null=True,
                                   rel_type='person_has_based_in+',
                                   help_text=u'',
                                   verbose_name=u'Based in')
    activity_in_organization = models.Relationship(
        "Organization",
        null=True,
        rel_type='person_has_activity_in_organization+',
        help_text=u'The Organization(s) this Person is active in.',
        verbose_name=u'Activity in Organizations')

    class Meta:
        verbose_name = u'Person'
        verbose_name_plural = u'Persons'

    def __unicode__(self):
        return self.name or u"Unkown"
Exemple #18
0
class IndexedMouse(models.NodeModel):
    name = models.StringProperty(indexed=True)
    age = models.IntegerProperty(indexed=True)
Exemple #19
0
class Organization(models.NodeModel):
    _topic = u'energy'
    _description = u'An Organization represents a social entity that implements, funds, takes part in or helps a Project. It can be an NGO, a university, a governement organization, a for-profit company or an international organization.'
    _status = models.IntegerProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'status')
    _author = models.IntArrayProperty(
        null=True,
        help_text=u'People that edited this entity.',
        verbose_name=u'author')
    founded = models.DateTimeProperty(
        null=True,
        help_text=u'The date when the organization was created.',
        verbose_name=u'Date founded')
    company_type = models.StringProperty(
        null=True,
        help_text=
        u'If the organization is a company, type of company (e.g. limited liability company, public corporation, unlimited company etc.)',
        verbose_name=u'Company type')
    company_register_link = models.URLProperty(
        null=True,
        help_text=
        u'The URL (starting with http://) to the official company register where the organization is registered.',
        verbose_name=u'Company register link')
    twitter_handle = models.StringProperty(
        null=True,
        help_text=u'The Twitter name of the entity (without the @)',
        verbose_name=u'Twitter handle')
    website_url = models.URLProperty(null=True,
                                     help_text=u'',
                                     verbose_name=u'Website URL')
    name = models.StringProperty(null=True, help_text=u'')
    source = models.URLProperty(
        null=True,
        help_text=
        u'The URL (starting with http://) to your source. If the source is a book, enter the URL to the book at Google Books or Amazon.',
        verbose_name=u'Source')
    address = models.StringProperty(
        null=True,
        help_text=u'The official address of the organization.',
        verbose_name=u'Address')
    organization_type = models.StringProperty(
        null=True,
        help_text=
        u'Type of organization. Can be Company, Government Organization, International Organization, University or NGO',
        verbose_name=u'Organization type')
    image = models.URLProperty(
        null=True,
        help_text=u'The URL (starting with http://) where the image is hosted.',
        verbose_name=u'Image URL')
    office_address = models.StringProperty(
        null=True,
        help_text=
        u'The address or addresses where this organization does business. Do add the country at the end of the address, e.g. Grimmstraße 10A, 10967 Berlin, Germany.',
        verbose_name=u'Office address')
    adviser = models.Relationship(
        "Person",
        null=True,
        rel_type='organization_has_adviser+',
        help_text=u'The list of persons that help the entity.',
        verbose_name=u'Adviser')
    revenue = models.Relationship(
        "Revenue",
        null=True,
        rel_type='organization_has_revenue+',
        help_text=
        u'A Revenue represents the quantity of cash that the Organization was able to gather in any given year. It doesn\'t have to be equal to the net sales but can take into account subsidies as well.',
        verbose_name=u'Revenue')
    board_member = models.Relationship(
        "Person",
        null=True,
        rel_type='organization_has_board_member+',
        help_text=u'The list of board members of the Organization, if any.',
        verbose_name=u'Board member')
    partner = models.Relationship(
        "self",
        null=True,
        rel_type='organization_has_partner+',
        help_text=
        u'An entity can have Partners, i.e. Organizations that help without making a financial contribution (if financial or substancial help is involved, use Fundraising Round instead).',
        verbose_name=u'Partner')
    key_person = models.Relationship(
        "Person",
        null=True,
        rel_type='organization_has_key_person+',
        help_text=
        u'A Key Person is an executive-level individual within an Organization, such as a CEO, CFO, spokesperson etc.',
        verbose_name=u'Key Person')
    litigation_against = models.Relationship(
        "self",
        null=True,
        rel_type='organization_has_litigation_against+',
        help_text=
        u'An entity is said to litigate against another when it is involved in a lawsuit or an out-of-court settlement with the other.',
        verbose_name=u'Litigation against')
    fundraising_round = models.Relationship(
        "FundraisingRound",
        null=True,
        rel_type='organization_has_fundraising_round+',
        help_text=
        u'A Fundraising Round represents an event when an Organization was able to raise cash or another asset.',
        verbose_name=u'Fundraising round')
    monitoring_body = models.Relationship(
        "self",
        null=True,
        rel_type='organization_has_monitoring_body+',
        help_text=
        u'The Monitoring Body is the organization that is responsible for overseeing the project. In the case of electricity projects, it is often the national electricity regulator.',
        verbose_name=u'Monitoring body')

    class Meta:
        verbose_name = u'Organization'
        verbose_name_plural = u'Organizations'

    def __unicode__(self):
        return self.name or u"Unkown"