Exemple #1
0
def json_catalog(request, domain='orunjs', packages=None):
    """
    Return the selected language catalog as a JSON object.

    Receives the same parameters as javascript_catalog(), but returns
    a response with a JSON object of the following format:

        {
            "catalog": {
                # Translations catalog
            },
            "formats": {
                # Language formats for date, time, etc.
            },
            "plural": '...'  # Expression for plural forms, or null.
        }
    """
    locale = _get_locale(request)
    packages = _parse_packages(packages)
    catalog, plural = get_javascript_catalog(locale, domain, packages)
    data = {
        'catalog': catalog,
        'formats': get_formats(),
        'plural': plural,
    }
    return jsonify(data)
Exemple #2
0
 def login(self):
     if request.method == 'POST':
         return jsonify(
             {'result': {
                 'success': True,
                 'is_authenticated': True
             }})
Exemple #3
0
 def public_query(self, id=None):
     if settings.PUBLIC_QUERY_ALLOWED:
         Query = app['ir.query']
         q = Query.objects.get(id)
         if q.public:
             return jsonify({'result': Query.read(id)})
     abort(403, 'Permission denied!')
Exemple #4
0
 def model_choices(self):
     data = request.json
     model = app[data['model']]
     model_field = data['kwargs'].get('model_field')
     if model_field:
         model_field = model._meta.fields[model_field]
         print(model_field)
     return jsonify(model.search_name(name=data.get('q'), count=data.get('count'), page=data.get('page')))
Exemple #5
0
 def logout(self):
     return jsonify({
         'result': {
             'success': True,
             'is_authenticated': False,
             'next': None
         }
     })
Exemple #6
0
 def sync(self):
     data = request.json
     objs = data['data']
     res = []
     for obj in objs:
         svc = app[obj['service']]
         values = {
             k: v
             for k, v in obj['data'].items() if not k.startswith('$')
         }
         r = svc.write(values)
         res.append({'id': r[0], '$id': obj['$id'], 'status': 'ok'})
     return jsonify({'ok': True, 'result': res})
Exemple #7
0
 def wrapped(*args, **kwargs):
     from orun.utils.json import jsonify
     data = request.json
     _id = data['id']
     kwargs['params'] = data.get('params')
     try:
         r = fn(*args, **kwargs)
         return jsonify({
             'jsonrpc': '2.0',
             'id': _id,
             'result': r
         })
     except ValidationError as e:
         return jsonify({
             'jsonrpc': '2.0',
             'id': _id,
             'error': {
                 'code': e.code,
                 'messages': e.message_dict,
             }
         })
     except RPCError as e:
         return jsonify({
             'jsonrpc': '2.0',
             'id': _id,
             'error': {
                 'code': e.code,
                 'message': str(e)
             }
         })
     except AssertionError as e:
         return jsonify({
             'jsonrpc': '2.0',
             'id': _id,
             'error': {
                 'message': str(e),
             }
         })
Exemple #8
0
 def logout(self):
     return jsonify({'result': {'success': True, 'is_authenticated': False, 'next': None}})
Exemple #9
0
 def login(self):
     if request.method == 'POST':
         return jsonify({'result': {'success': True, 'is_authenticated': True}})
Exemple #10
0
 def model_choices(self):
     data = request.json
     print(data)
     model = app[data['model']]
     return jsonify(model.search_name(name=data.get('q'), count=data.get('count'), page=data.get('page')))