X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/265d73dffcdea6560f38087eac0219777084c181..f5a171520d0105e9316afdd42dfee295f09e57ed:/src/references/models.py?ds=inline diff --git a/src/references/models.py b/src/references/models.py index d4733ffcf..e8813a016 100644 --- a/src/references/models.py +++ b/src/references/models.py @@ -31,6 +31,9 @@ class Entity(models.Model): def populate_from_wikidata(self, wikidata_id): client = Client() + client.opener.addheaders = [( + 'User-Agent', 'Wolne Lektury / https://wolnelektury.pl / Python-wikidata' + )] entity = client.get(wikidata_id) self.label = entity.label.get('pl', entity.label) or '' @@ -72,6 +75,40 @@ class Entity(models.Model): self.images = json.dumps(image_data_list) + def get_images(self): + return json.loads(self.images) + + def get_pretty_coords(self): + def to_minutes(n): + coo = [] + coo.append(int(n)) + n -= coo[-1] + n *= 60 + coo.append(int(n)) + n -= coo[-1] + n *= 60 + coo.append(n) + return coo + + if not self.lat or not self.lon: + return '' + + lat, latm, lon, lonm = self.lat, 'N', self.lon, 'E' + if lat < 0: + latm = 'S' + lat = -lat + if lon < 0: + lonm = 'W' + lon = -lon + + return '%d°%d\'%d"%s %d°%d\'%d"%s' % ( + *to_minutes(lat), + latm, + *to_minutes(lon), + lonm, + ) + + class Reference(models.Model): book = models.ForeignKey('catalogue.Book', models.CASCADE)