def __init__(self, app_title, app_banner, favicon, theme, card_extensions, services_service): """Initialization """ self.app_title = app_title self.app_banner = app_banner self.favicon = favicon self.theme = theme self.card_extensions = card_extensions self._services = services_service self.title = component.Component(self, 'tab') self.user_menu = component.Component(None) self.content = component.Component(None) self.user_manager = UserManager() self.boards_manager = self._services(BoardsManager, self.app_title, self.app_banner, self.theme, card_extensions) self.home_menu = OrderedDict() self.selected = 'board'
def go(self, comp): # Create the board board = Board(self.cols, self.rows) while not board.is_finish(): # Wait for a click in a cell (x, y) = comp.call(component.Component(board)) # Play it board.played(x + 1, y + 1) comp.call( util.Confirm('No movements left, you scored %s.' % board.score))
def render_Label_edit_color(self, h, comp, *args): """Edit the label color""" # If label changed reload columns if self._changed(): h << h.script('reload_columns()') self._changed(False) h << component.Component( overlay.Overlay(lambda r: comp.render(r, model='color'), lambda r: comp.render(r, model='edit-color-overlay'), dynamic=False, title=_('Change color'))) return h.root
def __init__(self, comp, model): """Initialization In: - ``comp`` -- the component wrapped by the popin - ``model`` -- the model of the wrapped component used to populate the popin content """ self.comp = component.Component(comp, model=comp.model) self.model = model Popin.panel_id += 1 self.id = 'panel%d' % Popin.panel_id
def create_all_cp_envs_viewer(*args, **kwargs): d_all_cp_envs = {} for env in self.env_resolver.all_envs: d_all_cp_envs[env] = component.Component( EnvViewer( appcode=lambda: self.appcode, aera=lambda: self.aera, env=env, resolvers=self, dom_storage=self, dom_father=self, )) return d_all_cp_envs
def _show_modal(self, o, model=0, title=None, on_answer=None): """Utility function that shows a component in a modal window""" def _on_answer(answer): self.modal.becomes(None) if on_answer: on_answer(answer) inner_comp = component.Component(o, model=model) modal_box = ModalBox(inner_comp, title=title, width=500, closable=False) self.modal.becomes(modal_box).on_answer(_on_answer)
def __init__(self, card, action_log, configurator, assets_manager_service): """Init method In: - ``card`` -- card component """ super(Gallery, self).__init__(card, action_log, configurator) self.assets_manager = assets_manager_service self.assets = [] self.load_assets() self.comp_id = str(random.randint(10000, 100000)) self.model = 'view' self.cropper = component.Component()
def test_rendering_security_view_board_1(self): """Test rendering security view board 1 Test rendering (Board private / user not logged) """ helpers.set_dummy_context() # to be able to create board board = helpers.create_board() board.set_visibility(board_module.BOARD_PRIVATE) helpers.set_context() with self.assertRaises(Unauthorized): component.Component(board).on_answer(lambda x: None).render( xhtml5.Renderer())
def __init__(self, configuration): self.configuration = configuration # create the singleton services for this session self.event_manager = event_management.Manager() self.flash_handler = FlashHandler() # install the singleton services in the current thread since the # portal component need them to initialize itself self._install_singleton_services() # the default content is the portal self.content = component.Component(Portal(self.configuration))
def test_rendering_security_view_board_3(self): """Test rendering security view board 3 Test rendering (Board public / user not logged) """ helpers.set_dummy_context() # for board creation board = helpers.create_board() helpers.set_context() # for realistic security check board.set_visibility(board_module.BOARD_PUBLIC) with i18n.Locale('en', 'US'): component.Component(board).on_answer(lambda x: None).render( xhtml5.Renderer())
def __init__(self, app_title, app_banner, theme, services_service): self._error_message = '' self.registration_task = services_service( RegistrationTask, app_title, app_banner, theme, moderator=self.config['moderator']) self.default_username = self.config['default_username'] self.default_password = self.config['default_password'] self.pwd_reset = services_service(PasswordResetTask, app_title, app_banner, theme) self.content = component.Component()
def __init__(self, content, model=None, title=None, css_class=None, menu_items=None): _content = content() if isinstance(content, component.Component) else content _model = model or (content.model if isinstance( content, component.Component) else None) self.content = component.Component(_content, model=_model) self.title = title self.css_class = css_class
def load_data(self): columns = [] archive = None for c in self.data.columns: col = self._services(column.Column, c.id, self, self.search_engine, data=c) if c.archive: archive = col else: columns.append(component.Component(col)) if archive is not None: self.archive_column = archive else: # Create the unique archive column last_idx = max(c.index for c in self.data.columns) col_id = self.create_column(index=last_idx + 1, title=_('Archive'), archive=True) self.archive_column = self._services(column.Column, col_id, self, self.search_engine) if self.archive and security.has_permissions('manage', self): columns.append(component.Component(self.archive_column)) self.columns = columns
def load_user_boards(self): user = security.get_user() self.my_boards = [] self.guest_boards = [] self.archived_boards = [] last_modifications = set() for board_obj in self._services(Board.get_all_boards, user, self.app_title, self.app_banner, self.theme, self.card_extensions, load_children=False): if (security.has_permissions('manage', board_obj) or security.has_permissions('edit', board_obj)): board_comp = component.Component(board_obj) if board_obj.archived: self.archived_boards.append(board_comp) else: last_activity = board_obj.get_last_activity() if last_activity is not None: last_modifications.add((last_activity, board_comp)) if security.has_permissions('manage', board_obj): self.my_boards.append(board_comp) elif security.has_permissions('edit', board_obj): self.guest_boards.append(board_comp) last_5 = sorted(last_modifications, reverse=True)[:5] self.last_modified_boards = [comp for _modified, comp in last_5] self.shared_boards = [ component.Component(board_obj) for board_obj in self._services(Board.get_shared_boards, self.app_title, self.app_banner, self.theme, self.card_extensions, load_children=False) ] public, private = Board.get_templates_for(user) self.templates = {'public': [(b.id, b.template_title) for b in public], 'private': [(b.id, b.template_title) for b in private]}
def render_fi_editor(self, h, comp, *args): async = h.AsyncRenderer() with h.div(class_='fi-editor rounded'): with h.h1(class_="tab active big"): h << h.span(h.a(_(u'Facilitator: %s') % self.user.fullname)) with h.div(class_='user-admin-item'): h << component.Component(self).render(async, model='add_entity') with h.div(class_='user-admin-item'): h << comp.render(h, model='replace_facilitator') return h.root
def render_comment_pager(self, h, comp, *args): if self.feedback_message: h << component.Component(FlashMessage(self.feedback_message.pop())) comments = self.comments() if comments: with h.ul(class_='comments-list'): print comments[0] h << comments else: with h.ul(class_='comments-list'): h << h.li(_(u'No comment')) # deal with the deletion of the last remaining comment return h.root
def load_children(self): columns = [] for c in self.data.columns: col = self._services(column.Column, c.id, self, self.card_extensions, self.action_log, data=c) if col.is_archive: self.archive_column = col columns.append(component.Component(col)) self.columns = columns
def render_article_box(self, h, comp, *args): SeeAllArticles = { ArticleType.News: _(u'See all news'), ArticleType.Ongoing: _(u'See all ongoing projects'), ArticleType.Headline: _(u'See all headlines'), } with h.div(class_='articles ' + self.type.lower()): h << h.h1(get_article_type_translation(self.type)) h << component.Component(self.pager) h << h.a(SeeAllArticles[self.type], href=self.see_all_url, class_='more-articles') return h.root
def search_ideas(self, pattern): if is_integer(pattern): idea_id = int(pattern) pager = IdeaPager( self, lambda idea_id=idea_id: get_all_published_ideas_unordered( ).filter(IdeaData.id == idea_id)) else: pager = IdeaPager( self, lambda pattern=pattern: get_searched_ideas(pattern)) pager.change_order("publication_date_desc") pager = InfinitePager(component.Component(pager, model='ideas-list')) box = IdeaPagerBox(pager, model='ideas-list') return self._show(box, selected_tab='search')
def __init__(self, id_, board, card_extensions, action_log, card_filter, search_engine_service, services_service, data=None): """Initialization In: - ``id_`` -- the id of the column """ self.db_id = id_ self._data = data self.id = 'list_' + str(self.db_id) self.board = board self._services = services_service self.action_log = action_log self.card_filter = card_filter self.search_engine = search_engine_service self.card_extensions = card_extensions self.body = component.Component(self, 'body') self.title = component.Component( title.EditableTitle(self.get_title)).on_answer(self.set_title) self.card_counter = component.Component(CardsCounter(self)) self._cards = None self.new_card = component.Component( NewCard(self))
def show_launched_ideas(self): pager = IdeaPager(self, get_all_published_ideas_unordered) menu_items = ( (_(u"Last published"), pager.last_published), (_(u"Progressing"), pager.progressing_ideas), (_(u"Most viewed"), pager.most_viewed), (_(u"Launched ideas"), pager.launched_ideas), ) pager = InfinitePager(component.Component(pager, model='ideas-list')) box = IdeaPagerBox(pager, model='list', menu_items=menu_items) box.select_item(3) return self._show(box, selected_tab='ideas', with_idea_submit=True)
def create_cp_appcomps_viewer( *args, **kwargs ): return component.Component( AppCompsViewer( appcode = lambda: self.appcode, aera = lambda: self.aera, env = lambda: self.env, resolvers = self, dom_storage = self, dom_father = self, ) )
def __init__(self, channel_id): """Initialization In: - ``channel_id`` -- identifier of the push channel to use """ self.channel_id = channel_id self.interaction = component.Component(User()) self.interaction.on_answer(self.actions) # Dispatch on the answer # Create the push channel # ``append_msg.name`` is the name of the generated javascript function comet.channels.create(channel_id, append_msg.name)
def copy(self, parent, additional_data): new_data = self.data.copy(parent.data) new_card = self._services(Card, new_data.id, parent, parent.card_extensions, parent.action_log, data=new_data) new_card.extensions = [ (name, component.Component(extension().copy(new_card, additional_data))) for name, extension in self.extensions ] return new_card
def get_users_comp(self, roles=None): # FIXME: use an appropriate method of the UserRepository query = self.get_users_query() if roles: query = query.outerjoin(UserData.roles).filter( RoleData.type.in_(roles)).distinct() query = query.offset(self.start).limit(self.batch_size + 1) return [ component.Component( UserLineEditor(q.uid, email_unique=self.email_unique, mobile_access=self.mobile_access)) for q in query ]
def resend_invitation(self, pending_member, application_url): """Resend an invitation, Resend invitation to the pending member In: - ``pending_member`` -- Send invitation to this user (PendingMember instance) """ email = pending_member.username invitation = forms.EmailInvitation(self.app_title, self.app_banner, self.theme, email, security.get_user().data, self.data, application_url) invitation.send_email(self.mail_sender) # re-calculate pending self.pending = [component.Component(BoardMember(PendingUser(token.token), self, "pending")) for token in set(self.data.pending)]
def create_cp_menu_all_envs( *args, **kwargs ): return component.Component( MenuControlEnv( env = '*', appcode = lambda: self.appcode, resolvers = self, dom_storage = self, dom_father = self, ), model = '*' )
def update_members(self): """Update members section Recalculate members + managers + pending Recreate overlays """ data = self.data #FIXME: use Membership components managers = [] simple_members = [] for manager, memberships in itertools.groupby( data.board_members, lambda item: item.manager): # we use extend because the board_members are not reordered in case of change if manager: managers.extend( [membership.user for membership in memberships]) else: simple_members.extend( [membership.user for membership in memberships]) simple_members.sort(key=lambda m: (m.fullname, m.email)) self.members = [ component.Component( BoardMember(usermanager.UserManager.get_app_user(data=member), self, 'member')) for member in simple_members ] self.managers = [ component.Component( BoardMember( usermanager.UserManager.get_app_user(data=member), self, 'manager' if len(managers) != 1 else 'last_manager')) for member in managers ] self.pending = [ component.Component( BoardMember(PendingUser(token.token), self, 'pending')) for token in data.pending ]
def __init__(self): """Each components to display is simply an attribute""" self.calc = component.Component(calculator.Calculator()) self.counter = component.Component(counter.Counter()) self.html = component.Component(html.Html()) if not has_continuation: self.tictactoe = self.wiki = self.jewels = self.gallery = None else: self.tictactoe = component.Component(tictactoe.Task()) self.wiki = component.Component(wiki9.app()) self.jewels = component.Component(Jewels(10, 10)) self.gallery = component.Component(gallery7.app())
def __init__(self, app_title, app_banner, theme, get_user, confirmation_base_url='', moderator=''): self.app_title = app_title self._get_user = get_user self.moderator = moderator self.confirmation_base_url = confirmation_base_url self.token_generator = TokenGenerator(self._get_user().username, 'email_confirmation') self.header = component.Component(Header(app_title, app_banner, theme)) self.alt_title = _('Sign up')