Example #1
0
 def __init__(self, view, account_management_interface,
              register_help_bookmark, verify_bookmark):
     super().__init__(view)
     self.add_child(P(view, text=_('You have successfully registered.')))
     self.add_child(
         P(view,
           text=
           _('Before we can allow you to log in, however, you need to prove to us that you are indeed the owner of %s.'
             ) % account_management_interface.email))
     p = P(view, text=_('In order to do this, an email was sent to {email} containing a secret code. '\
                        'Please check your email, retrieve the code and then enter it on {verify}.'))
     self.add_child(
         p.format(verify=A.from_bookmark(
             view,
             verify_bookmark.with_description(_('the verification page'))),
                  email=TextNode(view, account_management_interface.email)))
     self.add_child(
         P(view,
           text=
           _('Sometimes these emails arrive immediately, but they may also be delayed.'
             )))
     last_p = P(
         view,
         text=
         _('If you do not receive the email within an hour or so, please follow {trouble}.'
           ))
     self.add_child(
         last_p.format(trouble=A.from_bookmark(
             view,
             register_help_bookmark.with_description(
                 _('our troubleshooting procedure')))))
Example #2
0
    def create_items(self, menu):

        self.add_bordering_link_for(menu, '←', 'First', 1,
                                    not self.page_index.has_previous_page)
        self.add_bordering_link_for(menu, '«', 'Prev',
                                    self.page_index.previous_page.number,
                                    not self.page_index.has_previous_page)

        for page in self.page_index.pages_in_range:
            bookmark = self.paged_panel.get_bookmark(
                page_number=page.number, description=page.description)
            bookmark.query_arguments[
                'start_page_number'] = self.page_index.start_page_number
            link = A.from_bookmark(self.view, bookmark)
            item = menu.add_a(link)
            item.html_representation.add_attribute_source(
                ActiveStateAttributes(item))
            self.add_styling_to_menu_item(item)
            if self.page_index.current_page_number == page.number:
                item.set_active()

        self.add_bordering_link_for(menu, '»', 'Next',
                                    self.page_index.next_page.number,
                                    not self.page_index.has_next_page)
        self.add_bordering_link_for(menu, '→', 'Last',
                                    self.page_index.last_page.number,
                                    not self.page_index.has_next_page)
Example #3
0
    def add_dropdown(self,
                     title,
                     dropdown_menu,
                     drop_position='down',
                     query_arguments={}):
        """Adds the dropdown_menu :class:`DropdownMenu` to this Nav. It appears as the
        top-level item with text `title`.

        :keyword drop_position: Position relative to the item where the dropdown should appear ('up', 'down', 'left' or 'right').
        :keyword query_arguments: (For internal use)
        """
        if self.open_item == title:
            extra_query_arguments = {'open_item': ''}
        else:
            extra_query_arguments = {'open_item': title}
        extra_query_arguments.update(query_arguments)

        bookmark = Bookmark.for_widget(
            title, query_arguments=extra_query_arguments).on_view(self.view)
        submenu = MenuItem(self.view, A.from_bookmark(self.view, bookmark))
        self.menu_items.append(submenu)

        li = self.add_html_for_item(submenu)
        li.add_child(dropdown_menu)

        if self.open_item == title:
            li.append_class('show')
        submenu.a.append_class('dropdown-toggle')
        submenu.a.set_attribute('data-toggle', 'dropdown')
        submenu.a.set_attribute('role', 'button')
        submenu.a.set_attribute('aria-haspopup', 'true')
        # submenu.a.set_attribute('aria-expanded', 'true') #FYI no need to set this this as it is handled by bootstrap js

        li.append_class(DropdownMenuPosition(drop_position).as_html_snippet())
        return submenu
Example #4
0
    def __init__(self, view, account_management_interface):
        super().__init__(view)
        self.add_child(
            P(view,
              text=
              _('There is no record of someone trying to register the email address "%s".'
                ) % account_management_interface.email))
        self.add_child(
            P(view,
              text=
              _('Perhaps you mistyped your email address when registering? The system also removes '
                'such a registration request if you take a long time to get around to verifying it.'
                )))

        register_bookmark = self.user_interface.get_bookmark(
            relative_path='/register')
        last_p = P(
            view,
            text=_(
                'Whatever the case, please {register} to rectify the problem.')
        )
        self.add_child(
            last_p.format(register=A.from_bookmark(
                view, register_bookmark.with_description(_(
                    'register again')))))
Example #5
0
    def __init__(self, view, account_management_interface):
        super().__init__(view)
        self.add_child(
            P(view,
              text=_('You are trying to register using the email address "%s"')
              % account_management_interface.email))
        self.add_child(
            P(view,
              text=
              _('That address is already registered and active on the system.'
                'This means that you (or someone else) must have registered using that email address'
                ' previously.')))

        forgot_password_bookmark = self.user_interface.get_bookmark(
            relative_path='/resetPassword')
        last_p = P(
            view,
            text=
            _('You can gain access to this account by following our {procedure}.'
              ))
        self.add_child(
            last_p.format(procedure=A.from_bookmark(
                view,
                forgot_password_bookmark.with_description(
                    _(' password reset procedure')))))
Example #6
0
    def add_dropdown(self,
                     title,
                     dropdown_menu,
                     drop_up=False,
                     query_arguments={}):
        """Adds the dropdown_menu :class:`DropdownMenu` to this Nav. It appears as the
        top-level item with text `title`.

        :keyword drop_up: If True, the dropdown will drop upwards from its item, instead of down.
        :keyword query_arguments: (For internal use)
        """
        if self.open_item == title:
            extra_query_arguments = {'open_item': ''}
        else:
            extra_query_arguments = {'open_item': title}
        extra_query_arguments.update(query_arguments)

        bookmark = Bookmark.for_widget(
            title, query_arguments=extra_query_arguments).on_view(self.view)
        submenu = MenuItem(self.view, A.from_bookmark(self.view, bookmark))
        self.menu_items.append(submenu)

        li = self.add_html_for_item(submenu)
        li.add_child(dropdown_menu)

        if self.open_item == title:
            li.append_class('open')
        submenu.a.append_class('dropdown-toggle')
        submenu.a.set_attribute('data-toggle', 'dropdown')
        submenu.a.set_attribute('data-target', '-')
        submenu.a.add_child(Span(self.view)).append_class('caret')
        li.append_class('drop%s' % ('up' if drop_up else 'down'))
        return submenu
Example #7
0
 def __init__(self, view, account_management_interface, register_help_bookmark):
     super(CongratsWidget, self).__init__(view)
     self.add_child(P(view, text=_('You have successfully registered.')))
     self.add_child(P(view, text=_('Before we can allow you to log in, however, you need to prove to us that you are indeed the owner of %s.') % account_management_interface.email))
     self.add_child(P(view, text=_('You can do that by following instructions just emailed to that address.')))
     self.add_child(P(view, text=_('Sometimes these emails arrive immediately, but they may also be delayed.')))
     last_p = P(view, text=_('If you do not receive the email within an hour or so, please follow {trouble}.'))
     self.add_child(last_p.format(trouble=A.from_bookmark(view, register_help_bookmark.with_description(_('our troubleshooting procedure')))))
Example #8
0
    def __init__(self, view, account_management_interface):
        super(ChoosePasswordWidget, self).__init__(view)
        explanation = P(view, text=_('Do you have your secret key? You can only choose a new password if you {reset_password}.'))
        
        link_text = _('previously requested a secret key to be sent to your registered email address')
        step1_bookmark = self.user_interface.get_bookmark(relative_path='/resetPassword', description=link_text)

        self.add_child(explanation.format(reset_password=A.from_bookmark(view, step1_bookmark)))
        self.add_child(ChoosePasswordForm(view, account_management_interface))
Example #9
0
    def add_bookmark(self, bookmark, active_regex=None):
        """Adds a MenuItem for the given :class:`Bookmark` to this Menu'.

           Answers the added MenuItem.

           .. versionadded:: 3.2
        """
        return self.add_a(A.from_bookmark(self.view, bookmark),
                          active_regex=active_regex,
                          exact_match=bookmark.exact)
Example #10
0
 def __init__(self, view, account_management_interface):
     super(ResetPasswordWidget, self).__init__(view)
     explanation = P(view, text=_('To ensure you are not an impostor, resetting your password is a two step '\
                      'process: First, we send a "secret key" to your registered email address. '\
                      'Then, {choose_password}. But you need that secret key for the last step in order to prove '\
                      'that you are indeed the owner of the registered email address.'))
     link_text = _('you can choose a new password')
     step2_bookmark = self.user_interface.get_bookmark(relative_path='/choosePassword', description=link_text)
     self.add_child(explanation.format(choose_password=A.from_bookmark(view, step2_bookmark)))
     self.add_child(ResetPasswordForm(view, account_management_interface))
Example #11
0
    def __init__(self, view, address_book_ui):
        super(AddressBookList, self).__init__(view)

        current_account = LoginSession.for_current_session().account
        address_books = [book for book in AddressBook.address_books_visible_to(current_account)]
        bookmarks = [address_book_ui.get_address_book_bookmark(address_book, description=address_book.display_name)
                     for address_book in address_books]

        for bookmark in bookmarks:
            p = self.add_child(P(view))
            p.add_child(A.from_bookmark(view, bookmark))
Example #12
0
    def add_bordering_link_for(self, menu, short_description, long_description, start_page_number, disabled):
        link = A.from_bookmark(self.view, self.get_bookmark(start_page_number=start_page_number, 
                                                            disabled=disabled))

        link.add_child(Span(self.view, text=short_description)).set_attribute('aria-hidden', 'true');
        link.add_child(Span(self.view, text=long_description)).append_class('sr-only');
        link.set_attribute('aria-label', long_description);
        link.set_active(not disabled)
        item = menu.add_a(link)
        item.html_representation.add_attribute_source(AccessRightAttributes(link))
        self.add_styling_to_menu_item(item)
Example #13
0
    def __init__(self, view, account_management_interface, verify_bookmark):
        super().__init__(view)
        config = ExecutionContext.get_context().config
        self.add_child(
            P(view,
              text=_('There is a registration pending for email address "%s".')
              % account_management_interface.email))
        self.add_child(
            P(view,
              text=_(
                  'Before you can log in, you need to verify your email address using the secret key '
                  'sent to that address. It looks like you did not do that.')))
        self.add_child(
            P(view,
              text=
              _('You should receive the automated email anything between a minute to an hour after '
                'registration. Sometimes though, your email software may mistakenly identify our '
                'email as junk email. If this happens it will be hidden away in a "junk email" '
                'folder or just not shown to you.')))
        self.add_child(
            P(view,
              text=
              _('You can have the email re-sent to you by clicking on the button below.'
                )))
        self.add_child(
            P(view,
              text=
              _('Before you do that, however, please make sure that your email system will allow '
                'emails from "%s" through to you.') %
              config.accounts.admin_email))
        self.add_child(
            P(view,
              text=
              _('Sometimes these emails arrive immediately, but they may also be delayed.'
                )))
        p = P(
            view,
            text=
            _('Once you located the email, retrieve the code and then enter it on {verify}.'
              ))
        self.add_child(
            p.format(verify=A.from_bookmark(
                view,
                verify_bookmark.with_description(_('the verification page')))))

        self.add_child(RegistrationPendingForm(view))
Example #14
0
    def create_sorter_link(self, column_number, heading_widget):
        show_control = (column_number == self.page_index.sort_column_number)
        if show_control:
            sort_descending = 'off' if self.page_index.sort_descending else 'on'
            link_class = 'sorted-descending' if sort_descending=='off' else 'sorted-ascending'
        else:
            sort_descending = 'off'
            link_class = None

        bookmark = Bookmark.for_widget(None,
                                       query_arguments={'sort_column_number': column_number,
                                                        'sort_descending': sort_descending})
        link = A.from_bookmark(self.view, bookmark.on_view(self.view))
        link.add_child(heading_widget)
        if link_class:
            link.append_class(link_class)
        return link
Example #15
0
    def __init__(self, view, event_channel_name, account_management_interface):
        super().__init__(view, event_channel_name)
        self.account_management_interface = account_management_interface

        if self.exception:
            self.add_child(
                Alert(view, self.exception.as_user_message(), 'warning'))

        login_inputs = self.add_child(
            FieldSet(view,
                     legend_text=_('Please specify'))).use_layout(FormLayout())
        email_cue = P(view, _('The email address you used to register here.'))
        login_inputs.layout.add_input(
            CueInput(
                TextInput(self,
                          self.account_management_interface.fields.email),
                email_cue))

        password_cue = P(
            view, _('The secret password you supplied upon registration.'))
        password_cue_input = CueInput(
            PasswordInput(self,
                          self.account_management_interface.fields.password),
            password_cue)
        forgot_password_bookmark = self.user_interface.get_bookmark(
            relative_path='/resetPassword',
            description=_('Forgot your password?'))

        password_cue_input.add_child(
            A.from_bookmark(view, forgot_password_bookmark))
        login_inputs.layout.add_input(password_cue_input)
        stay_cue = P(view,
                     _('If selected, you will stay logged in for longer.'))
        login_inputs.layout.add_input(
            CueInput(
                CheckboxInput(
                    self,
                    self.account_management_interface.fields.stay_logged_in),
                stay_cue))

        login_buttons = self.add_child(ActionButtonGroup(view))
        btn = login_buttons.add_child(
            Button(self,
                   account_management_interface.events.login_event,
                   style='primary'))
Example #16
0
def test_populating(web_fixture):
    """Navs can be populated with a list of A's or Bookmarks."""

    # Case: a normal menu from bookmarks
    item_specs = [Bookmark('/', '/href1', 'description1'),
                  Bookmark('/', '/go_to_href', 'description2')]
    menu = Nav(web_fixture.view).with_bookmarks(item_specs)
    tester = WidgetTester(menu)

    [item1, item2] = menu.menu_items
    assert item1.a.href.path == '/href1'
    assert item1.a.children[0].value == 'description1'

    assert item2.a.href.path == '/go_to_href'
    assert item2.a.children[0].value == 'description2'

    #case: using A's
    a_list = [A.from_bookmark(web_fixture.view, i) for i in item_specs]
    menu = Nav(web_fixture.view).with_a_list(a_list)
    [item1, item2] = menu.menu_items
    assert item1.a is a_list[0]
    assert item2.a is a_list[1]
Example #17
0
 def make_link_widget(view, row):
     return A.from_bookmark(view, address_book_ui.get_edit_bookmark(row.address, description='Edit'))
Example #18
0
 def __init__(self, view, address, address_book_ui):
     super().__init__(view)
     bookmark = address_book_ui.get_edit_bookmark(address=address, description='edit')
     paragraph = self.add_child(P(view, text='%s: %s ' % (address.name, address.email_address)))
     paragraph.add_child(A.from_bookmark(view, bookmark))