Skip to content

Commit

Permalink
API-ŝlosiloj prefere ne estu en la kodo
Browse files Browse the repository at this point in the history
  • Loading branch information
interDist committed Jun 22, 2018
1 parent 4fb1516 commit 4eed701
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
25 changes: 25 additions & 0 deletions core/migrations/0005_geo_api_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-06-12 17:17
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0004_agreement_model'),
]

operations = [
migrations.AddField(
model_name='siteconfiguration',
name='opencage_api_key',
field=models.CharField(blank=True, default='a27f7e361bdfe11881a987a6e86fb5fd', max_length=32),
),
migrations.AddField(
model_name='siteconfiguration',
name='openmaptiles_api_key',
field=models.CharField(blank=True, default='iQbjILhp2gs0dgNfTlIV', max_length=32),
),
]
13 changes: 10 additions & 3 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class SiteConfiguration(SingletonModel):
_("site name"),
max_length=30, default='Pasporta Servo')

google_analytics_key = models.CharField(
max_length=13, default='UA-99737795-1', blank=True)

salt = models.CharField(
_("encryption salt"),
max_length=30, default='salo',
Expand All @@ -54,6 +51,16 @@ class SiteConfiguration(SingletonModel):
default=timedelta(weeks=42),
help_text=_("Delay (in days/hours) after which an object is no longer considered as confirmed."))

google_analytics_key = models.CharField(
max_length=13, default='UA-99737795-1', blank=True)

opencage_api_key = models.CharField(
max_length=32, default='a27f7e361bdfe11881a987a6e86fb5fd', blank=True)

# https://openmaptiles.com/hosting/
openmaptiles_api_key = models.CharField(
max_length=32, default='iQbjILhp2gs0dgNfTlIV', blank=True)

def __str__(self):
return str(_("Site Configuration"))

Expand Down
30 changes: 18 additions & 12 deletions hosting/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
import re
from uuid import uuid4
Expand All @@ -9,21 +10,26 @@
import geocoder
from pyuca import Collator

from core.models import SiteConfiguration


def geocode(query, country='', private=False, annotations=False):
key = settings.OPENCAGE_API_KEY
key = SiteConfiguration.get_solo().opencage_api_key
lang = settings.LANGUAGE_CODE
if query:
params = {'language': lang}
if not annotations:
params.update({'no_annotations': int(not annotations)})
if private:
params.update({'no_record': int(private)})
if country:
params.update({'countrycode': country})
result = geocoder.opencage(query, key=key, params=params)
result.point = Point(result.xy, srid=4326) if result.xy else None
return result
if not query:
return
params = {'language': lang}
if not annotations:
params.update({'no_annotations': int(not annotations)})
if private:
params.update({'no_record': int(private)})
if country:
params.update({'countrycode': country})
result = geocoder.opencage(query, key=key, params=params)
logging.getLogger('PasportaServo.geo').debug(
"Query: %s\n\tResult: %s\n\tConfidence: %d", query, result, result.confidence)
result.point = Point(result.xy, srid=4326) if result.xy else None
return result


def title_with_particule(value, particules=None):
Expand Down
3 changes: 2 additions & 1 deletion maps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from djgeojson.views import GeoJSONLayerView

from core.models import SiteConfiguration
from hosting.models import Place

HOURS = 3600
Expand All @@ -28,7 +29,7 @@ def get_template_names(self):

def get_context_data(self, **kwargs):
return {
'key': settings.OPENMAPTILES_API_KEY,
'key': SiteConfiguration.get_solo().openmaptiles_api_key,
'lang': settings.LANGUAGE_CODE,
}

Expand Down
7 changes: 1 addition & 6 deletions pasportaservo/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _site_admins():

# Prefix for marking values (such as email addresses) as no longer valid
# Do not change the value without a data migration!
INVALID_PREFIX = 'INVALID_'
INVALID_PREFIX = "INVALID_"


from djangocodemirror.settings import * # noqa isort:skip
Expand Down Expand Up @@ -218,11 +218,6 @@ def user_first_name(user):
POSTMAN_DISALLOW_COPIES_ON_REPLY = True
POSTMAN_NOTIFIER_APP = None

OPENCAGE_API_KEY = 'a27f7e361bdfe11881a987a6e86fb5fd'

MAPBOX_GL_BASE_STATIC = 'https://api.tiles.mapbox.com/mapbox-gl-js/v0.45.0/mapbox-gl.{ext}'
MAPBOX_GL_CSS = MAPBOX_GL_BASE_STATIC.format(ext='css')
MAPBOX_GL_JS = MAPBOX_GL_BASE_STATIC.format(ext='js')

# https://openmaptiles.com/hosting/
OPENMAPTILES_API_KEY = 'iQbjILhp2gs0dgNfTlIV'
1 change: 1 addition & 0 deletions pasportaservo/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


logging.getLogger('PasportaServo.auth').setLevel(logging.INFO)
logging.getLogger('PasportaServo.geo').setLevel(logging.DEBUG)

SASS_PROCESSOR_ROOT = path.join(BASE_DIR, 'core', 'static')

Expand Down

0 comments on commit 4eed701

Please sign in to comment.