Пример #1
0
    def subscribe_to_forum(self, subscribe=None, unsubscribe=None, shortname=None, **kw):
        if subscribe:
            self.discussion.subscribe(type='direct')

            # unsubscribe from all individual threads that are part of this forum, so you don't have overlapping subscriptions
            forumthread_index_prefix = (DM.ForumThread.__module__ + '.' + DM.ForumThread.__name__).replace('.', '/') + '#'
            thread_mboxes = M.Mailbox.query.find(dict(
                user_id=c.user._id,
                project_id=c.project._id,
                app_config_id=c.app.config._id,
                artifact_index_id=re.compile('^' + re.escape(forumthread_index_prefix)),
            )).all()
            # get the ForumThread objects from the subscriptions
            thread_index_ids = [mbox.artifact_index_id for mbox in thread_mboxes]
            threads_by_id = mapped_artifacts_from_index_ids(thread_index_ids, DM.ForumThread, objectid_id=False)
            for mbox in thread_mboxes:
                thread_id = mbox.artifact_index_id.split('#')[1]
                thread = threads_by_id[thread_id]
                # only delete if the ForumThread is part of this forum
                if thread.discussion_id == self.discussion._id:
                    mbox.delete()

        elif unsubscribe:
            self.discussion.unsubscribe()

        return {
            'status': 'ok',
            'subscribed': M.Mailbox.subscribed(artifact=self.discussion),
            'subscribed_to_tool': M.Mailbox.subscribed(),
        }
Пример #2
0
    def _search(self,
                model,
                fields,
                add_fields,
                q=None,
                f=None,
                page=0,
                limit=None,
                **kw):
        all_fields = fields + [(fld, fld) for fld in add_fields]
        c.search_form = W.admin_search_form(all_fields)
        c.page_list = W.page_list
        c.page_size = W.page_size
        count = 0
        objects = []
        limit, page, start = g.handle_paging(limit, page, default=25)
        if q:
            match = search.site_admin_search(model,
                                             q,
                                             f,
                                             rows=limit,
                                             start=start)
            if match:
                count = match.hits
                objects = match.docs

                ids = [obj['id'] for obj in objects]
                mongo_objects = search.mapped_artifacts_from_index_ids(
                    ids, model)
                for i in range(len(objects)):
                    obj = objects[i]
                    _id = obj['id'].split('#')[1]
                    obj['object'] = mongo_objects.get(_id)
                # Some objects can be deleted, but still have index in solr, should skip those
                objects = [o for o in objects if o.get('object')]

        def convert_fields(obj):
            # throw the type away (e.g. '_s' from 'url_s')
            result = {}
            for k, val in obj.iteritems():
                name = k.rsplit('_', 1)
                if len(name) == 2:
                    name = name[0]
                else:
                    name = k
                result[name] = val
            return result

        return {
            'q': q,
            'f': f,
            'objects': map(convert_fields, objects),
            'count': count,
            'page': page,
            'limit': limit,
            'fields': fields,
            'additional_fields': add_fields,
            'type_s': model.type_s,
        }
Пример #3
0
    def _search(self, model, fields, add_fields, q=None, f=None, page=0, limit=None, **kw):
        all_fields = fields + [(fld, fld) for fld in add_fields]
        c.search_form = W.admin_search_form(all_fields)
        c.page_list = W.page_list
        c.page_size = W.page_size
        count = 0
        objects = []
        limit, page, start = g.handle_paging(limit, page, default=25)
        if q:
            match = search.site_admin_search(model, q, f, rows=limit, start=start)
            if match:
                count = match.hits
                objects = match.docs

                ids = [obj['id'] for obj in objects]
                mongo_objects = search.mapped_artifacts_from_index_ids(ids, model)
                for i in range(len(objects)):
                    obj = objects[i]
                    _id = obj['id'].split('#')[1]
                    obj['object'] = mongo_objects.get(_id)
                # Some objects can be deleted, but still have index in solr, should skip those
                objects = [o for o in objects if o.get('object')]

        def convert_fields(obj):
            # throw the type away (e.g. '_s' from 'url_s')
            result = {}
            for k,val in obj.iteritems():
                name = k.rsplit('_', 1)
                if len(name) == 2:
                    name = name[0]
                else:
                    name = k
                result[name] = val
            return result

        return {
            'q': q,
            'f': f,
            'objects': map(convert_fields, objects),
            'count': count,
            'page': page,
            'limit': limit,
            'fields': fields,
            'additional_fields': add_fields,
            'type_s': model.type_s,
        }
Пример #4
0
    def subscribe_to_forum(self,
                           subscribe=None,
                           unsubscribe=None,
                           shortname=None,
                           **kw):
        if subscribe:
            self.discussion.subscribe(type='direct')

            # unsubscribe from all individual threads that are part of this forum, so you don't have overlapping subscriptions
            forumthread_index_prefix = (DM.ForumThread.__module__ + '.' +
                                        DM.ForumThread.__name__).replace(
                                            '.', '/') + '#'
            thread_mboxes = M.Mailbox.query.find(
                dict(
                    user_id=c.user._id,
                    project_id=c.project._id,
                    app_config_id=c.app.config._id,
                    artifact_index_id=re.compile(
                        '^' + re.escape(forumthread_index_prefix)),
                )).all()
            # get the ForumThread objects from the subscriptions
            thread_index_ids = [
                mbox.artifact_index_id for mbox in thread_mboxes
            ]
            threads_by_id = mapped_artifacts_from_index_ids(thread_index_ids,
                                                            DM.ForumThread,
                                                            objectid_id=False)
            for mbox in thread_mboxes:
                thread_id = mbox.artifact_index_id.split('#')[1]
                thread = threads_by_id[thread_id]
                # only delete if the ForumThread is part of this forum
                if thread.discussion_id == self.discussion._id:
                    mbox.delete()

        elif unsubscribe:
            self.discussion.unsubscribe()

        return {
            'status': 'ok',
            'subscribed': M.Mailbox.subscribed(artifact=self.discussion),
            'subscribed_to_tool': M.Mailbox.subscribed(),
        }