def add_new(self, content, refresh): # Add new entry c_id, c_type = get_id_and_type(content) url = '%s/%s' % (URL_APPLY, c_type) roles = [ "Administrator", "Ingestador", "Editor", "Publicador", "Consumidor" ] role_options = [(None, 'Todos')] + [(Role.name_to_role(x), x) for x in roles] user_options = [(None, 'Todos')] + Auth.get_users() entries = [ CTK.RawHTML(''), CTK.Checkbox({ 'name': "ad", 'checked': False, 'class': 'required' }), CTK.Checkbox({ 'name': "ed", 'checked': False, 'class': 'required' }), CTK.Checkbox({ 'name': "rm", 'checked': False, 'class': 'required' }), CTK.Checkbox({ 'name': "co", 'checked': False, 'class': 'required' }), CTK.Combobox({ 'name': 'role', 'class': 'required' }, role_options), CTK.Combobox({ 'name': 'user_id', 'class': 'required' }, user_options) ] self.table[(self.n, 1)] = entries + [CTK.SubmitterButton('Enviar')] self.n += 1 form = CTK.Submitter(url) form += self.table form += CTK.HiddenField({'name': 'type', 'value': c_type}) form += CTK.HiddenField({'name': 'id', 'value': c_id}) form.bind('submit_success', refresh.JS_to_refresh()) self += form
def __init__(self, apps, b_next, b_cancel, b_close): CTK.Table.__init__(self, {'id': 'maintenance-removal-list'}) # Dialog button management js = "if ($('#%s input:checked').size() > 0) {" % (self.id) js += b_close.JS_to_hide() js += b_cancel.JS_to_show() js += b_next.JS_to_show() js += "} else {" js += b_close.JS_to_show() js += b_cancel.JS_to_hide() js += b_next.JS_to_hide() js += "}" # Global Selector global_selector = CTK.Checkbox({'class': 'noauto'}) global_selector.bind( 'change', """ var is_checked = this.checked; $('#%s input:checkbox').each (function() { $(this).attr('checked', is_checked); }); """ % (self.id) + js) # Add the table title title = [global_selector] title += [ CTK.RawHTML(x) for x in (_('Application'), _('Status'), _('Database'), _('Date')) ] self += title self.set_header() # Table body for app in apps: check = CTK.Checkbox({ 'name': 'remove_%s' % (app), 'class': 'noauto' }) check.bind('change', js) self += [ check, CTK.RawHTML(apps[app]['name']), CTK.RawHTML(apps[app]['type']), CTK.RawHTML(apps[app].get('db', '')), CTK.RawHTML(apps[app]['date']) ]
def Add(self, asset): assert isinstance(asset, Asset.Asset) flag = asset['published_flag'] if not flag: flag = 0 if self.sect_type != asset['Type']: self.sect_type = asset['Type'] self.n += 1 self.table[(self.n, 1)] = CTK.RawHTML("<b>%s</b>" % (self.sect_type)) linkname = LINK_HREF % ("/consume/a=%s" % (str(asset['id'])), str(asset['id'])) linktrans = LINK_HREF % ("/transcode/%s" % (str(asset['id'])), 'Transcodificar') row = [ CTK.RawHTML(''), CTK.RawHTML(linkname), CTK.RawHTML(asset['title']), CTK.RawHTML(asset['date_created']), CTK.Checkbox({ 'name': 'published_' + str(asset['id']), 'checked': '%d' % (flag) }), CTK.RawHTML(linktrans) ] self.n += 1 self.table[(self.n, 1)] = row
def _get_bookmark_link (self, asset_id): bookmark = (asset_id, Auth.get_user_id()) ref = urllib.unquote_plus(CTK.request.url) flag = Bookmark.bookmark_exists (bookmark) table = CTK.Table () table [(1,1)] = CTK.RawHTML('Favorito') table [(1,2)] = CTK.Checkbox({'name': 'bookmark', 'checked': flag}) submit = '/bookmark/%s;%s' % (asset_id, ref) form = CTK.Submitter (submit) form += table return form
def _get_action(self, asset): flag = asset['collections_id'] or 0 c_id = str(self.collection_id) a_id = str(asset['id']) table = CTK.Container() table += CTK.HiddenField({'name': 'asset_id', 'value': a_id}) table += CTK.HiddenField({'name': 'collection_id', 'value': c_id}) table += CTK.Checkbox({'name': 'assigned', 'checked': flag}) url = '%s/include' % (PageCollection.LOCATION) submit = CTK.Submitter(url) submit += table return submit
def __init__ (self): a = CTK.PropsAuto ('/apply') a.Add ('To upcase', CTK.TextField({'name': "server!uno"}), 'Converts the content of the field to upcase') a.Add ('Shows error', CTK.TextField({'name': "server!dos"}), 'It shows an error, it does not matter what you write') a.Add ('Delay 2secs', CTK.TextField({'name': "server!tri"}), 'It delays response for 2 seconds, so the submitting message is shown') a.Add ('Active', CTK.Checkbox ({'name': "server!active", 'checked':1}), 'It\'s just a plain checkbox. Nothing to see here') b = CTK.PropsAuto ('/apply') b.Add ('Elige', CTK.Combobox ({'name': "server!elec", 'selected': "two"}, OPTIONS), 'la lista') b.Add ('iPhone', CTK.iPhoneToggle({'name': "server!off"}), 'Fancy') b.Add ('Carga', CTK.Proxy("www.cherokee-project.com", '/dynamic/cherokee-list.html'), 'Lista') self.tab = CTK.Tab() self.tab.Add('Primero', a) self.tab.Add('Segundo', b)
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()
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ón profile</h1>" % (PROFILES_PREFIX)) page += table return page.Render()
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()