Beispiel #1
0
 def _get_entity_types(self):
     
     entity_types = {}
     new_entity_types = set()
     for slug, et in self._entity_types.items():
         et_category, created = EntityTypeCategory.objects.get_or_create(name=et['category'])
         try:
             entity_type = EntityType.objects.get(slug=slug)
             created = False
         except EntityType.DoesNotExist:
             entity_type = EntityType(slug=slug)
             created = True
         entity_type.category = et_category
         entity_type.slug = slug
         if created:
             entity_type.show_in_nearby_list = et['show_in_nearby_list']
             entity_type.show_in_category_list = et['show_in_category_list']
         entity_type.save()
         for lang_code, lang_name in settings.LANGUAGES:
             with override(lang_code):
                 set_name_in_language(entity_type, lang_code,
                                      verbose_name=_(et['verbose_name']),
                                      verbose_name_singular=_(et['verbose_name_singular']),
                                      verbose_name_plural=_(et['verbose_name_plural']))
         new_entity_types.add(slug)
         entity_types[slug] = entity_type
     
     for slug in new_entity_types:
         subtype_of = self._entity_types[slug]['parent-types']
         entity_types[slug].subtype_of.clear()
         for s in subtype_of:
             entity_types[slug].subtype_of.add(entity_types[s])
         entity_types[slug].save()
     
     return entity_types
Beispiel #2
0
    def _get_entity_types(self):

        entity_types = {}
        category, created = EntityTypeCategory.objects.get_or_create(name=_("Transport"))
        category.save()

        for stop_type in self.entity_type_definitions:
            et = self.entity_type_definitions[stop_type]

            try:
                entity_type = EntityType.objects.get(slug=et["slug"])
            except EntityType.DoesNotExist:
                entity_type = EntityType(slug=et["slug"])

            entity_type.category = category
            entity_type.uri = "http://mollyproject.org/schema/maps#%s" % et["uri-local"]
            if created:
                entity_type.show_in_nearby_list = et["nearby"]
                entity_type.show_in_category_list = et["category"]
            entity_type.save()
            for lang_code, lang_name in settings.LANGUAGES:
                with override(lang_code):
                    set_name_in_language(
                        entity_type,
                        lang_code,
                        verbose_name=ugettext(et["verbose-name"]),
                        verbose_name_singular=ugettext(et["verbose-name-singular"]),
                        verbose_name_plural=ugettext(et["verbose-name-plural"]),
                    )

            entity_types[stop_type] = entity_type

        for stop_type, entity_type in entity_types.items():
            if entity_type.slug == "public-transport-access-node":
                continue
            entity_type.subtype_of.add(entity_types[None])
            if (
                stop_type.startswith("MET")
                and stop_type != "MET"
                and entity_type.slug != self.RAIL_STATION_DEFINITION["slug"]
            ):
                entity_type.subtype_of.add(entity_types["MET"])

        return entity_types
Beispiel #3
0
 def _get_entity_type(self):
     try:
         entity_type = EntityType.objects.get(slug='travel-alert')
         created = False
     except EntityType.DoesNotExist:
         entity_type = EntityType(slug='travel-alert')
         created = True
     category, etc_created = EntityTypeCategory.objects.get_or_create(name=ugettext_noop('Transport'))
     if created:
         entity_type.show_in_nearby_list = False
         entity_type.show_in_category_list = False
     entity_type.category = category
     entity_type.save()
     for lang_code, lang_name in settings.LANGUAGES:
         with override(lang_code):
             set_name_in_language(entity_type, lang_code,
                                  verbose_name=_('travel alert'),
                                  verbose_name_singular=_('a travel alert'),
                                  verbose_name_plural=_('travel alerts'))
     return entity_type