Code Duplication    Length = 21-21 lines in 2 locations

flask_jsondash/charts_builder.py 2 locations

@@ 340-360 (lines=21) @@
337
    return redirect(url_for('jsondash.view', id=new_id))
338
339
340
@charts.route('/charts/clone/<c_id>', methods=['POST'])
341
def clone(c_id):
342
    """Clone a json view config from the DB."""
343
    if not auth(authtype='clone'):
344
        flash('You do not have access to clone dashboards.', 'error')
345
        return redirect(url_for('jsondash.dashboard'))
346
    viewjson = adapter.read(c_id=c_id)
347
    if not viewjson:
348
        flash('Could not find view: {}'.format(id), 'error')
349
        return redirect(url_for('jsondash.dashboard'))
350
    # Update some fields.
351
    data = dict(
352
        name='Clone of {}'.format(viewjson['name']),
353
        modules=viewjson['modules'],
354
        date=dt.now(),
355
        id=str(uuid.uuid1()),
356
    )
357
    data.update(**metadata())
358
    # Add to DB
359
    adapter.create(data=data)
360
    return redirect(url_for('jsondash.view', id=data['id']))
361
@@ 317-337 (lines=21) @@
314
    return dict()
315
316
317
@charts.route('/charts/create', methods=['POST'])
318
def create():
319
    """Normalize the form POST and setup the json view config object."""
320
    if not auth(authtype='create'):
321
        flash('You do not have access to create dashboards.', 'error')
322
        return redirect(url_for('jsondash.dashboard'))
323
    data = request.form
324
    new_id = str(uuid.uuid1())
325
    d = dict(
326
        name=data['name'],
327
        modules=adapter._format_modules(data),
328
        date=dt.now(),
329
        id=new_id,
330
    )
331
    d.update(**metadata())
332
    # Possibly override global user, if configured and valid.
333
    d.update(**check_global())
334
    # Add to DB
335
    adapter.create(data=d)
336
    flash('Created new view "{}"'.format(data['name']))
337
    return redirect(url_for('jsondash.view', id=new_id))
338
339
340
@charts.route('/charts/clone/<c_id>', methods=['POST'])