Code Duplication    Length = 21-21 lines in 2 locations

flask_jsondash/charts_builder.py 2 locations

@@ 340-360 (lines=21) @@
337
def create():
338
    """Normalize the form POST and setup the json view config object."""
339
    if not auth(authtype='create'):
340
        flash('You do not have access to create dashboards.', 'error')
341
        return redirect(url_for('jsondash.dashboard'))
342
    data = request.form
343
    new_id = str(uuid.uuid1())
344
    d = dict(
345
        name=data['name'],
346
        modules=adapter._format_modules(data),
347
        date=dt.now(),
348
        id=new_id,
349
    )
350
    d.update(**metadata())
351
    # Possibly override global user, if configured and valid.
352
    d.update(**check_global())
353
    # Add to DB
354
    adapter.create(data=d)
355
    flash('Created new view "{}"'.format(data['name']))
356
    return redirect(url_for('jsondash.view', id=new_id))
357
358
359
@charts.route('/charts/clone/<c_id>', methods=['POST'])
360
def clone(c_id):
361
    """Clone a json view config from the DB."""
362
    if not auth(authtype='clone'):
363
        flash('You do not have access to clone dashboards.', 'error')
@@ 317-337 (lines=21) @@
314
315
def is_global_dashboard(view):
316
    """Check if a dashboard is considered global."""
317
    return all([
318
        setting('JSONDASH_GLOBALDASH'),
319
        view.get('created_by') == setting('JSONDASH_GLOBAL_USER'),
320
    ])
321
322
323
def check_global():
324
    """Allow overriding of the user by making it global.
325
    This also checks if the setting is enabled for the app,
326
    otherwise it will not allow it.
327
    """
328
    global_enabled = setting('JSONDASH_GLOBALDASH')
329
    global_flag = request.form.get('is_global', '') == 'on'
330
    can_make_global = auth(authtype='edit_global')
331
    if all([global_flag, global_enabled, can_make_global]):
332
        return dict(created_by=setting('JSONDASH_GLOBAL_USER'))
333
    return dict()
334
335
336
@charts.route('/charts/create', methods=['POST'])
337
def create():
338
    """Normalize the form POST and setup the json view config object."""
339
    if not auth(authtype='create'):
340
        flash('You do not have access to create dashboards.', 'error')