Exemplo n.º 1
0
def edit_type():
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_ADMIN)
    if fail: return fail

    # Table
    asset_type_id = CTK.request.url.split('/')[-1]
    q = "SELECT * FROM asset_types WHERE id = '%(asset_type_id)s';" % (
        locals())

    table = PropsAutoSQL('%s/edit/apply' % LOCATION, q)
    table.AddConstant('asset_typeid', asset_type_id)
    table.Add('Tipo', CTK.TextField(), 'type', 'Nombre del tipo de activo')

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: Edicion de tipos</h1>" % (MENU_LINK))
    page += table
    return page.Render()
Exemplo n.º 2
0
def new_type():
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_ADMIN)
    if fail: return fail

    table = CTK.PropsTable()
    table.Add('Tipo', CTK.TextField({
        'name': 'type',
        'class': "required"
    }), 'Nombre del tipo de activo')

    form = CTK.Submitter("%s/new/apply" % LOCATION)
    form += table

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: A&ntilde;adir tipo</h1>" % (MENU_LINK))
    page += form
    return page.Render()
Exemplo n.º 3
0
def report_system():
    """Report info for system administration:"""

    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_ADMIN)
    if fail: return fail

    pairs = [('1h', '1 hora'), ('6h', '6 horas'), ('1d', '1 día'),
             ('1w', '1 semana')]

    tabs = CTK.Tab()
    for pair in pairs:
        mapping = {'ext': pair[0], 'desc': pair[1]}
        tabs.Add(pair[1], CTK.RawHTML(GRAPH_TEMPLATE % mapping))

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s</h1>" % (MENU_LINK))
    page += tabs
    return page.Render()
Exemplo n.º 4
0
def auth():
    g = CTK.PropsTable()
    g.Add('Usuario', CTK.TextField({
        'name': "login!name",
        'class': "required"
    }), 'Nombre de usuario')
    g.Add('Contraseña',
          CTK.TextFieldPassword({
              'name': "login!pass",
              'class': "required"
          }), 'Clave de acceso')

    box = CTK.Box({'id': 'login'}, g)
    form = CTK.Submitter("/auth/apply")
    form += box

    page = Page.Default(body_id='login_page')
    page += form
    return page.Render()
Exemplo n.º 5
0
def add_collection():
    # Authentication
    ok = Role.user_has_roles([Role.ROLE_UPLOADER, Role.ROLE_ADMIN])
    if not ok:
        return CTK.HTTP_Redir('/')

    table = CTK.PropsTable()
    table.Add('Nombre', CTK.TextField({
        'name': 'name',
        'class': "required"
    }), 'Nombre de la colección')

    form = CTK.Submitter("%s/new/apply" % LOCATION)
    form += table

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: A&ntilde;adir colección</h1>" % (MENU_LINK))
    page += form
    return page.Render()
Exemplo n.º 6
0
def edit_license():
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_ADMIN)
    if fail: return fail

    # Table
    license_id = CTK.request.url.split('/')[-1]
    q = "SELECT * FROM licenses WHERE id = '%(license_id)s';" % (locals())

    table = PropsAutoSQL('%s/edit/apply' % LOCATION, q)
    table.AddConstant('licenseid', license_id)
    table.Add('Licencia', CTK.TextField(), 'name', 'Nombre de la licencia')
    table.Add('Descripción', CTK.TextField(), 'description',
              'Breve descripción')

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: Edicion de licencia</h1>" % (MENU_LINK))
    page += table
    return page.Render()
Exemplo n.º 7
0
    def __call__(self):
        # Authentication
        fail = Auth.assert_is_role(Role.ROLE_UPLOADER)
        if fail: return fail
        operation = Limiter()
        if not operation.is_allowed():
            return page_forbidden(operation)

        self.page = Page.Default()
        self.page += CTK.RawHTML("<h1>%s: Subir ficheros</h1>" % (MENU_LINK))
        self.page += CTK.Uploader(
            {
                'handler': report_upload_new,
                'target_dir': self.target_dir
            },
            direct=False)
        self.page += CTK.RawHTML(
            LINK_HREF %
            ('%s/new' % PAGEASSET_LOCATION, 'Crear sin fichero adjunto'))
        return self.page.Render()
Exemplo n.º 8
0
def report_assets():
    """Report info for users"""

    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_CONSUMER)
    if fail: return fail

    page = Page.Default()

    if Role.user_has_role(Role.ROLE_ADMIN):
        page += CTK.RawHTML("<h1>%s</h1>" % (MENU_LINK))

    report = get_24h_task()
    if report:
        page += CTK.RawHTML('<h2>Activos de las últimas 24 horas</h2>')
        page += get_section(report)

    report = get_views_task()
    if report:
        page += CTK.RawHTML('<h2>Activos más populares</h2>')
        page += get_section(report, ('Visitas', 'views'))

    return page.Render()
Exemplo n.º 9
0
def new_license():
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_ADMIN)
    if fail: return fail

    table = CTK.PropsTable()
    table.Add('Licencia', CTK.TextField({
        'name': 'name',
        'class': "required"
    }), 'Nombre de la licencia')
    table.Add('Descripción',
              CTK.TextField({
                  'name': 'description',
                  'class': "required"
              }), 'Breve descripción')

    form = CTK.Submitter("%s/new/apply" % LOCATION)
    form += table

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: A&ntilde;adir licencia</h1>" % (MENU_LINK))
    page += form
    return page.Render()
Exemplo n.º 10
0
def publish_asset(perform=None):
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_PUBLISHER)
    if fail: return fail

    lookup = OpLookup()
    search = {'published_flag': 0, '__order__': 'type'}
    try:
        result = lookup(search)
    except:
        result = []
    acl = ACL()
    result = acl.filter_assets("ad", result)

    contents = [(Asset, x) for x in result]

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: Publicar activos</h1>" % (MENU_LINK))

    pending = CTK.Container()
    if len(contents) == 0:
        pending += CTK.RawHTML(
            "<h2>No hay activos pendientes de publicación</h2>")
    else:
        pending += Paginate(contents, PublishWidget)

    if perform or perform == []:
        page += CTK.RawHTML("<h2>Activos buscados</h2>")
        page += publish_get_custom(perform)

    tabs = CTK.Tab()
    tabs.Add('Pendientes', pending)
    tabs.Add('Búsqueda', WidgetLookup.get_fields_form(PUBLISH_LOOKUP))
    page += tabs

    return page.Render()
Exemplo n.º 11
0
def edit_format():
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_ADMIN)
    if fail: return fail

    # Table
    format_id = CTK.request.url.split('/')[-1]
    f = Format.get_format(format_id)
    lossy_dict = {'name': 'lossy_flag', 'checked': str(f['lossy_flag'])}

    table = CTK.PropsAuto('%s/edit/apply' % LOCATION)
    table.AddConstant('formatid', format_id)
    table.Add('Formato', CTK.RawHTML(f['name']), 'Nombre del formato')
    table.Add(
        'Con pérdida', CTK.Checkbox(lossy_dict),
        'La transcodificación a este formato conlleva pérdida de calidad')

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: Edicion de formato</h1>" % (MENU_LINK))
    page += table

    # New targets
    new_table = __get_new_targets_table(format_id)
    if new_table:
        page += CTK.RawHTML("<h3>Agregar objetivos de transcodificación</h3>")
        page += new_table

    # Current targets
    target_table, dialogs = __get_current_targets_table(format_id)
    if target_table:
        page += CTK.RawHTML(
            "<h3>Objetivos de transcodificación existentes</h3>")
        page += target_table
        for dialog in dialogs:
            page += dialog
    return page.Render()
Exemplo n.º 12
0
def default(message=None):
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_ADMIN)
    if fail: return fail

    # List of profiles
    q = "SELECT * FROM profiles;"
    profiles = Query(q)

    table = CTK.Table()
    title = [CTK.RawHTML(x) for x in ['Profile', 'Descripcion', 'Role']]
    table[(1, 1)] = title
    table.set_header(row=True, num=1)

    page = Page.Default()

    n = 2
    for profile in profiles:
        # Fetch data
        profile_id = profiles[profile]['id']
        profile_name = profiles[profile]['name']
        profile_desc = profiles[profile]['description']

        # Role
        q = "SELECT * FROM profiles_has_roles WHERE profiles_id='%s';" % (
            profile_id)
        roles = Query(q)
        profile_roles_str = ', '.join(
            [Role.role_to_name(roles[x]['roles_id']) for x in roles])

        # Delete profile
        dialog = CTK.Dialog({
            'title': "Eliminando profile %s?" % (profile_name),
            'autoOpen': False
        })
        dialog += CTK.RawHTML(NOTE_DELETE)
        dialog.AddButton('Cancelar', "close")
        dialog.AddButton('Borrar', "/admin/profile/del/%s" % (profile_id))

        del_img = '<img src="/CTK/images/del.png" alt="Borrar"'
        linkdel = LINK_JS_ON_CLICK % (dialog.JS_to_show(), del_img)
        linkname = LINK_HREF % ("/admin/profile/%s" % profile_id, profile_name)

        table[(n, 1)] = [
            CTK.RawHTML(linkname),
            CTK.RawHTML(profile_desc),
            CTK.RawHTML(profile_roles_str),
            CTK.RawHTML(linkdel)
        ]

        page += dialog
        n += 1

    # Render
    page += CTK.RawHTML("<h1>%s: Administraci&oacute;n de Profiles</h1>" %
                        (ADMIN_PREFIX))
    page += CTK.RawHTML(LINK_HREF %
                        ('/admin/profile/new', 'A&ntilde;adir profile'))
    page += table

    if message:
        page += Message(message)

    return page.Render()
Exemplo n.º 13
0
def edit_profile():
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_ADMIN)
    if fail: return fail

    # Table
    profile_id = CTK.request.url.split('/')[3]
    q = ("SELECT *, GROUP_CONCAT(roles_id) " +
         "  FROM profiles, profiles_has_roles " +
         "  WHERE profiles.id = %(profile_id)s AND " +
         "        profiles_has_roles.profiles_id = %(profile_id)s " +
         "  GROUP by profiles.id;") % (locals())

    p = Query(q)
    profile_roles = [int(x) for x in p['GROUP_CONCAT(roles_id)'][0].split(',')]

    table = CTK.PropsAuto('/admin/profile/apply')
    table.AddConstant('profile_id', profile_id)
    table.Add('Nombre', CTK.TextField({
        'name': "name",
        'value': p['name'][0]
    }), "Nombre del profile")
    table.Add(
        'Description',
        CTK.TextField({
            'name': "description",
            'value': p['description'][0]
        }), "Descripcion del profile")
    table.Add(
        'Role: Administrador',
        CTK.Checkbox({
            'name': "role_" + str(Role.ROLE_ADMIN),
            'checked': '01'[Role.ROLE_ADMIN in profile_roles]
        }), "Tiene permisos de administrador")
    table.Add(
        'Role: Ingestador',
        CTK.Checkbox({
            'name': "role_" + str(Role.ROLE_UPLOADER),
            'checked': '01'[Role.ROLE_UPLOADER in profile_roles]
        }), "Puede dar de alta nuevos activos en el sistema")
    table.Add(
        'Role: Editor',
        CTK.Checkbox({
            'name': "role_" + str(Role.ROLE_EDITOR),
            'checked': '01'[Role.ROLE_EDITOR in profile_roles]
        }), "Puede editar los activos que ya existen en el sistema")
    table.Add(
        'Role: Publicador',
        CTK.Checkbox({
            'name': "role_" + str(Role.ROLE_PUBLISHER),
            'checked': '01'[Role.ROLE_PUBLISHER in profile_roles]
        }), "Puede publicar activos")
    table.Add(
        'Role: Consumidor',
        CTK.Checkbox({
            'name': "role_" + str(Role.ROLE_CONSUMER),
            'checked': '01'[Role.ROLE_CONSUMER in profile_roles]
        }), "El usuario puede consumir, ver, y descargar activos")

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: Edici&oacute;n profile</h1>" %
                        (PROFILES_PREFIX))
    page += table
    return page.Render()
Exemplo n.º 14
0
def edit_asset():
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_EDITOR)
    if fail: return fail

    asset_id = CTK.request.url.split('/')[-1]
    acl = ACL()
    editable = acl.filter_assets("ed", [asset_id])

    if not int(asset_id) in editable:
        return CTK.HTTP_Error(401)

    asset = Asset(asset_id)
    q        = "SELECT * "\
               "FROM assets WHERE id = '%(asset_id)s';" %(locals())

    # Prevent simultaneous editions
    editor_id = int(Auth.get_user_id())
    try:
        strp = time.strptime(asset['date_modified'], '%Y-%m-%d %H:%M:%S')
        edit_ts = int(time.mktime(strp))
    except (ValueError, TypeError):
        edit_ts = 0
    # Edition during edition-window is only allowed to the current editor.
    if time.time() - edit_ts < EDIT_WINDOW and asset['editor_id'] != editor_id:
        page = Page.Default()
        page += CTK.RawHTML("<h1>%s: Editar activo</h1>" % (MENU_LINK))
        page += CTK.RawHTML(
            "<h2>El activo está siendo editado actualmente</h2>")
        return page.Render()

    # Mark it as 'being edited'
    asset['date_modified'] = "CURRENT_TIMESTAMP()"
    asset['editor_id'] = editor_id
    oa = OpAsset(asset)
    rc = oa.update()
    asset = Asset(asset_id)

    lang = asset['language']
    languages = CTK.Combobox(
        {
            'name': 'language',
            'selected': lang,
            'class': 'required'
        }, LANG)

    # Table
    types = ComboboxSQL(props={
        'selected': asset['asset_types_id'],
        'class': 'required'
    },
                        sql="SELECT id, type FROM asset_types;")
    licenses = ComboboxSQL(props={
        'selected': asset['licenses_id'],
        'class': 'required'
    },
                           sql="SELECT id, name FROM licenses;")

    table = PropsAutoSQL(False, q)
    table.AddConstant('asset_id', str(asset_id))
    table.Add('Tipo', types, 'asset_types_id', 'Tipo de activo')
    table.Add('Licencia', licenses, 'licenses_id', 'Licencia del activo')
    table.Add('Título',
              CTK.TextField({
                  'class': 'required',
                  'maxlength': LEN_TITL
              }), 'title', 'Titulo del activo')
    table.Add('Descripción',
              CTK.TextField({
                  'class': 'required',
                  'maxlength': LEN_DESC
              }), 'description', 'Descripcion del activo')
    table.Add('Versión', CTK.TextField({'class': 'required'}), 'version',
              'Version del activo')
    table.Add('Idioma', languages, 'language', 'Idioma del activo')
    table.Add('Tema',
              CTK.TextField({
                  'class': 'required',
                  'maxlength': LEN_SUBJ
              }), 'subject', 'El tema del contenido del recurso')

    form = CTK.Submitter('%s/edit/apply' % LOCATION)
    form += table
    form += CTK.SubmitterButton('Enviar')

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: Editar activo</h1>" % (MENU_LINK))
    page += form
    return page.Render()
Exemplo n.º 15
0
def error_page(msg=NOTE_NO_TRANSCODING):
    page = Page.Default()
    page += CTK.RawHTML('<h1>%s</h1>' % MENU_LINK)
    page += CTK.RawHTML('<h3>%s</h3>' % msg)
    return page.Render()
Exemplo n.º 16
0
def evolve_form(parent_id):
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_UPLOADER)
    if fail: return fail

    req = CTK.request.url.split('/')
    name, ref = None, None

    for r in req:
        try:
            if r.startswith('name='):
                name = r.split('name=')[1]
            elif r.startswith('ref='):
                ref = r.split('ref=')[1]
        except IndexError:
            pass

    asset = Asset(parent_id)
    lang = asset['language']
    languages = CTK.Combobox({'name': 'language', 'selected': lang}, LANG)

    # Table
    types = ComboboxSQL(props={
        'name': 'asset_types_id',
        'selected': asset['asset_types_id']
    },
                        sql="SELECT id, type FROM asset_types;")
    licenses = ComboboxSQL(props={
        'name': 'licenses_id',
        'selected': asset['licenses_id']
    },
                           sql="SELECT id, name FROM licenses;")

    table = CTK.PropsTable()

    table.Add('Tipo', types, 'Tipo de activo')
    table.Add('Licencia', licenses, 'Licencia del activo')
    table.Add(
        'Título',
        CTK.TextField({
            'value': asset['title'],
            'name': 'title',
            'class': 'required'
        }), 'Titulo del activo')
    table.Add(
        'Descripción',
        CTK.TextField({
            'value': asset['description'],
            'name': 'description',
            'class': 'required'
        }), 'Descripcion del activo')
    table.Add(
        'Versión',
        CTK.TextField({
            'value': asset['version'],
            'name': 'version',
            'class': 'required'
        }), 'Version del activo')
    table.Add(
        'Partes',
        PartChooser({
            'name': 'parts',
            'value': asset['parts'],
            'class': 'required'
        }), 'Otros activos que forman parte del actual')
    table.Add('Idioma', languages, 'Idioma del activo')
    table.Add(
        'Tema',
        CTK.TextField({
            'value': asset['subject'],
            'name': 'subject',
            'class': 'required'
        }), 'El tema del contenido del recurso')

    form = CTK.Submitter("%s/new/apply" % LOCATION)
    form += table
    form += CTK.HiddenField({'name': 'parent_id', 'value': parent_id})
    form += CTK.SubmitterButton('Crear activo')

    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: Evolucionar activo</h1>" % (MENU_LINK))
    if name and ref:
        form += CTK.HiddenField({'name': 'ref', 'value': ref})
        form += CTK.HiddenField({'name': 'name', 'value': name})
        page += CTK.RawHTML('<h3>Archivo: "%s"</h3>' % (name))

    page += form
    return page.Render()
Exemplo n.º 17
0
def add_asset(parent_id=None):
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_UPLOADER)
    if fail: return fail

    req = CTK.request.url.split('/')
    name, ref = None, None

    for r in req:
        try:
            if r.startswith('name='):
                name = r.split('name=')[1]
            elif r.startswith('ref='):
                ref = r.split('ref=')[1]
        except IndexError:
            pass

    q_types = "SELECT id, type   FROM asset_types;"
    q_licenses = "SELECT id, name   FROM licenses;"
    q_formats = "SELECT id, format FROM formats;"

    lang_options = [(x, '(%s) %s' % (x, y)) for x, y in LANG]

    table = CTK.PropsTable()
    table.Add(
        'Tipo',
        ComboboxSQL({
            'name': 'asset_types_id',
            'class': "required"
        }, q_types), 'Tipo de activo')
    table.Add(
        'Licencia',
        ComboboxSQL(
            {
                'name': 'licenses_id',
                'class': "required",
                'selected': DEFAULT_LICENSE
            }, q_licenses), 'Licencia del activo')
    table.Add(
        'Título',
        CTK.TextField({
            'name': 'title',
            'class': "required",
            'maxlength': LEN_TITL
        }), 'Titulo del activo')
    table.Add('Descripción',
              CTK.TextField({
                  'name': 'description',
                  'maxlength': LEN_DESC
              }), 'Descripcion del activo')
    table.Add('Versión', CTK.TextField({'name': 'version'}),
              'Version del activo')
    table.Add('Partes', PartChooser({'name': 'parts'}),
              'Otros activos que forman parte del actual')
    table.Add(
        'Idioma',
        CTK.Combobox({
            'name': 'language',
            'class': "required"
        }, lang_options), 'Idioma del activo')
    table.Add(
        'Tema',
        CTK.TextField({
            'name': 'subject',
            'class': "required",
            'maxlength': LEN_SUBJ
        }), 'El tema del contenido del recurso')

    form = CTK.Submitter("%s/new/apply" % LOCATION)
    form += table
    if parent_id:
        form += CTK.HiddenField({'name': 'parent_id', 'value': str(parent_id)})
    page = Page.Default()
    page += CTK.RawHTML("<h1>%s: A&ntilde;adir activo</h1>" % (MENU_LINK))

    if name and ref:
        form += CTK.HiddenField({'name': 'ref', 'value': ref})
        form += CTK.HiddenField({'name': 'name', 'value': name})
        page += CTK.RawHTML('<h3>Archivo: "%s"</h3>' % (name))

    page += form
    return page.Render()
Exemplo n.º 18
0
def transcode():
    # Authentication
    fail = Auth.assert_is_role(Role.ROLE_PUBLISHER)
    if fail: return fail

    asset_id = CTK.request.url.split('/')[-1]
    asset = Asset(asset_id)

    if not asset._file.get('filename'):
        return error_page(NOTE_NO_FILE)

    format_id = asset._file.get('formats_id')
    if not format_id:
        info = get_info(asset._file.get('filename'))
        format_id = info.get('formats_id', None)

    if not format_id:
        return error_page(NOTE_NO_FORMAT)

    sql = "SELECT * FROM transcode_targets "\
          "JOIN formats ON target_id=formats.id "\
          "WHERE source_id = %(format_id)s;" %(locals())
    q = Query(sql)

    if not len(q):
        return error_page(NOTE_NO_TRANSCODING)

    table = CTK.Table()

    header = ['Formato', 'Convertir', 'Calidad de conversión']
    table[(1, 1)] = [CTK.RawHTML(x) for x in header]
    table.set_header(row=True, num=1)
    n = 2

    for x in q:
        if q[x]['lossy_flag']: text = LOSSY
        else: text = LOSSLESS
        opts = {
            'name': 'target_id_%s' % str(q[x]['target_id']),
            'class': 'required',
            'checked': 0
        }

        fields = [
            CTK.RawHTML(q[x]['format'].upper()),
            CTK.Checkbox(opts),
            CTK.RawHTML(text)
        ]

        table[(n, 1)] = fields
        n += 1

    form = CTK.Submitter("%s/apply" % LOCATION)
    form += table
    form += CTK.HiddenField({'name': 'asset_id', 'value': str(asset_id)})
    form += CTK.SubmitterButton('Enviar')

    page = Page.Default()
    page += CTK.RawHTML('<h1>%s</h1>' % MENU_LINK)
    page += form
    return page.Render()