This commit is contained in:
Martin
2016-06-30 17:31:58 +02:00
parent 032b417e1d
commit 77634ae303
15 changed files with 41 additions and 23 deletions
+1 -1
View File
@@ -1 +1 @@
from .core import *
from .core import *
+4 -2
View File
@@ -7,6 +7,7 @@ from api.validators import ValidationError
db = SQLAlchemy()
esales = Esales()
def create_app(config_name='config'):
app = Flask(__name__)
app.config.from_object(config_name)
@@ -17,7 +18,8 @@ def create_app(config_name='config'):
# register errors handlers
@app.errorhandler(404)
def on_404(error):
response = jsonify({'status': 404, 'message': 'The requested resource was not found'})
response = jsonify(
{'status': 404, 'message': 'The requested resource was not found'})
response.status_code = 404
return response
@@ -36,4 +38,4 @@ def create_app(config_name='config'):
# authentication
app.before_request(check_api_key)
return app
return app
+2 -1
View File
@@ -1,5 +1,6 @@
from esales.cluster import Cluster
class Esales(object):
def __init__(self, app=None):
@@ -9,4 +10,4 @@ class Esales(object):
self.init_app(app)
def init_app(self, app):
self.cluster.url = app.config.get('ESALES_URL')
self.cluster.url = app.config.get('ESALES_URL')
+3 -1
View File
@@ -4,13 +4,15 @@ from flask import request, current_app, Response
import unidecode
import re
def check_api_key():
api_keys = current_app.config.get("API_KEYS")
if not api_keys:
return
auth = request.authorization
if not auth or not auth.username in api_keys:
response = json.dumps({'status': 401, 'message': 'No valid API key provided'})
response = json.dumps(
{'status': 401, 'message': 'No valid API key provided'})
return Response(
response, 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'}
+1 -1
View File
@@ -16,7 +16,7 @@ class Category(db.Model):
if not row:
raise Exception(
'Could not find a path for category: {}, locale: {}'.format(self.id, locale))
path = row.path.split('/', 1)[-1] # get all text after the first /
path = row.path.split('/', 1)[-1] # get all text after the first /
path = slugify(path)
return path
+6 -2
View File
@@ -28,7 +28,8 @@ class Market(object):
@property
def price_adjustments(self):
if self._price_adjustments is None:
row = PriceAdjustments.query.filter_by(territory=self.territory).first()
row = PriceAdjustments.query.filter_by(
territory=self.territory).first()
if row:
self._price_adjustments = float(row.adjustment)
self._price_adjustments = 1
@@ -86,18 +87,21 @@ _markets = [
Market('International', 'en_EU', 'EUR', 1, None),
]
def iter_markets():
for market in _markets:
yield market
def from_locale(locale):
for market in iter_markets():
if market.locale == locale:
return market
return None
def from_territory(territory):
for market in iter_markets():
if market.territory == territory.upper():
return market
return None
return None
+1 -1
View File
@@ -8,4 +8,4 @@ class Currencies(db.Model):
__tablename__ = 'product-currencies'
iso3char = db.Column(db.String(3), primary_key=True)
exchange_rate = db.Column(db.Numeric, default=1)
exchange_rate = db.Column(db.Numeric, default=1)
+1
View File
@@ -2,6 +2,7 @@ from flask import Blueprint, jsonify
mod = Blueprint('server', __name__)
@mod.route("/", methods=["GET"])
def status():
data = {
+2 -1
View File
@@ -1,5 +1,6 @@
# coding=UTF-8
class ValidationError(Exception):
def __init__(self, message):
@@ -11,4 +12,4 @@ def validate_keys_exists(obj, *keys):
for key in keys:
if not key in obj:
raise ValidationError('No {} is specified'.format(key))
return True
return True