Code Duplication    Length = 21-21 lines in 2 locations

flask_jsondash/charts_builder.py 2 locations

@@ 340-360 (lines=21) @@
337
    # be overwritten by user, once the view has been created.
338
    data.update(**metadata(exclude=['created_by']))
339
    # Possibly override global user, if configured and valid.
340
    data.update(**check_global())
341
    # Update db
342
    if edit_raw:
343
        adapter.update(c_id, data=data, fmt_modules=False)
344
    else:
345
        adapter.update(c_id, data=data)
346
    flash('Updated view "{}"'.format(c_id))
347
    return redirect(view_url)
348
349
350
def is_global_dashboard(view):
351
    """Check if a dashboard is considered global."""
352
    return all([
353
        setting('JSONDASH_GLOBALDASH'),
354
        view.get('created_by') == setting('JSONDASH_GLOBAL_USER'),
355
    ])
356
357
358
def check_global():
359
    """Allow overriding of the user by making it global.
360
    This also checks if the setting is enabled for the app,
361
    otherwise it will not allow it.
362
    """
363
    global_enabled = setting('JSONDASH_GLOBALDASH')
@@ 317-337 (lines=21) @@
314
        return redirect(url_for('jsondash.dashboard'))
315
    viewjson = adapter.read(c_id=c_id)
316
    if not viewjson:
317
        flash('Could not find view: {}'.format(c_id), 'error')
318
        return redirect(url_for('jsondash.dashboard'))
319
    form_data = request.form
320
    view_url = url_for('jsondash.view', c_id=c_id)
321
    edit_raw = 'edit-raw' in request.form
322
    if edit_raw:
323
        try:
324
            data = json.loads(form_data.get('config'))
325
            data = adapter.reformat_data(data, c_id)
326
        except (TypeError, ValueError):
327
            flash('Invalid JSON config.', 'error')
328
            return redirect(view_url)
329
    else:
330
        data = dict(
331
            name=form_data['name'],
332
            modules=adapter._format_modules(form_data),
333
            date=dt.now(),
334
            id=c_id,
335
        )
336
    # Update metadata, but exclude some fields that should never
337
    # be overwritten by user, once the view has been created.
338
    data.update(**metadata(exclude=['created_by']))
339
    # Possibly override global user, if configured and valid.
340
    data.update(**check_global())