Ejemplo n.º 1
0
    def send_notifications(self, hours, url):

        mail_sender = self._services['mail_sender']
        # Group users by board
        boards = {}
        for subscriber_bo in notifications.get_subscribers():
            # FIXME: don't use the data directly
            subscriber = subscriber_bo.data
            boards.setdefault(subscriber.board.id, {'board': subscriber.board,
                                                    'subscribers': []})['subscribers'].append(subscriber)

        for board in boards.itervalues():
            if not board['board'].archived:
                events = services.ActionLog.get_events_for_data(board['board'], hours)
                for subscriber in board['subscribers']:
                    data = notifications.filter_events(events, subscriber)
                    if not data:
                        continue
                    locale = UserManager.get_app_user(subscriber.user.username).get_locale()
                    self.set_locale(locale)
                    subject, content, content_html = notifications.generate_email(self.app_title, board['board'],
                                                                                  subscriber.user, hours, url, data)
                    mail_sender.send(subject, [subscriber.user.email], content, content_html)
        if self.activity_monitor:
            events = services.ActionLog.get_events_for_data(None, hours)
            new_users = UserManager.get_all_users(hours)

            if not (events or new_users):
                return
            h = xhtml5.Renderer()
            with h.html:
                h << h.h1('Boards')
                with h.ul:
                    for event in events:
                        notif = event.to_string()
                        if event.card:
                            # IDs are interpreted as anchors since HTML4. So don't use the ID of
                            # the card as a URL fragment, because the browser
                            # jumps to it.
                            ev_url = urlparse.urljoin(url, event.board.url)
                            id_ = '%s#id_card_%s' % (ev_url, event.card.id)
                            notif = h.a(notif, href=id_, style='text-decoration: none;')
                        h << h.li(u'%s : ' % (event.board.title), notif)
                h << h.h1('New users')
                with h.table(border=1):
                    with h.tr:
                        h << h.th('Login')
                        h << h.th('Fullname')
                        h << h.th('Email')
                        h << h.th('Registration date')
                    for usr in new_users:
                        with h.tr:
                            h << h.td(usr.username)
                            h << h.td(usr.fullname)
                            h << h.td(usr.email)
                            h << h.td(usr.registration_date.isoformat())

            mail_sender.send('Activity report for '+url, [self.activity_monitor], u'', h.root.write_htmlstring())
Ejemplo n.º 2
0
    def send_notifications(self, hours, url):

        mail_sender = self._services['mail_sender']
        # Group users by board
        boards = {}
        for subscriber_bo in notifications.get_subscribers():
            # FIXME: don't use the data directly
            subscriber = subscriber_bo.data
            boards.setdefault(subscriber.board.id, {'board': subscriber.board,
                                                    'subscribers': []})['subscribers'].append(subscriber)

        for board in boards.itervalues():
            if not board['board'].archived:
                events = services.ActionLog.get_events_for_data(board['board'], hours)
                for subscriber in board['subscribers']:
                    data = notifications.filter_events(events, subscriber)
                    if not data:
                        continue
                    locale = UserManager.get_app_user(subscriber.user.username).get_locale()
                    self.set_locale(locale)
                    subject, content, content_html = notifications.generate_email(self.app_title, board['board'],
                                                                                  subscriber.user, hours, url, data)
                    mail_sender.send(subject, [subscriber.user.email], content, content_html)
        if self.activity_monitor:
            events = services.ActionLog.get_events_for_data(None, hours)
            new_users = UserManager.get_all_users(hours)

            if not (events or new_users):
                return
            h = xhtml5.Renderer()
            with h.html:
                h << h.h1('Boards')
                with h.ul:
                    for event in events:
                        notif = event.to_string()
                        if event.card:
                            # IDs are interpreted as anchors since HTML4. So don't use the ID of
                            # the card as a URL fragment, because the browser
                            # jumps to it.
                            ev_url = urlparse.urljoin(url, event.board.url)
                            id_ = '%s#id_card_%s' % (ev_url, event.card.id)
                            notif = h.a(notif, href=id_, style='text-decoration: none;')
                        h << h.li(u'%s : ' % (event.board.title), notif)
                h << h.h1('New users')
                with h.table(border=1):
                    with h.tr:
                        h << h.th('Login')
                        h << h.th('Fullname')
                        h << h.th('Email')
                        h << h.th('Registration date')
                    for usr in new_users:
                        with h.tr:
                            h << h.td(usr.username)
                            h << h.td(usr.fullname)
                            h << h.td(usr.email)
                            h << h.td(usr.registration_date.isoformat())

            mail_sender.send('Activity report for '+url, [self.activity_monitor], u'', h.root.write_htmlstring())
Ejemplo n.º 3
0
def create_demo(app):
    # demo users
    user_manager = UserManager()
    assets_manager = app.assets_manager
    for i in xrange(1, 4):
        email = u'*****@*****.**' % i
        username = u'user%d' % i
        user = user_manager.create_user(username, u'password', u'user %d' % i, email)
        user.confirm_email()
        appuser = user_manager.get_app_user(username, user)
        appuser.reset_avatar(assets_manager)
        database.session.flush()
Ejemplo n.º 4
0
def init_app__new_mail(self, url, comp, http_method, request):
    username, token = (url[1], url[2])
    get_user = lambda: UserManager.get_by_username(username)
    confirmation = self._services(
        forms.EmailConfirmation,
        self.app_title,
        self.app_banner,
        self.theme,
        get_user
    )
    if confirmation.confirm_email_address(token):
        log.debug(_('Change email success for user %s') % get_user().username)
        comp.becomes(self._services(
            forms.ChangeEmailConfirmation,
            self.app_title,
            self.app_banner,
            self.theme,
            request.application_url
        ),
            model='success'
        )
        confirmation.reset_token(token)
    else:
        log.debug(_('Change email failure for user %s') % get_user().username)
        comp.becomes(
            self._services(
                forms.ChangeEmailConfirmation,
                self.app_title,
                self.app_banner,
                self.theme,
                request.application_url
            ),
            model='failure'
        )
Ejemplo n.º 5
0
def render_kansha_tab(self, h, comp, *args):
    user = security.get_user()
    if user is None:
        h << h.a(self.app_title)
    else:
        app_user = UserManager.get_app_user(user.username)
        h << h.a(component.Component(app_user, "avatar"), self.app_title)
    return h.root
Ejemplo n.º 6
0
def render_kansha_tab(self, h, comp, *args):
    user = security.get_user()
    if user is None:
        h << h.a(self.app_title)
    else:
        app_user = UserManager.get_app_user(user.username)
        h << h.a(component.Component(app_user, "avatar"), self.app_title)
    return h.root
Ejemplo n.º 7
0
def init_app__new_mail(self, url, comp, http_method, request):
    username, token = (url[1], url[2])
    get_user = lambda: UserManager.get_by_username(username)
    confirmation = self._services(forms.EmailConfirmation, self.app_title,
                                  self.app_banner, self.theme, get_user)
    if confirmation.confirm_email_address(token):
        log.debug(_('Change email success for user %s') % get_user().username)
        comp.becomes(self._services(forms.ChangeEmailConfirmation,
                                    self.app_title, self.app_banner,
                                    self.theme, request.application_url),
                     model='success')
        confirmation.reset_token(token)
    else:
        log.debug(_('Change email failure for user %s') % get_user().username)
        comp.becomes(self._services(forms.ChangeEmailConfirmation,
                                    self.app_title, self.app_banner,
                                    self.theme, request.application_url),
                     model='failure')
Ejemplo n.º 8
0
    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'