コード例 #1
0
def post_create_new_layout(request):
    """ Create a new layout and return the ID of it """
    if request.method != 'POST':
        return res.get_only_post_allowed({})

    new_layout = BluesteelLayoutController.create_new_default_layout()

    data = {}
    # data['layout'] = new_layout.as_object()
    # data['layout'] = ViewPrepareObjects.prepare_layout_for_html(data['layout'])
    data['redirect'] = ViewUrlGenerator.get_layout_edit_url(new_layout.id)

    return res.get_response(200, 'New layout created', data)
コード例 #2
0
def add_default_project(request, layout_id):
    """ Add default projet to layout """
    if request.method != 'POST':
        return res.get_only_post_allowed({})

    layout_entry = BluesteelLayoutEntry.objects.filter(id=layout_id).first()
    if layout_entry is None:
        return res.get_response(404, 'Bluesteel layout not found', {})

    BluesteelLayoutController.add_default_project_to_layout(layout_entry)
    BluesteelLayoutController.sort_layout_projects_by_order(layout_entry)

    obj = {}
    obj['redirect'] = ViewUrlGenerator.get_layout_edit_url(layout_entry.id)
    return res.get_response(200, 'Layout saved!', obj)
コード例 #3
0
def prepare_layout_for_html(layout):
    """ Adds information to layout objects for template interaction """
    layout['url'] = {}
    layout['url']['edit'] = ViewUrlGenerator.get_layout_edit_url(layout['id'])
    layout['url']['save'] = ViewUrlGenerator.get_save_layout_url(layout['id'])
    layout['url'][
        'confirm_delete'] = ViewUrlGenerator.get_confirm_delete_layout_url(
            layout['id'])
    layout['url'][
        'confirm_wipe'] = ViewUrlGenerator.get_confirm_wipe_layout_url(
            layout['id'])
    layout['url'][
        'add_project'] = ViewUrlGenerator.get_add_default_project_url(
            layout['id'])

    obj_active = {}
    obj_active['name'] = 'ACTIVE'
    obj_active['value'] = 1
    obj_active['selected'] = ''

    obj_inactive = {}
    obj_inactive['name'] = 'INACTIVE'
    obj_inactive['value'] = 0
    obj_inactive['selected'] = ''

    if layout['active'] is True:
        obj_active['selected'] = 'selected'
    else:
        obj_inactive['selected'] = 'selected'

    layout['active_selection'] = []
    layout['active_selection'].append(obj_active)
    layout['active_selection'].append(obj_inactive)

    layout['project_selection'] = []
    for index, project in enumerate(layout['projects']):
        obj = {}
        obj['name'] = project['name']
        obj['value'] = index
        obj['selected'] = ''
        if int(index) == int(layout['project_index_path']):
            obj['selected'] = 'selected'

        layout['project_selection'].append(obj)

    return layout
コード例 #4
0
def confirm_wipe(request, layout_id):
    """ Confirm layout deletion """
    if request.method != 'GET':
        return res.get_only_get_allowed({})

    layout_entry = BluesteelLayoutEntry.objects.filter(id=layout_id).first()
    if layout_entry is None:
        return res.get_response(404, 'Bluesteel layout not found', {})

    data = {}
    data['confirm'] = {}
    data['confirm']['title'] = 'Wipe layout'
    data['confirm']['text'] = 'Are you sure you want to wipe this Layout\'s data ?'
    data['confirm']['url'] = {}
    data['confirm']['url']['accept'] = ViewUrlGenerator.get_wipe_layout_url(layout_entry.id)
    data['confirm']['url']['cancel'] = ViewUrlGenerator.get_layout_edit_url(layout_entry.id)
    data['menu'] = ViewPrepareObjects.prepare_menu_for_html([])

    return res.get_template_data(request, 'presenter/confirm.html', data)
コード例 #5
0
def delete_project(request, project_id):
    """ Delete project on a layout """
    if request.method != 'POST':
        return res.get_only_post_allowed({})

    project_entry = BluesteelProjectEntry.objects.filter(id=project_id).first()
    if project_entry is None:
        return res.get_response(404, 'Bluesteel project not found', {})

    layout_id = project_entry.layout.id
    project_entry.layout.active = False
    project_entry.layout.save()

    BluesteelProjectController.delete_project(project_entry)
    BluesteelLayoutController.sort_layout_projects_by_order(project_entry.layout)

    obj = {}
    obj['redirect'] = ViewUrlGenerator.get_layout_edit_url(layout_id)
    return res.get_response(200, 'Project deleted', obj)