Exemple #1
0
    def _wall_events_query(self):
        """WallMixin implementation."""
        from ututi.lib.wall import generic_events_query
        evts_generic = generic_events_query()

        t_evt = meta.metadata.tables['events']
        t_wall_posts = meta.metadata.tables['wall_posts']

        locations = [loc.id for loc in c.location.flatten]
        subjects = meta.Session.query(Subject)\
            .filter(Subject.location_id.in_(locations))\
            .all()
        if self.feed_filter == 'sub_department':
            subject_ids = [subject.id for subject in self.sub_department.subjects
                           if check_crowds(["subject_accessor"], c.user, subject)]
        else:
            subject_ids = [subject.id for subject in subjects
                           if check_crowds(["subject_accessor"], c.user, subject)]
        public_groups = meta.Session.query(Group)\
            .filter(Group.location_id.in_(locations))\
            .filter(Group.forum_is_public == True)\
            .all()
        ids = [obj.id for obj in subjects + public_groups]

        obj_id_in_list = t_evt.c.object_id.in_(ids) if ids else False
        events_query = evts_generic
        if self.feed_filter == 'subjects':
            return events_query.where(or_(obj_id_in_list, t_wall_posts.c.subject_id.in_(subject_ids)))
        elif self.feed_filter == 'sub_department':
            return events_query.where(or_(t_evt.c.object_id.in_(subject_ids) if subject_ids else False, t_wall_posts.c.subject_id.in_(subject_ids)))
        elif self.feed_filter == 'discussions':
            return events_query.where(or_(t_wall_posts.c.target_location_id.in_(locations), t_wall_posts.c.subject_id.in_(subject_ids)))
        else:
            return events_query.where(or_(obj_id_in_list, t_wall_posts.c.target_location_id.in_(locations),
                                          t_wall_posts.c.subject_id.in_(subject_ids)))
Exemple #2
0
    def get_wall_events_query(self):
        user_is_admin_of_groups = [membership.group_id
                                   for membership in self.memberships
                                   if membership.membership_type == 'administrator']
        subjects = self.all_watched_subjects
        if self.is_teacher:
            subjects += self.taught_subjects
        from ututi.lib.wall import generic_events_query
        evts_generic = generic_events_query()

        t_evt = meta.metadata.tables['events']
        t_evt_comments = meta.metadata.tables['event_comments']
        t_wall_posts = meta.metadata.tables['wall_posts']
        t_content_items = meta.metadata.tables['content_items']
        subject_ids = [s.id for s in subjects]
        group_ids = [m.group.id for m in self.memberships]
        user_commented_evts_select = select([t_evt_comments.c.event_id],
                                            from_obj=[t_evt_comments.join(t_content_items,
                                                                          t_content_items.c.id == t_evt_comments.c.id)],)\
            .where(t_content_items.c.created_by == self.id)
        user_commented_evts = map(lambda r: r[0], meta.Session.execute(user_commented_evts_select).fetchall())

        query = evts_generic\
            .where(or_(or_(t_evt.c.object_id.in_(subject_ids),
                           t_wall_posts.c.subject_id.in_(subject_ids)) if subject_ids else False,  # subject wall posts
                       and_(or_(t_evt.c.author_id == self.id,  # location wall posts
                                # XXX User comments may grow to 1k-10k scale, consider a different implementation.
                                t_evt.c.id.in_(user_commented_evts) if user_commented_evts else False),
                            t_evt.c.event_type.in_(('subject_wall_post', 'location_wall_post'))),
                       or_(t_evt.c.object_id.in_(group_ids),) if group_ids else False))\
            .where(or_(t_evt.c.event_type != 'moderated_post_created',
                       t_evt.c.object_id.in_(user_is_admin_of_groups) if user_is_admin_of_groups else False))\
            .where(not_(t_evt.c.event_type.in_(self.ignored_events_list) if self.ignored_events_list else False))
        return query
Exemple #3
0
    def _wall_events_query(self):
        """WallMixin implementation."""
        public_event_types = [
            'group_created',
            'subject_created',
            'subject_modified',
            'page_created',
            'page_modified',
        ]
        from ututi.lib.wall import generic_events_query
        t_evt = meta.metadata.tables['events']
        evts_generic = generic_events_query()

        if hasattr(c, 'teacher'):
            user_id = c.teacher.id
        else:
            user_id = c.user_info.id

        query = evts_generic\
            .where(t_evt.c.author_id == user_id)

        # XXX using literal_column, this is because I don't know how
        # to refer to the column in the query directly
        query = query.where(or_(t_evt.c.event_type.in_(public_event_types),
                                and_(t_evt.c.event_type == 'file_uploaded',
                                     literal_column('context_ci.content_type') == 'subject')))

        return query
Exemple #4
0
    def _wall_events_query(self):
        """WallMixin implementation."""
        from ututi.lib.wall import generic_events_query
        evts_generic = generic_events_query()

        t_evt = meta.metadata.tables['events']
        t_wall_posts = meta.metadata.tables['wall_posts']
        query = evts_generic\
             .where(or_(t_evt.c.object_id == c.subject.id,
                             t_wall_posts.c.subject_id == c.subject.id))

        if getattr(self, 'feed_filter', None) == u'discussions':
            query = query.where(t_evt.c.event_type=='subject_wall_post')

        return query
Exemple #5
0
    def _wall_events_query(self):
        """WallMixin implementation."""
        user_is_admin_of_groups = [membership.group_id
                                   for membership in c.user.memberships
                                   if membership.membership_type == 'administrator']
        from ututi.lib.wall import generic_events_query
        evts_generic = generic_events_query()
        t_evt = meta.metadata.tables['events']
        watched_subject_ids = [s.id for s in c.group.watched_subjects]
        object_id_in_list = t_evt.c.object_id.in_(watched_subject_ids) if watched_subject_ids else False
        object_id_in_admin_groups = (t_evt.c.object_id.in_(user_is_admin_of_groups)
                                     if user_is_admin_of_groups else False)
        query = evts_generic\
                .where(or_(object_id_in_list,
                           t_evt.c.object_id == c.group.id))\
                .where(or_(t_evt.c.event_type != 'moderated_post_created',
                           object_id_in_admin_groups))

        return query
Exemple #6
0
    def _wall_events_query(self):
        """WallMixin implementation."""
        from ututi.lib.wall import generic_events_query
        evts_generic = generic_events_query()

        return evts_generic