Code Duplication    Length = 21-21 lines in 2 locations

flask_jsondash/charts_builder.py 2 locations

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