Code Duplication    Length = 21-21 lines in 2 locations

flask_jsondash/charts_builder.py 2 locations

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