Esempio n. 1
0
    def save_buildings(self, entry):
        """
        Ulozi vyparsovane obrysy budov. Ke kazde budove vypocita jeji obrys.
        """
        ct1 = CoordTransform(SpatialReference('WGS84'), SpatialReference(102065))
        ct2 = CoordTransform(SpatialReference(102065), SpatialReference('WGS84'))

        for building in self.buildings_data:
            # vytvorime polygon
            coords = [(i['lon'], i['lat']) for i in building['coordinates']]
            if coords[0] != coords[-1]:
                coords.append(coords[0])
            if not coords:
                logger.info('No coordinates information in KML data for %s record' % building['name'])
                continue

            poly = Polygon(coords, srid=4326)

            # ulozime zaznam o budove do DB
            b = Building.objects.create(
                title       = building['name'],
                description = building['description'],
                slug        = slugify(building['name'][:99]),
                entry       = entry,
                poly        = poly
            )

            # vypocteme okoli budovy
            b.calculate_zone(M100, ct1, ct2)
Esempio n. 2
0
    def refine_entry(self, entry):
        """
        Vypilovani zaznamu o obci. Nyni aktualizujeme vsechny jeji udaje do
        finalni podoby.
        """

        ei = self.ei
        old_entry = self.old_entry

        if old_entry:
            exists = True
            # novy zaznam podedi nektere vlastnosti stareho zaznamu
            slug = old_entry.slug # stejny slug
            public = old_entry.public # viditelnost

            # stary zaznam obce odstavime na vedlejsi kolej
            old_entry.slug = "%s-%i" % (old_entry.slug, old_entry.id)
            old_entry.public = False
            old_entry.save()
        else:
            # pro novy zaznam vymyslime unikatni slug
            slug, exists = get_unique_slug(ei['town'][:90]) # TODO: neopakuje se mi to? ta :90
            if exists:
                point = Point(ei['pos']['lon'], ei['pos']['lat'], srid=4326)
                if Entry.objects.filter(slug__startswith=slugify(ei['town'][:90]), dpoint__distance_lte=(point, D(km=KM20))).exists():
                    # duplicitni zaznam s jinym zdrojem dat; tohle skryjem
                    public = False
                else:
                    # jde pouze o shodu jmena obce; normalne ji zverejnime
                    # (slug sice bude mit cislo, ale jinak to stejne nejde)
                    public = True
            else:
                public = True

        # data pro aktualizovani zaznamu Entry
        data = {
            'slug':         slug,
            'population':   ei['population'] and int(ei['population']) or None,
            'area':         ei['area'] and int(ei['area']) or None,
            'wikipedia':    ei['wikipedia_url'],
            'public':       public,
            'email':        self.cleaned_data['email'],
            'description':  ''
        }
        if old_entry:
            # pokud nam v "ei" datech neco chybi, doplnime to ze stareho zaznamu
            data['population'] = data['population'] or old_entry.population
            data['area'] = data['area'] or old_entry.area
            data['wikipedia'] = data['wikipedia'] or old_entry.wikipedia
            data['description'] = data['description'] or old_entry.description

        # ulozeni objektu do DB
        for k, v in data.iteritems():
            setattr(entry, k, v)
        entry.recalculate_denormalized_values(True)
        entry.save()
        cache.clear()
        return entry, exists
Esempio n. 3
0
File: utils.py Progetto: Posp/hazard
def get_unique_slug(title):
    """
    Vrati jedinecny slug pro zaznam Entry a priznak, jestli se musela "vypocitavat"
    alternativni forma s cislem (protoze v DB uz stejny slug existuje).
    """
    from hazard.geo.models import Entry

    slug = slugify(title)
    exists = False
    if Entry.objects.filter(slug=slug).exists():
        slug = "%s-%s" % (slug, "".join(random.sample(list("abcdefghjkmopqrstuvwxyz"), 10)))
        exists = True
    return slug, exists
Esempio n. 4
0
def get_unique_slug(title):
    """
    Vrati jedinecny slug pro zaznam Entry a priznak, jestli se musela "vypocitavat"
    alternativni forma s cislem (protoze v DB uz stejny slug existuje).
    """
    from hazard.geo.models import Entry

    slug = slugify(title)
    exists = False
    if Entry.objects.filter(slug=slug).exists():
        slug = "%s-%s" % (slug, ''.join(
            random.sample(list('abcdefghjkmopqrstuvwxyz'), 10)))
        exists = True
    return slug, exists
Esempio n. 5
0
    def save_hells(self, entry):
        """
        Ulozi vyparsovane body s hernami. Pro kazdou z heren zjisti seznam zon,
        se kterymi je v konfliktu.
        """
        times = []
        buildings = list(entry.building_set.all())
        for hell in self.hells_data:
            # vytvorime bod
            coords = [(i['lon'], i['lat']) for i in hell['coordinates']]
            point = Point(hell['coordinates'][0]['lon'], hell['coordinates'][0]['lat'], srid=4326)

            # ulozime zaznam o budove do DB
            b = Hell.objects.create(
                title       = hell['name'],
                description = hell['description'],
                slug        = slugify(hell['name'][:99]),
                entry       = entry,
                point       = point
            )

            # zjistime zony se kterymi ma podnik konflikt
            b.calculate_conflicts(buildings)
            b.calculate_uzone()