def _wrapper(*args, **kwd): self = args[0] user = cherrypy.session.get('user', None) if user: utils.details_cache = {} # invalidate details cache nperms = [] if isinstance(objects_nperms, types.StringTypes): onperms = [objects_nperms] else: onperms = objects_nperms for objects_nperm in onperms: nperms.append('%s.%s' % (objects_nperm, self.classname)) if user.check_nperms(nperms, check_type): context = {'message': div()} context['message'].add( p(_("You don't have permissions for this page!"))) if fred.config.debug: context['message'].add( p('usernperm = %s,' % user.nperms, br(), 'nperms=%s,' % nperms, br(), 'nperm_type=%s' % check_type, br())) return self._render('error', context) return view_func(*args, **kwd) redir_addr = '/login/?next=%s' % get_current_url(cherrypy.request) raise cherrypy.HTTPRedirect(redir_addr)
def _wrapper(*args, **kwd): self = args[0] user = cherrypy.session.get('user', None) if user: utils.details_cache = {} # invalidate details cache nperms = [] if isinstance(objects_nperms, types.StringTypes): onperms = [objects_nperms] else: onperms = objects_nperms for objects_nperm in onperms: nperms.append('%s.%s' % (objects_nperm, self.classname)) if user.check_nperms(nperms, check_type): context = {'message': div()} context['message'].add( p(_("You don't have permissions for this page!"))) if fred.config.debug: context['message'].add( p( 'usernperm = %s,' % user.nperms, br(), 'nperms=%s,' % nperms, br(), 'nperm_type=%s' % check_type, br())) context['message'].add(p( "a tohle to je udelano nejsofistikovanejsim " "decoratorem")) return self._render('error', context) return view_func(*args, **kwd) redir_addr = '/login/?next=%s' % get_current_url(cherrypy.request) raise cherrypy.HTTPRedirect(redir_addr)
def __init__(self, context): super(FormPage, self).__init__(context) c = self.context self.main.add( h1(c['heading']) if 'heading' in c else None, p(c['before_form']) if 'before_form' in c else None, c['form'] if 'form' in c else None, p(c['after_form']) if 'after_form' in c else None)
def __init__(self, context): super(DomainBlockingResult, self).__init__(context) c = self.context self.main.add(h1(c['heading'])) if c.get('blocked_objects'): self.main.add(p(_('These domains were successfully changed:')), ul(save(self, 'blocked_object_ul'))) for blocked_object in c['blocked_objects']: if c.get('holder_changes') and c.holder_changes.get( blocked_object.id): old_holder = c.holder_changes[ blocked_object.id]['old_holder'] new_holder = c.holder_changes[ blocked_object.id]['new_holder'] holder_change_text = notag( ', holder changed ', a(attr(href=old_holder['link']), old_holder['handle']), ' -> ', a(attr(href=new_holder['link']), new_holder['handle'])) else: holder_change_text = None self.blocked_object_ul.add( li( a(attr(href=c['detail_url'] % blocked_object.id), blocked_object.handle), holder_change_text))
def add_to_bottom(self): ''' Usualy used for filterpanel and/or edit link. ''' if self.editable: self.add( p( a( attr(href=u'../edit/?id=' + unicode(self.data.get('id'))), _('Edit'))))
def _wrapper(*args, **kwd): user = cherrypy.session.get('user', None) if user: if not user.check_nperms(nperms, nperm_type): return view_func(*args, **kwd) else: context = {'main': div()} context['main'].add( p(_("You don't have permissions for this page!"))) if fred.config.debug: context['main'].add( p('nperms=%s, nperm_type=%s' % ( nperms, nperm_type))) return BaseSiteMenu(context).render() redir_addr = '/login/?next=%s' % get_current_url(cherrypy.request) raise cherrypy.HTTPRedirect(redir_addr)
def _wrapper(*args, **kwd): user = cherrypy.session.get('user', None) if user: if not user.check_nperms(nperms, nperm_type): return view_func(*args, **kwd) else: context = {'main': div()} context['main'].add( p(_("You don't have permissions for this page!"))) if fred.config.debug: context['main'].add( p('nperms=%s, nperm_type=%s' % (nperms, nperm_type))) return BaseSiteMenu(context).render() redir_addr = '/login/?next=%s' % get_current_url(cherrypy.request) raise cherrypy.HTTPRedirect(redir_addr)
def _process_form(self, context, action, cleaned_data=None, **kwd): form_class = self._get_filterform_class() # bound form with data if (kwd.get('json_data') or kwd.get('json_linear_filter')): if kwd.get('json_linear_filter'): kwd['json_data'] = simplejson.dumps( convert_linear_filter_to_form_output( simplejson.loads(kwd['json_linear_filter']))) form = UnionFilterForm(kwd, form_class=form_class) elif kwd.get('jump_prev') or kwd.get('jump_next'): form = UnionFilterForm(cleaned_data, form_class=form_class, data_cleaned=True) else: form = UnionFilterForm(form_class=form_class) context['form'] = form if form.is_bound and config.debug: context['main'].add(p(u'kwd:' + unicode(kwd))) valid = form.is_valid() if valid: in_props = [] # log request properties # Log the selected filters. # TODO(tomas): Log OR operators better... for name, value, neg in form_utils.flatten_form_data( form.cleaned_data): in_props.append(('filter_%s' % name, value, False)) in_props.append(('negation', str(neg), True)) context = self._get_list(context, form.cleaned_data, in_log_props=in_props, **kwd) if config.debug: context['main'].add(u"rows: " + str(self._get_itertable().num_rows)) if self._should_display_jump_links(form): # Key time field is active => Display prev/next links. key_time_field = form.forms[0].get_key_time_field() context['display_jump_links'] = { 'url': f_urls[self.classname], 'field_name': key_time_field.name } action = 'filter' else: if form.is_bound and config.debug: context['main'].add(u'Invalid form data, errors:' + unicode(form.errors.items())) context['headline'] = '%s filter' % self.__class__.__name__ return action
def _process_form(self, context, action, cleaned_data=None, **kwd): form_class = self._get_filterform_class() # bound form with data if (kwd.get('json_data') or kwd.get('json_linear_filter')): if kwd.get('json_linear_filter'): kwd['json_data'] = simplejson.dumps( convert_linear_filter_to_form_output( simplejson.loads(kwd['json_linear_filter']))) form = UnionFilterForm(kwd, form_class=form_class) elif kwd.get('jump_prev') or kwd.get('jump_next'): form = UnionFilterForm( cleaned_data, form_class=form_class, data_cleaned=True) # form = UnionFilterForm( # form_class=form_class) else: form = UnionFilterForm(form_class=form_class) context['form'] = form if form.is_bound and config.debug: context['main'].add(p(u'kwd:' + unicode(kwd))) valid = form.is_valid() if valid: in_props = [] # log request properties # Log the selected filters. # TODO(tomas): Log OR operators better... for name, value, neg in form_utils.flatten_form_data(form.cleaned_data): in_props.append(('filter_%s' % name, value, False)) in_props.append(('negation', str(neg), True)) context = self._get_list(context, form.cleaned_data, in_log_props=in_props, **kwd) if config.debug: context['main'].add(u"rows: " + str(self._get_itertable().num_rows)) if self._should_display_jump_links(form): # Key time field is active => Display prev/next links. key_time_field = form.forms[0].get_key_time_field() context['display_jump_links'] = { 'url': f_urls[self.classname], 'field_name': key_time_field.name} action = 'filter' else: if form.is_bound and config.debug: context['main'].add(u'Invalid form data, errors:' + unicode(form.errors.items())) context['headline'] = '%s filter' % self.__class__.__name__ return action
def check_nperm_func(nperms, nperm_type='all', raise_err=False): ''' Like check_nperm decorator, but it's normal function, used when you cannot use as decorator, for example when you need to get permission from string from other object, which is instantiated in the function. ''' user = cherrypy.session.get('user', None) if user: utils.details_cache = {} # invalidate details cache if not user.check_nperms(nperms, nperm_type): return True else: if raise_err: context = {'main': div()} context['main'].add( p(_("You don't have permissions for this page!"))) if fred.config.debug: context['main'].add( p('nperms=%s, nperm_type=%s' % (nperms, nperm_type))) raise CustomView(BaseSiteMenu(context).render()) else: return False else: redir_addr = '/login/?next=%s' % get_current_url(cherrypy.request) raise cherrypy.HTTPRedirect(redir_addr)
def __init__(self, context=None): super(DomainFilterPage, self).__init__(context) c = self.context if hasattr(self.main, 'exports'): self.main.exports.add( p( _('Export for out-of-zone notification'), a( attr(href='?txt=1&%s' % self.NOTIFICATION_EXPORT_COLUMNS_QUERY), 'TXT'), ',', a( attr(href='?csv=1&%s' % self.NOTIFICATION_EXPORT_COLUMNS_QUERY), 'CSV')))
def catch_webadmin_exceptions_decorator(view_func): ''' This decorator is applicated to all view methods of website, it catches some permission as PermissionDeniedError''' def _wrapper(*args, **kwd): self = args[0] try: return view_func(*args, **kwd) except CorbaServerDisconnectedException, e: self._remove_session_data() return self._render('disconnected') except CORBA.TRANSIENT, e: error("BACKEND IS NOT RUNNING") context = {'message': div()} if config.debug: context['message'].add(p('''Congratulations! Prave se vam ''' '''(nebo nekomu pred vami) povedlo shodit backend server, ''' '''pripiste si plusovy bod!''')) else: context['message'].add( p(_('Error: Backend server is not running!'))) context['message'].add( pre(attr(id='traceback'), traceback.format_exc())) return self._render('error', context)
def catch_webadmin_exceptions_decorator(view_func): ''' This decorator is applicated to all view methods of website, it catches some permission as PermissionDeniedError''' def _wrapper(*args, **kwd): self = args[0] try: return view_func(*args, **kwd) except CorbaServerDisconnectedException, e: self._remove_session_data() return self._render('disconnected') except CORBA.TRANSIENT, e: error("BACKEND IS NOT RUNNING") context = {'message': div()} if config.debug: context['message'].add(p('''Congratulations! Prave se vam ''' '''(nebo nekomu pred vami) povedlo shodit backend server, ''' '''pripiste si plusovy bod!''')) else: context['message'].add( p(_('Error: Backend server is not running!'))) context['message'].add( pre(attr( id='traceback'), traceback.format_exc())) return self._render('error', context)
def add_to_bottom(self): ''' Usualy used for filterpanel and/or edit link. ''' if self.editable: self.add(p(a(attr(href=u'../edit/?id=' + unicode(self.data.get('id'))), _('Edit'))))
def __init__(self, context = None): super(ErrorPage, self).__init__(context) c = self.context self.main.add(h1('Error:')) if c.has_key('message'): self.main.add(p(c.message))
def __init__(self, context = None): super(FilterPage, self).__init__(context) c = self.context lang_code = config.lang[0:2] if lang_code == 'cs': # conversion between cs and cz identifier of lagnguage lang_code = 'cz' self.head.add(script(attr(type='text/javascript'), 'scwLanguage = "%s"; //sets language of js_calendar' % lang_code, 'scwDateOutputFormat = "%s"; // set output format for js_calendar' % config.js_calendar_date_format)) if context.get('form') and (config.debug or not c.get('itertable') or c.get('show_form')): self.main.add(c.form) self.main.add(script(attr(type='text/javascript'), 'Ext.onReady(function () {addFieldsButtons()})')) else: self.main.add(a(attr(href=append_getpar_to_url(add_par_dict={'load': 1, 'show_form': 1})), _('Modify filter'))) if c.get('result'): self.main.add(p(c['result'])) if c.get('itertable'): itertable = c.itertable self.main.add(WIterTable(itertable)) self.main.add(p(_('Table_as'), a(attr(href='?txt=1'), 'TXT'), ',', a(attr(href='?csv=1'), 'CSV'))) if config.debug: self.main.add(br(), br()) header = tr(attr(cssc="header")) for htext in itertable.header: header.add(td(htext)) rows = [header] for irow in itertable: row = tr() for col in irow: if col.get('icon'): val = img(attr(src=col['icon'])) else: val = col['value'] if col.get('url'): val = a(attr(href=col['url']), val) row.add(td(attr(cssc=col.get('cssc')), val)) rows.append(row) self.main.add(table(attr(id='objectlist', media_files='/css/objectlist.css'), rows)) # Numbers of entries if itertable.num_rows_over_limit: num_rows = span(attr(cssc='warning'), itertable.num_rows) else: num_rows = itertable.num_rows pageflip = span( '%s: %s,' % (_('Number_of_pages'), itertable.last_page), '%s: ' % _('entries'), num_rows, ',', br()) # Pager if itertable.num_pages > 1: pageflip.add(div( a(attr(cssc='pager-button', href='?page=%s' % itertable.first_page), noesc('«')), a(attr(cssc='pager-button', href='?page=%s' % itertable.prev_page), noesc('‹')), form(attr(style='display: inline;', method='GET'), input(attr(type='text', size='2', name='page', value=itertable.current_page))), a(attr(cssc='pager-button', href='?page=%s' % itertable.next_page), noesc('›')), a(attr(cssc='pager-button', href='?page=%s' % itertable.last_page), noesc('»')) )) self.main.add(pageflip) if c.get("display_jump_links"): # Display the 'previous' and 'next' links (they auto-submit # the form to display results for the prev./next time interval). jump_links_info = c.get("display_jump_links") self.main.add(div(a( attr( title="Jumps to the previous time period.", href=(jump_links_info['url'] + 'filter/?jump_prev=1&field_name=%s' % jump_links_info['field_name'])), "prev"), a(attr( title="Jumps to the next time period.", href=(jump_links_info['url'] + 'filter/?jump_next=1&field_name=%s' % jump_links_info['field_name'])), "next")))
def __init__(self, context = None): super(DisconnectedPage, self).__init__(context) self.main.add(p(_('Server disconnected, please '), a(attr(href='/login/?next=%s' % get_current_url()), _('log in')), ' again.'))
def _get_list(self, context, cleaned_filters=None, in_log_props=None, **kwd): log_req = create_log_request(f_name_actionfiltername[self.__class__.__name__.lower()], properties=in_log_props) try: out_props = [] table = self._get_itertable() show_result = True try: page = int(kwd.get('page', 1)) except (ValueError, TypeError): page = 1 try: sort_col = kwd.get('sort_col') if sort_col is not None: sort_col = int(kwd.get('sort_col')) except (ValueError, TypeError): sort_col = 1 try: sort_dir = bool(int(kwd.get('sort_dir', 1))) except (ValueError, TypeError): sort_dir = True if cleaned_filters is not None: table.set_filter(cleaned_filters) if kwd.get('save_input'): # save filter props = (('name', kwd['save_input']), ('type', f_name_actionfiltername[self.__class__.__name__.lower()])) save_log_req = create_log_request('SaveFilter', properties = props) try: table.save_filter(kwd['save_input']) save_log_req.result = 'Success' finally: save_log_req.close() context['main'].add(_('Filter saved as "%s"') % kwd['save_input']) show_result = False else: # normal setting filter table.reload() if kwd.get('filter_id'): # load filter # Do not log filter load (Jara's decision - it would just clutter # the log output). table.load_filter(int(kwd.get('filter_id'))) if kwd.get('show_form') or not table.all_fields_filled(): show_result = False filter_data = table.get_filter_data() form_class = self._get_filterform_class() context['form'] = UnionFilterForm( filter_data, data_cleaned=True, form_class=form_class) else: table.reload() if kwd.get('cf'): table.clear_filter() if kwd.get('reload'): table.reload() if kwd.get('load'): # load current filter from backend cleaned_filter_data = table.get_filter_data() form_class = self._get_filterform_class() form = UnionFilterForm( cleaned_filter_data, form_class=form_class, data_cleaned=True) context['form'] = form context['show_form'] = kwd.get('show_form') if config.debug: context['main'].add( 'kwd_json_data_loaded:', cleaned_filter_data) if kwd.get('list_all'): table.clear_filter() table._table.add() table.reload() if sort_col is not None: table.set_sort(sort_col, sort_dir) log_req.result = 'Success' if show_result: out_props.append(('result_size', table.num_rows)) if table.num_rows == 0: context['result'] = _("No_entries_found") if table.num_rows == 1: rowId = table.get_row_id(0) raise (cherrypy.HTTPRedirect(f_urls[self.classname] + 'detail/?id=%s' % rowId)) if kwd.get('txt', None): cherrypy.response.headers["Content-Type"] = "text/plain" cherrypy.response.headers["Content-Disposition"] = \ "inline; filename=%s_%s.txt" % (self.classname, time.strftime('%Y-%m-%d')) return fileGenerator(table) elif kwd.get('csv', None): cherrypy.response.headers["Content-Type"] = "text/plain" cherrypy.response.headers["Content-Disposition"] = \ "attachement; filename=%s_%s.csv" % ( self.classname, time.strftime('%Y-%m-%d')) return fileGenerator(table) table.set_page(page) context['itertable'] = table except ccReg.Filters.SqlQueryTimeout, e: context['main'].add(h1(_('Timeout')), p(_('Database timeout, please try to be more specific about requested data.')))
def index(self): context = DictLookup({'main': p("hoj")}) return BaseSiteMenu(context).render()
if config.debug: context['message'].add(p('''Congratulations! Prave se vam ''' '''(nebo nekomu pred vami) povedlo shodit backend server, ''' '''pripiste si plusovy bod!''')) else: context['message'].add( p(_('Error: Backend server is not running!'))) context['message'].add( pre(attr( id='traceback'), traceback.format_exc())) return self._render('error', context) except CORBA.UNKNOWN, e: error("Exception CORBA.UNKNOWN!") context = {'message': div()} if config.debug: context['message'].add(p('''Congratulations! Prave se vam ''' '''povedlo na backend serveru vyvolat neocekavanou vyjimku, ''' '''k cemuz samozrejme nikdy nemuze dojit!''')) else: context['message'].add( p(_('Error: Unknown backend server exception!'))) context['message'].add( pre(attr( id='traceback'), traceback.format_exc())) return self._render('error', context) except ccReg.FileManager.IdNotFound, e: error("FILE NOT FOUND %s" % e) context = {'message': div()} context['message'].add(p(_('''Error: File not found!'''))) context['message'].add( pre(attr(id='traceback'), traceback.format_exc())) return self._render('error', context)
def __init__(self, context = None): super(NotFound404Page, self).__init__(context) self.main.add(h1(_('Not found (404)')), p(_('Page not found')) )
def index(self): context = DictLookup() context.main = p( "Logging has been disabled, Daphne could not connect to CORBA logd." ) return self._render('base', ctx=context)
if config.debug: context['message'].add(p('''Congratulations! Prave se vam ''' '''(nebo nekomu pred vami) povedlo shodit backend server, ''' '''pripiste si plusovy bod!''')) else: context['message'].add( p(_('Error: Backend server is not running!'))) context['message'].add( pre(attr(id='traceback'), traceback.format_exc())) return self._render('error', context) except CORBA.UNKNOWN, e: error("Exception CORBA.UNKNOWN!") context = {'message': div()} if config.debug: context['message'].add(p('''Congratulations! Prave se vam ''' '''povedlo na backend serveru vyvolat neocekavanou vyjimku, ''' '''k cemuz samozrejme nikdy nemuze dojit!''')) else: context['message'].add( p(_('Error: Unknown backend server exception!'))) context['message'].add( pre(attr(id='traceback'), traceback.format_exc())) return self._render('error', context) except ccReg.FileManager.IdNotFound, e: error("FILE NOT FOUND %s" % e) context = {'message': div()} context['message'].add(p(_('''Error: File not found!'''))) context['message'].add( pre(attr(id='traceback'), traceback.format_exc())) return self._render('error', context)
def index(self): context = DictLookup() context.main = p( "Logging has been disabled, Daphne could not connect to CORBA logd.") return self._render('base', ctx=context)
def __init__(self, context=None): super(FilterPage, self).__init__(context) c = self.context lang_code = config.lang[0:2] if lang_code == 'cs': # conversion between cs and cz identifier of lagnguage lang_code = 'cz' self.head.add( script( attr(type='text/javascript'), 'scwLanguage = "%s"; //sets language of js_calendar' % lang_code, 'scwDateOutputFormat = "%s"; // set output format for js_calendar' % config.js_calendar_date_format)) if context.get('form') and (config.debug or not c.get('itertable') or c.get('show_form')): self.main.add(c.form) self.main.add( script(attr(type='text/javascript'), 'Ext.onReady(function () {addFieldsButtons()})')) else: self.main.add( a( attr(href=append_getpar_to_url(add_par_dict={ 'load': 1, 'show_form': 1 })), _('Modify filter'))) if c.get('result'): self.main.add(p(c['result'])) if c.get('witertable'): if c.get('blocking_mode'): self.main.add( h1(attr(id='blocking_text'), _('Administrative blocking'))) self.main.add(c.witertable) if not c.get('blocking_mode'): self.main.add( p(tagid('exports'), _('Table_as'), a(attr(href='?txt=1'), 'TXT'), ',', a(attr(href='?csv=1'), 'CSV'))) if c.get("display_jump_links"): # Display the 'previous' and 'next' links (they auto-submit # the form to display results for the prev./next time interval). jump_links_info = c.get("display_jump_links") self.main.add( div( a( attr(title="Jumps to the previous time period.", href=(jump_links_info['url'] + 'filter/?jump_prev=1&field_name=%s' % jump_links_info['field_name'])), "prev"), a( attr(title="Jumps to the next time period.", href=(jump_links_info['url'] + 'filter/?jump_next=1&field_name=%s' % jump_links_info['field_name'])), "next"))) if c.get('blocking_possible') and not c.get('blocking_mode'): self.main.add( p( a(attr(href='./blocking_start/'), _('Administrative blocking'))))