示例#1
0
    def post_process_request(self, req, template, data, content_type):
        """Executed after EVERY request is processed.
           Used to add navigation bars, display messages
           and to note visits to watched resources."""
        user = to_unicode( req.authname )
        if not user or user == "anonymous":
            return (template, data, content_type)

        # Extract realm and resid from path:
        parts = req.path_info[1:].split('/',1)

        try:
            realm, resid = parts[:2]
        except:
            # Handle special case for '/' and '/wiki'
            if parts[0] == 'wiki' or (parts[0] == '' and
               'WikiModule' == self.env.config.get('trac','default_handler') ):
                realm, resid = 'wiki', 'WikiStart'
            else:
                realm, resid = parts[0], ''

        if realm not in self.realms or not \
                self.realm_handler[realm].has_perm(realm, req.perm):
            return (template, data, content_type)

        notify = 'False'
        # The notification setting is stored in the session to avoid rereading
        # the whole user settings for every page displayed
        try:
            notify = req.session['watchlist_display_notify_navitems']
        except KeyError:
            settings = self.get_settings(user)
            options = settings['booloptions']
            notify = (self.wsub and options['notifications']
                  and options['display_notify_navitems']) and 'True' or 'False'
            req.session['watchlist_display_notify_navitems'] = notify

        try:
            add_notice(req, req.session['watchlist_message'])
            del req.session['watchlist_message']
        except KeyError:
            pass
        try:
            add_notice(req, req.session['watchlist_notify_message'])
            del req.session['watchlist_notify_message']
        except KeyError:
            pass

        if self.is_watching(realm, resid, user):
            add_ctxtnav(req, _("Unwatch"),
                href=req.href('watchlist', action='unwatch',
                    resid=resid, realm=realm),
                title=_("Remove %(document)s from watchlist",
                    document=realm))
            self.visiting(realm, resid, user)
        else:
            add_ctxtnav(req, _("Watch"),
                href=req.href('watchlist', action='watch',
                resid=resid, realm=realm),
                title=_("Add %(document)s to watchlist", document=realm))
        if notify == 'True':
            if self.is_notify(req, realm, resid):
                add_ctxtnav(req, _("Do not Notify me"),
                    href=req.href('watchlist', action='notifyoff',
                        resid=resid, realm=realm),
                    title=_("Do not notify me if %(document)s changes",
                        document=realm))
            else:
                add_ctxtnav(req, _("Notify me"),
                    href=req.href('watchlist', action='notifyon',
                        resid=resid, realm=realm),
                    title=_("Notify me if %(document)s changes",
                        document=realm))

        return (template, data, content_type)
示例#2
0
                self._delete_user_settings(req.authname)
            req.redirect(req.href('watchlist'))

        redirectback_notify = options['stay_at_resource_notify'] and not \
                              onwatchlistpage and not async
        if action == "notifyon":
            if not self.res_exists(realm, resid):
                raise HTTPNotFound(t_("Page %(name)s not found", name=resid))
            elif self.wsub and options['notifications']:
                self.set_notify(req, realm, resid)
                db.commit()
            if redirectback_notify:
                if options['show_messages_on_resource_page']:
                    req.session['watchlist_notify_message'] = _(
                      """
                      You are now receiving change notifications
                      about this resource.
                      """
                    )
                req.redirect(req.href(realm,resid))
            if async:
                req.send("",'text/plain', 200)
            else:
                req.redirect(req.href('watchlist'))
        elif action == "notifyoff":
            if self.wsub and options['notifications']:
                self.unset_notify(req, realm, resid)
                db.commit()
            if redirectback_notify:
                if options['show_messages_on_resource_page']:
                    req.session['watchlist_notify_message'] = _(
                      """
示例#3
0
    def process_request(self, req):
        """Processes requests to the '/watchlist' path."""
        user  = to_unicode( req.authname )

        # Reject anonymous users
        if not user or user == 'anonymous':
            # TRANSLATOR: Link part of
            # "Please %(log_in)s to view or change your watchlist"
            log_in=tag.a(_("log in"), href=req.href('login'))
            if tag_ == None:
                # For Trac 0.11
                raise HTTPNotFound(
                        tag("Please ", log_in, " to view or change your watchlist"))
            else:
                # For Trac 0.12
                raise HTTPNotFound(
                        tag_("Please %(log_in)s to view or change your watchlist",
                            log_in=log_in))

        # Get and format request arguments
        realm = to_unicode( req.args.get('realm', u'') )
        resid = ensure_string( req.args.get('resid', u'') ).strip()
        action = req.args.get('action','view')
        async = req.args.get('async', 'false') == 'true'

        # Handle AJAX search early to speed up things
        if action == "search":
            """AJAX search request. At the moment only used to get list
               of all not watched resources."""
            handler = self.realm_handler[realm]
            query = to_unicode( req.args.get('q', u'') ).strip()
            group = to_unicode( req.args.get('group', u'notwatched') )
            if not query:
                req.send('', 'text/plain', 200 )
            if group == 'notwatched':
                result = list(handler.unwatched_resources(realm, query, user, self, fuzzy=1))
            else:
                result = list(handler.watched_resources(realm, query, user, self, fuzzy=1))
            result.sort(cmp=handler.get_sort_cmp(realm),
                        key=handler.get_sort_key(realm))
            req.send( unicode(u'\n'.join(result) + u'\n').encode("utf-8"),
                'text/plain', 200 )

        # DB cursor
        db = self.env.get_db_cnx()
        cursor = db.cursor()

        wldict = dict()
        for k,v in req.args.iteritems():
            try:
                wldict[str(k)] = v
            except:
                pass

        wldict['action'] = action

        onwatchlistpage = req.environ.get('HTTP_REFERER','').find(
                          req.href.watchlist()) != -1

        settings = self.get_settings( user )
        options = settings['booloptions']
        self.options = options
        # Needed here to get updated settings
        if action == "save":
            newoptions = req.args.get('booloptions',[])
            for k in settings['booloptions'].keys():
                settings['booloptions'][k] = k in newoptions
            for realm in self.realms:
                settings[realm + '_fields'] = req.args.get(realm + '_fields', '').split(',')
            for l in settings['listoptions']:
                if l in req.args:
                    settings['listoptions'][l] = [ e.strip() for e in req.args.get(l).split(',')]
            self._save_user_settings(req.authname, settings)

            # Clear session cache for nav items
            try:
                # Clear session cache for nav items, so that the post processor
                # rereads the settings
                del req.session['watchlist_display_notify_navitems']
            except:
                pass
            req.redirect(req.href('watchlist'))
        elif action == "defaultsettings":
            # Only execute if sent using the watchlist preferences form
            if onwatchlistpage and req.method == 'POST':
                self._delete_user_settings(req.authname)
            req.redirect(req.href('watchlist'))

        redirectback_notify = options['stay_at_resource_notify'] and not \
                              onwatchlistpage and not async
示例#4
0
    def __init__(self):
        try:  # Only works for Trac 0.12, but is not needed for Trac 0.11 anyway
            self.fields['ticket'].update(
                self.env[TicketSystem].get_ticket_field_labels())
        except (KeyError, AttributeError):
            pass
        self.fields['ticket']['id'] = self.get_realm_label('ticket')

        try:  # Try to support the Tags Plugin
            from tractags.api import TagSystem
            self.tagsystem = self.env[TagSystem]
        except ImportError, e:
            pass
        else:
            if self.tagsystem:
                self.fields['ticket']['tags'] = _("Tags")

    def get_realm_label(self, realm, n_plural=1, astitle=False):
        if astitle:
            # TRANSLATOR: 'ticket(s)' as title
            return ngettext("Ticket", "Tickets", n_plural)
        else:
            # TRANSLATOR: 'ticket(s)' inside a sentence
            return ngettext("ticket", "tickets", n_plural)

    def _get_sql(self, resids, fuzzy, var='id'):
        if isinstance(resids, basestring):
            sql = decode_range_sql(resids) % {'var': var}
            args = []
        else:
            args = resids
示例#5
0
 def get_navigation_items(self, req):
     user = req.authname
     if user and user != 'anonymous':
         yield ('mainnav', 'watchlist', tag.a(_("Watchlist"),
                href=req.href("watchlist")))
示例#6
0
    def process_request(self, req):
        """Processes requests to the '/watchlist' path."""
        user = to_unicode(req.authname)

        # Reject anonymous users
        if not user or user == 'anonymous':
            # TRANSLATOR: Link part of
            # "Please %(log_in)s to view or change your watchlist"
            log_in = tag.a(_("log in"), href=req.href('login'))
            if tag_ == None:
                # For Trac 0.11
                raise HTTPNotFound(
                    tag("Please ", log_in,
                        " to view or change your watchlist"))
            else:
                # For Trac 0.12
                raise HTTPNotFound(
                    tag_("Please %(log_in)s to view or change your watchlist",
                         log_in=log_in))

        # Get and format request arguments
        realm = to_unicode(req.args.get('realm', u''))
        resid = ensure_string(req.args.get('resid', u'')).strip()
        action = req.args.get('action', 'view')
        async = req.args.get('async', 'false') == 'true'

        # Handle AJAX search early to speed up things
        if action == "search":
            """AJAX search request. At the moment only used to get list
               of all not watched resources."""
            handler = self.realm_handler[realm]
            query = to_unicode(req.args.get('q', u'')).strip()
            group = to_unicode(req.args.get('group', u'notwatched'))
            if not query:
                req.send('', 'text/plain', 200)
            if group == 'notwatched':
                result = list(
                    handler.unwatched_resources(realm,
                                                query,
                                                user,
                                                self,
                                                fuzzy=1))
            else:
                result = list(
                    handler.watched_resources(realm,
                                              query,
                                              user,
                                              self,
                                              fuzzy=1))
            result.sort(cmp=handler.get_sort_cmp(realm),
                        key=handler.get_sort_key(realm))
            req.send(
                unicode(u'\n'.join(result) + u'\n').encode("utf-8"),
                'text/plain', 200)

        # DB cursor
        db = self.env.get_db_cnx()
        cursor = db.cursor()

        wldict = dict()
        for k, v in req.args.iteritems():
            try:
                wldict[str(k)] = v
            except:
                pass

        wldict['action'] = action

        onwatchlistpage = req.environ.get('HTTP_REFERER', '').find(
            req.href.watchlist()) != -1

        settings = self.get_settings(user)
        options = settings['booloptions']
        self.options = options
        # Needed here to get updated settings
        if action == "save":
            newoptions = req.args.get('booloptions', [])
            for k in settings['booloptions'].keys():
                settings['booloptions'][k] = k in newoptions
            for realm in self.realms:
                settings[realm + '_fields'] = req.args.get(
                    realm + '_fields', '').split(',')
            for l in settings['listoptions']:
                if l in req.args:
                    settings['listoptions'][l] = [
                        e.strip() for e in req.args.get(l).split(',')
                    ]
            self._save_user_settings(req.authname, settings)

            # Clear session cache for nav items
            try:
                # Clear session cache for nav items, so that the post processor
                # rereads the settings
                del req.session['watchlist_display_notify_navitems']
            except:
                pass
            req.redirect(req.href('watchlist'))
        elif action == "defaultsettings":
            # Only execute if sent using the watchlist preferences form
            if onwatchlistpage and req.method == 'POST':
                self._delete_user_settings(req.authname)
            req.redirect(req.href('watchlist'))

        redirectback_notify = options['stay_at_resource_notify'] and not \
                              onwatchlistpage and not async
示例#7
0
    def post_process_request(self, req, template, data, content_type):
        """Executed after EVERY request is processed.
           Used to add navigation bars, display messages
           and to note visits to watched resources."""
        user = to_unicode(req.authname)
        if not user or user == "anonymous":
            return (template, data, content_type)

        # Extract realm and resid from path:
        parts = req.path_info[1:].split('/', 1)

        try:
            realm, resid = parts[:2]
        except:
            # Handle special case for '/' and '/wiki'
            if parts[0] == 'wiki' or (parts[0] == ''
                                      and 'WikiModule' == self.env.config.get(
                                          'trac', 'default_handler')):
                realm, resid = 'wiki', 'WikiStart'
            else:
                realm, resid = parts[0], ''

        if realm not in self.realms or not \
                self.realm_handler[realm].has_perm(realm, req.perm):
            return (template, data, content_type)

        notify = 'False'
        # The notification setting is stored in the session to avoid rereading
        # the whole user settings for every page displayed
        try:
            notify = req.session['watchlist_display_notify_navitems']
        except KeyError:
            settings = self.get_settings(user)
            options = settings['booloptions']
            notify = (self.wsub and options['notifications'] and
                      options['display_notify_navitems']) and 'True' or 'False'
            req.session['watchlist_display_notify_navitems'] = notify

        try:
            add_notice(req, req.session['watchlist_message'])
            del req.session['watchlist_message']
        except KeyError:
            pass
        try:
            add_notice(req, req.session['watchlist_notify_message'])
            del req.session['watchlist_notify_message']
        except KeyError:
            pass

        if self.is_watching(realm, resid, user):
            add_ctxtnav(req,
                        _("Unwatch"),
                        href=req.href('watchlist',
                                      action='unwatch',
                                      resid=resid,
                                      realm=realm),
                        title=_("Remove %(document)s from watchlist",
                                document=realm))
            self.visiting(realm, resid, user)
        else:
            add_ctxtnav(req,
                        _("Watch"),
                        href=req.href('watchlist',
                                      action='watch',
                                      resid=resid,
                                      realm=realm),
                        title=_("Add %(document)s to watchlist",
                                document=realm))
        if notify == 'True':
            if self.is_notify(req, realm, resid):
                add_ctxtnav(req,
                            _("Do not Notify me"),
                            href=req.href('watchlist',
                                          action='notifyoff',
                                          resid=resid,
                                          realm=realm),
                            title=_("Do not notify me if %(document)s changes",
                                    document=realm))
            else:
                add_ctxtnav(req,
                            _("Notify me"),
                            href=req.href('watchlist',
                                          action='notifyon',
                                          resid=resid,
                                          realm=realm),
                            title=_("Notify me if %(document)s changes",
                                    document=realm))

        return (template, data, content_type)
示例#8
0
            if onwatchlistpage and req.method == 'POST':
                self._delete_user_settings(req.authname)
            req.redirect(req.href('watchlist'))

        redirectback_notify = options['stay_at_resource_notify'] and not \
                              onwatchlistpage and not async
        if action == "notifyon":
            if not self.res_exists(realm, resid):
                raise HTTPNotFound(t_("Page %(name)s not found", name=resid))
            elif self.wsub and options['notifications']:
                self.set_notify(req, realm, resid)
                db.commit()
            if redirectback_notify:
                if options['show_messages_on_resource_page']:
                    req.session['watchlist_notify_message'] = _("""
                      You are now receiving change notifications
                      about this resource.
                      """)
                req.redirect(req.href(realm, resid))
            if async:
                req.send("", 'text/plain', 200)
            else:
                req.redirect(req.href('watchlist'))
        elif action == "notifyoff":
            if self.wsub and options['notifications']:
                self.unset_notify(req, realm, resid)
                db.commit()
            if redirectback_notify:
                if options['show_messages_on_resource_page']:
                    req.session['watchlist_notify_message'] = _("""
                      You are no longer receiving
                      change notifications about this resource.
示例#9
0
 def get_navigation_items(self, req):
     user = req.authname
     if user and user != 'anonymous':
         yield ('mainnav', 'watchlist',
                tag.a(_("Watchlist"), href=req.href("watchlist")))
示例#10
0
        'name', 'changetime', 'author', 'version', 'diff',
        'history', 'unwatch', 'notify', 'comment',
    ]}
    tagsystem = None


    def __init__(self):
        self.fields['wiki']['name'] = self.get_realm_label('wiki')
        try: # Try to support the Tags Plugin
            from tractags.api import TagSystem
            self.tagsystem = self.env[TagSystem]
        except ImportError, e:
            pass
        else:
            if self.tagsystem:
                self.fields['wiki']['tags'] = _("Tags")


    def get_realm_label(self, realm, n_plural=1, astitle=False):
        if astitle:
            # TRANSLATOR: 'wiki page(s)' as title
            return ngettext("Wiki Page", "Wiki Pages", n_plural)
        else:
            # TRANSLATOR: 'wiki page(s)' inside a sentence
            return ngettext("wiki page", "wiki pages", n_plural)


    def _get_sql(self, resids, fuzzy, var='name'):
        if isinstance(resids,basestring):
            if fuzzy:
                resids += '*'
示例#11
0
                self._delete_user_settings(req.authname)
            req.redirect(req.href('watchlist'))

        redirectback_notify = options['stay_at_resource_notify'] and not \
                              onwatchlistpage and not async
        if action == "notifyon":
            if not self.res_exists(realm, resid):
                raise HTTPNotFound(t_("Page %(name)s not found", name=resid))
            elif self.wsub and options['notifications']:
                self.set_notify(req, realm, resid)
                db.commit()
            if redirectback_notify:
                if options['show_messages_on_resource_page']:
                    req.session['watchlist_notify_message'] = _(
                      """
                      You are now receiving change notifications
                      about this resource.
                      """
                    )
                req.redirect(req.href(realm,resid))
            if async:
                req.send("",'text/plain', 200)
            else:
                req.redirect(req.href('watchlist'))
        elif action == "notifyoff":
            if self.wsub and options['notifications']:
                self.unset_notify(req, realm, resid)
                db.commit()
            if redirectback_notify:
                if options['show_messages_on_resource_page']:
                    req.session['watchlist_notify_message'] = _(
                      """
示例#12
0
    def __init__(self):
        try: # Only works for Trac 0.12, but is not needed for Trac 0.11 anyway
            self.fields['ticket'].update( self.env[TicketSystem].get_ticket_field_labels() )
        except (KeyError, AttributeError):
            pass
        self.fields['ticket']['id'] = self.get_realm_label('ticket')

        try: # Try to support the Tags Plugin
            from tractags.api import TagSystem
            self.tagsystem = self.env[TagSystem]
        except ImportError, e:
            pass
        else:
            if self.tagsystem:
                self.fields['ticket']['tags'] = _("Tags")


    def get_realm_label(self, realm, n_plural=1, astitle=False):
        if astitle:
            # TRANSLATOR: 'ticket(s)' as title
            return ngettext("Ticket", "Tickets", n_plural)
        else:
            # TRANSLATOR: 'ticket(s)' inside a sentence
            return ngettext("ticket", "tickets", n_plural)


    def _get_sql(self, resids, fuzzy, var='id'):
        if isinstance(resids,basestring):
            sql = decode_range_sql( resids ) % {'var':var}
            args = []