예제 #1
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = find_entities(user=user,
                                interfaces=[IPreregistration],
                                sort_on='release_date')
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_registrations"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        result_body, result = render_listing_objs(self.request, batch, user)

        values = {
            'bodies': result_body,
            'length': len_result,
            'batch': batch,
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #2
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = [obj for obj
                   in self.context.get_sub_nodes()
                   if can_access(user, obj)]
        objects = sorted(
            objects,
            key=lambda e: getattr(e, 'modified_at'),
            reverse=True)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_node_dependencies_" + str(self.context.__oid__)
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(WG_MESSAGES[index], mapping={'number': len_result})
        result = {}
        result_body = render_small_listing_objs(
            self.request, batch, user)

        values = {
            'bodies': result_body,
            'batch': batch,
            'empty_message': _("No association"),
            'empty_icon': 'glyphicon glyphicon-link'
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #3
0
    def update(self):
        self.execute(None)
        objects = self.context.newsletters
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_newsletters"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})

        user = get_current()
        result_body, result = render_listing_objs(
            self.request, batch, user)

        result = {}
        values = {
            'bodies': result_body,
            'length': len_result,
            'batch': batch,
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #4
0
    def update(self):
        self.execute(None)
        root = getSite()
        objects = root.preregistrations
        objects.reverse()
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_registrations"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'nember': len_result})
        result_body = []
        for obj in batch:
            object_values = {'object': obj}
            body = self.content(args=object_values,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        result = {}
        values = {
            'bodies': result_body,
            'length': len_result,
            'batch': batch,
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #5
0
    def get_related_contents(self, user, interface):
        lac_catalog = find_catalog('lac')
        venue_index = lac_catalog['object_venue']
        query = venue_index.any([self.context.get_id()])
        objects = find_entities(user=user,
                                interfaces=[interface],
                                metadata_filter={'states': ['published']},
                                add_query=query,
                                include_site=True)
        batch = Batch(objects,
                      self.request,
                      default_size=core.BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents" + str(interface.__name__)
        len_result = batch.seqlen
        result_body = []
        for obj in batch:
            render_dict = {
                'object':
                obj,
                'current_user':
                user,
                'state':
                get_states_mapping(user, obj,
                                   getattr(obj, 'state_or_none', [None])[0])
            }
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        values = {'bodies': result_body, 'batch': batch}
        contents_body = self.content(
            args=values, template=self.related_events_template)['body']
        return ((result_body and contents_body) or None), len_result
예제 #6
0
    def update(self):
        self.execute(None)
        objects = self.context.files
        default = datetime.datetime.now(tz=pytz.UTC)
        objects = sorted(objects,
                         key=lambda e: getattr(e, 'modified_at', default),
                         reverse=True)
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_files"
        len_result = batch.seqlen
        result_body = []
        for obj in batch:
            object_values = {'object': obj}
            body = self.content(args=object_values,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        result = {}
        values = {'bodies': result_body,
                  'length': len_result,
                  'batch': batch}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #7
0
 def update(self):
     user = get_current()
     context_oid = get_oid(self.context)
     dace_index = find_catalog('dace')
     dace_container_oid = dace_index['container_oid']
     query = dace_container_oid.eq(context_oid)
     objects = find_entities(
         user=user,
         interfaces=[ISReport],
         metadata_filter={'states': [self.report_state]},
         add_query=query)
     url = self.request.resource_url(
         self.context, '', query={'view_report_state': self.report_state})
     batch = Batch(objects,
                   self.request,
                   url=url,
                   default_size=BATCH_DEFAULT_SIZE)
     self.title = _(self.title, mapping={'nb': batch.seqlen})
     batch.target = "#results" + "-report-" + self.report_state.replace(
         ' ', '')
     result_body, result = render_listing_objs(self.request, batch, user)
     values = {
         'bodies': result_body,
         'batch': batch,
         'empty_message': self.empty_message,
         'empty_icon': self.empty_icon
     }
     body = self.content(args=values, template=self.template)['body']
     item = self.adapt_item(body, self.viewid)
     result['coordinates'] = {self.coordinates: [item]}
     return result
예제 #8
0
 def update(self):
     user = get_current()
     context_oid = get_oid(self.context)
     dace_index = find_catalog('dace')
     dace_container_oid = dace_index['container_oid']
     query = dace_container_oid.eq(context_oid)
     objects = find_entities(
         user=user,
         interfaces=[ISReport],
         metadata_filter={
             'states': [self.report_state]
         },
         add_query=query)
     url = self.request.resource_url(
         self.context, '',
         query={'view_report_state': self.report_state})
     batch = Batch(objects,
                   self.request,
                   url=url,
                   default_size=BATCH_DEFAULT_SIZE)
     self.title = _(self.title, mapping={'nb': batch.seqlen})
     batch.target = "#results"+"-report-" + self.report_state.replace(' ', '')
     result_body, result = render_listing_objs(
         self.request, batch, user)
     values = {'bodies': result_body,
               'batch': batch,
               'empty_message': self.empty_message,
               'empty_icon': self.empty_icon}
     body = self.content(args=values, template=self.template)['body']
     item = self.adapt_item(body, self.viewid)
     result['coordinates'] = {self.coordinates: [item]}
     return result
예제 #9
0
    def get_related_contents(self, user, interface):
        lac_catalog = find_catalog('lac')
        venue_index = lac_catalog['object_venue']
        query = venue_index.any([self.context.get_id()])
        objects = find_entities(
            user=user,
            interfaces=[interface],
            metadata_filter={'states': ['published']},
            add_query=query,
            include_site=True)
        batch = Batch(objects, self.request,
                      default_size=core.BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"+str(interface.__name__)
        len_result = batch.seqlen
        result_body = []
        for obj in batch:
            render_dict = {'object': obj,
                           'current_user': user,
                           'state': get_states_mapping(user, obj,
                                   getattr(obj, 'state_or_none', [None])[0])}
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        values = {'bodies': result_body,
                  'batch': batch}
        contents_body = self.content(
            args=values,
            template=self.related_events_template)['body']
        return ((result_body and contents_body) or None), len_result
예제 #10
0
    def update(self):
        self.execute(None)
        objects = find_entities(
            user=get_current(),
            interfaces=[IOrganization],
            sort_on='modified_at', reverse=True)
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_organizations"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'nember': len_result})
        result_body = []
        for obj in batch:
            object_values = {'object': obj}
            body = self.content(args=object_values,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        result = {}
        values = {
                'bodies': result_body,
                'length': len_result,
                'batch': batch,
               }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #11
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = getattr(self.context.working_group, 'members', [])
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_proposal_members" + str(self.context.__oid__)
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        result_body = render_small_listing_objs(self.request, batch, user)
        result = {}
        self.title = _(MEMBERS_MESSAGES[index], mapping={'number': len_result})
        values = {
            'bodies': result_body,
            'batch': batch,
            'empty_message': _("No members"),
            'empty_icon': 'glyphicon glyphicon-user'
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #12
0
    def update(self):
        user = get_current()
        filter_form, filter_data = self._add_filter(user)
        args = merge_with_filter_view(self, {})
        args['request'] = self.request
        filters = [
            {
                'metadata_filter': {
                    'states': ['published'],
                    'interfaces': [IAnswer]
                }
            },
        ]
        # Answer is non a searchable element
        # we need add it to the args dict
        args['interfaces'] = [IAnswer]
        objects = find_entities(filters=filters,
                                user=user,
                                intersect=self._get_answers(user),
                                **args)
        objects, sort_body = sort_view_objects(self, objects, ['answer'], user,
                                               'nbsupport')
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results-answers"
        len_answers = batch.seqlen
        index = str(len_answers) if len_answers <= 1 else '*'
        if not self.parent:
            self.title = _(CONTENTS_MESSAGES[index],
                           mapping={'number': len_answers})
        elif index != '*':
            self.title = _('The answer')

        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body, result = render_listing_objs(self.request, batch, user)
        if filter_form:
            result = merge_dicts(
                {
                    'css_links': filter_form['css_links'],
                    'js_links': filter_form['js_links']
                }, result)

        values = {
            'bodies': result_body,
            'batch': batch,
            'empty_message': self.empty_message,
            'empty_icon': self.empty_icon,
            'filter_body': filter_body,
            'sort_body': sort_body,
            'view': self
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        item['isactive'] = True
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #13
0
    def update(self):
        self.execute(None)
        site = get_site_folder(True)
        objects = site.newsletters
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_newsletters"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'nember': len_result})
        result_body = []
        for obj in batch:
            object_values = {'object': obj}
            body = self.content(args=object_values,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        result = {}
        values = {
            'bodies': result_body,
            'length': len_result,
            'batch': batch,
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #14
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = find_entities(
            user=user,
            interfaces=[IPreregistration],
            sort_on='release_date')
        batch = Batch(
            objects, self.request,
            default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_registrations"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        result_body, result = render_listing_objs(
            self.request, batch, user)

        values = {
            'bodies': result_body,
            'length': len_result,
            'batch': batch,
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #15
0
    def update(self):
        self.execute(None)
        user = get_current()
        site = str(get_oid(get_site_folder(True)))
        games = find_entities(interfaces=[IGame],
                              metadata_filter={'states': ['published']},
                              other_filter={'sources': [site]},
                              force_publication_date=True)

        batch = Batch(games, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'nember': len_result})
        result_body = []
        for obj in batch:
            render_dict = {'object': obj, 'current_user': user, 'state': None}
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        result = {}
        values = {'bodies': result_body, 'batch': batch}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #16
0
    def update(self):
        self.execute(None)
        objects = self.context.organizations
        now = datetime.datetime.now(tz=pytz.UTC)
        objects = sorted(objects,
                         key=lambda e: getattr(e, 'modified_at', now),
                         reverse=True)
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_organizations"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        user = get_current()
        result_body, result = render_listing_objs(self.request, batch, user)
        values = {
            'bodies': result_body,
            'length': len_result,
            'batch': batch,
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #17
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = getattr(self.context.working_group, 'members', [])
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_proposal_members" + str(self.context.__oid__)
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        result_body = render_small_listing_objs(
            self.request, batch, user)
        result = {}
        self.title = _(MEMBERS_MESSAGES[index], mapping={'number': len_result})
        values = {
            'bodies': result_body,
            'batch': batch,
            'empty_message': _("No members"),
            'empty_icon': 'glyphicon glyphicon-user'
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #18
0
    def get_related_contents(self, user):
        interfaces = get_subinterfaces(IBaseReview)
        interfaces.extend([ICulturalEvent, IFilmSynopses])
        objects = find_entities(
            user=user,
            interfaces=interfaces,
            metadata_filter={'states': ['published']},
            contribution_filter={'artists_ids': [self.context]},
            include_site=True,
            sort_on='release_date',
            reverse=True)
        batch = Batch([o for o in objects], self.request,
                      default_size=core.BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        result_body = []
        for obj in batch:
            render_dict = {'object': obj,
                           'current_user': user,
                           'state': get_states_mapping(user, obj,
                                   getattr(obj, 'state_or_none', [None])[0])}
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        values = {'bodies': result_body,
                  'batch': batch}
        contents_body = self.content(
            args=values,
            template=self.related_contents_template)['body']
        return ((result_body and contents_body) or None), len_result
예제 #19
0
    def get_related_contents(self, user):
        interfaces = get_subinterfaces(IBaseReview)
        interfaces.extend([ICulturalEvent, IFilmSynopses])
        objects = find_entities(
            user=user,
            interfaces=interfaces,
            metadata_filter={'states': ['published']},
            contribution_filter={'artists_ids': [self.context]},
            include_site=True,
            sort_on='release_date',
            reverse=True)
        batch = Batch([o for o in objects],
                      self.request,
                      default_size=core.BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        result_body = []
        for obj in batch:
            render_dict = {
                'object':
                obj,
                'current_user':
                user,
                'state':
                get_states_mapping(user, obj,
                                   getattr(obj, 'state_or_none', [None])[0])
            }
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        values = {'bodies': result_body, 'batch': batch}
        contents_body = self.content(
            args=values, template=self.related_contents_template)['body']
        return ((result_body and contents_body) or None), len_result
예제 #20
0
    def update(self):
        self.execute(None)
        objects = self.context.organizations
        now = datetime.datetime.now(tz=pytz.UTC)
        objects = sorted(objects,
                         key=lambda e: getattr(e, 'modified_at', now),
                         reverse=True)
        batch = Batch(
            objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_organizations"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        user = get_current()
        result_body, result = render_listing_objs(
            self.request, batch, user)
        values = {
            'bodies': result_body,
            'length': len_result,
            'batch': batch,
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #21
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = find_entities(
            user=user, interfaces=[IChallenge],
            metadata_filter={'states': ['pending']},
            sort_on='release_date')
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(
            objects, self.request, url=url, default_size=BATCH_HOME_DEFAULT_SIZE)
        batch.target = "#results-home-challenges"
        len_result = batch.seqlen
        user = get_current()
        if len_result == 0:
            self.no_challenges = True
            result = {}
            result_body = []
        else:
            self.title = self.request.localizer.translate(self.title)
            result_body, result = render_listing_objs(
                self.request, batch, user, 'card')

        values = {
            'bodies': result_body,
            'batch': batch
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #22
0
    def update(self):
        self.execute(None)
        user = get_current()
        is_manager = has_role(user=user, role=('PortalManager', ))
        filters = [
            {'metadata_filter': {
                'content_types': ['person']
            }}
        ]
        filter_form, filter_data = self._add_filter(user, is_manager)
        args = merge_with_filter_view(self, {})
        args['request'] = self.request
        objects = find_entities(
            user=user,
            filters=filters,
            **args)
        objects, sort_body = sort_view_objects(
            self, objects, ['person'], user)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_users"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = self._get_title(
            index=index, len_result=len_result, user=user)
        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body, result = render_listing_objs(
            self.request, batch, user)
        novaideo_catalog = find_catalog('novaideo')
        last_connection_index = novaideo_catalog['last_connection']
        current_date = datetime.datetime.combine(
            datetime.datetime.now(),
            datetime.time(0, 0, 0, tzinfo=pytz.UTC))
        inactive_users = find_users(
            last_connection_index, current_date, (INACTIVITY_DURATION, None))
        if filter_form:
            result = merge_dicts(
                {'css_links': filter_form['css_links'],
                'js_links': filter_form['js_links']
                }, result)

        values = {'bodies': result_body,
                  'batch': batch,
                  'is_manager': is_manager,
                  'inactivity_duration': INACTIVITY_DURATION,
                  'inactive_users': inactive_users.__len__(),
                  'filter_body': filter_body,
                  'sort_body': sort_body}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #23
0
    def update(self):
        user = get_current()
        validated = getattr(self, 'validated', {})
        not_validated = True if not validated else False
        posted = self.request.POST or self.request.GET or {}
        posted = posted.copy()
        executed = not not_validated
        if not_validated:
            formviewinstance = SearchView(self.context, self.request)
            formviewinstance.postedform = posted
            validated = formviewinstance.calculate_posted_filter()
            executed = getattr(formviewinstance, 'executed', False)

        if not executed or self.params('filter_result'):
            default_content = [key[0] for key in
                               get_default_searchable_content(self.request)]
            default_content.remove("person")
            default_content.remove("event")
            if 'question' in default_content:
                default_content.remove("question")

            filter_ = {
                'metadata_filter': {'content_types': default_content}
            }
            validated = merge_with_filter_view(self, {})
            validated['request'] = self.request
            validated['filters'] = [filter_]

        objects = find_entities(
            user=user,
            **validated)
        # content_types = validated.get('metadata_filter', {}).get('content_types', ['all'])
        # objects, sort_body = sort_view_objects(
        #     self, objects, content_types, user)
        url = self.request.resource_url(
            self.context, self.request.view_name,
            query=posted)
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        result_body, result = render_listing_objs(
            self.request, batch, user)
        values = {'bodies': result_body,
                  'batch': batch}
                  # 'sort_body': sort_body}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #24
0
파일: home.py 프로젝트: ecreall/nova-ideo
    def update(self):
        body = ''
        result = {}
        if self.isactive or self.params('on_demand') == 'load':
            user = get_current()
            filter_form, filter_data = self._add_filter(user)
            default_content = [self.content_type]
            validated = self._get_validated({
                'metadata_filter':
                    {'content_types': default_content,
                    'states': ['active', 'published']},
            }, user)
            args = {}
            args = merge_with_filter_view(self, args)
            args['request'] = self.request
            objects = find_entities(
                user=user,
                filters=[validated],
                **args)
            objects, sort_body = sort_view_objects(
                self, objects, [self.content_type], user)
            url = self.request.resource_url(
                self.context, '',
                query={'view_content_id': self.content_id})
            batch = Batch(objects,
                          self.request,
                          url=url,
                          default_size=BATCH_DEFAULT_SIZE)
            self.title = _(self.title, mapping={'nb': batch.seqlen})
            batch.target = "#results-" + self.content_id
            filter_instance = getattr(self, 'filter_instance', None)
            filter_body = None
            if filter_instance:
                filter_data['filter_message'] = self.title
                filter_body = filter_instance.get_body(filter_data)
            result_body, result = render_listing_objs(
                self.request, batch, user,
                display_state=getattr(self, 'display_state', True))
            values = {'bodies': result_body,
                      'batch': batch,
                      'empty_message': self.empty_message,
                      'empty_icon': self.empty_icon,
                      'filter_body': filter_body,
                      'filter_class': self.filter_class,
                      'sort_body': sort_body,
                      'view': self}
            if filter_form:
                result = merge_dicts(
                    {'css_links': filter_form['css_links'],
                     'js_links': filter_form['js_links']
                    }, result)

            body = self.content(args=values, template=self.template)['body']

        item = self.adapt_item(body, self.viewid)
        item['isactive'] = self.isactive
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #25
0
파일: home.py 프로젝트: ecreall/KuneAgi
    def update(self):
        body = ''
        result = {}
        if self.isactive or self.params('on_demand') == 'load':
            user = get_current()
            filter_form, filter_data = self._add_filter(user)
            default_content = [self.content_type]
            validated = self._get_validated({
                'metadata_filter':
                    {'content_types': default_content,
                    'states': ['active', 'published']},
            }, user)
            args = {}
            args = merge_with_filter_view(self, args)
            args['request'] = self.request
            objects = find_entities(
                user=user,
                filters=[validated],
                **args)
            objects, sort_body = sort_view_objects(
                self, objects, [self.content_type], user)
            url = self.request.resource_url(
                self.context, '',
                query={'view_content_id': self.content_id})
            batch = Batch(objects,
                          self.request,
                          url=url,
                          default_size=BATCH_DEFAULT_SIZE)
            self.title = _(self.title, mapping={'nb': batch.seqlen})
            batch.target = "#results-" + self.content_id
            filter_instance = getattr(self, 'filter_instance', None)
            filter_body = None
            if filter_instance:
                filter_data['filter_message'] = self.title
                filter_body = filter_instance.get_body(filter_data)
            result_body, result = render_listing_objs(
                self.request, batch, user,
                display_state=getattr(self, 'display_state', True))
            values = {'bodies': result_body,
                      'batch': batch,
                      'empty_message': self.empty_message,
                      'empty_icon': self.empty_icon,
                      'filter_body': filter_body,
                      'filter_class': self.filter_class,
                      'sort_body': sort_body,
                      'view': self}
            if filter_form:
                result = merge_dicts(
                    {'css_links': filter_form['css_links'],
                     'js_links': filter_form['js_links']
                    }, result)

            body = self.content(args=values, template=self.template)['body']

        item = self.adapt_item(body, self.viewid)
        item['isactive'] = self.isactive
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #26
0
    def update(self):
        self.execute(None)
        user = self.context
        current_user = get_current()
        def actions_getter():
            return [a for a in self.context.actions \
                   if getattr(a.action, 'style', '') == 'button']

        actions_navbar = get_actions_navbar(actions_getter, self.request,
                                ['global-action', 'text-action'])
        isactive = actions_navbar['modal-action']['isactive']
        messages = actions_navbar['modal-action']['messages']
        resources = actions_navbar['modal-action']['resources']
        objects = []
        if current_user is  user:
            objects = [o for o in getattr(user, 'contents', []) \
                      if not('archived' in o.state)]
        else:
            objects = [o for o in getattr(user, 'contents', []) \
                      if not('archived' in o.state) and\
                         can_access(current_user, o)]
      
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        result_body = []
        result = {}
        for obj in batch:
            object_values = {'object': obj, 
                             'current_user': current_user, 
                             'state': get_states_mapping(current_user, obj, 
                                   getattr(obj, 'state', [None])[0])
                             }
            body = self.content(result=object_values,
                    template=obj.result_template)['body']
            result_body.append(body)

        values = {'bodies': result_body,
                  'length': len_result,
                  'batch': batch
                  }
        contents_body = self.content(result=values,
                template=SearchResultView.template)['body']

        values = {'contents': (result_body and contents_body) or None,
                  'proposals': None,
                  'user': self.context,
                  'state': get_states_mapping(current_user, user, 
                                getattr(user, 'state', [None])[0]), 
                  'navbar_body': navbar_body_getter(self, actions_navbar)}
        body = self.content(result=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        item['messages'] = messages
        item['isactive'] = isactive
        result.update(resources)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #27
0
파일: search.py 프로젝트: ecreall/nova-ideo
    def update(self):
        user = get_current()
        validated = getattr(self, 'validated', {})
        not_validated = True if not validated else False
        posted = self.request.POST or self.request.GET or {}
        posted = posted.copy()
        executed = not not_validated
        if not_validated:
            formviewinstance = SearchView(self.context, self.request)
            formviewinstance.postedform = posted
            validated = formviewinstance.calculate_posted_filter()
            executed = getattr(formviewinstance, 'executed', False)

        if not executed or self.params('filter_result'):
            default_content = [key[0] for key in
                               get_default_searchable_content(self.request)]
            default_content.remove("person")
            if 'question' in default_content:
                default_content.remove("question")

            filter_ = {
                'metadata_filter': {'content_types': default_content}
            }
            validated = merge_with_filter_view(self, {})
            validated['request'] = self.request
            validated['filters'] = [filter_]

        objects = find_entities(
            user=user,
            **validated)
        # content_types = validated.get('metadata_filter', {}).get('content_types', ['all'])
        # objects, sort_body = sort_view_objects(
        #     self, objects, content_types, user)
        url = self.request.resource_url(
            self.context, self.request.view_name,
            query=posted)
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        result_body, result = render_listing_objs(
            self.request, batch, user)
        values = {'bodies': result_body,
                  'batch': batch}
                  # 'sort_body': sort_body}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #28
0
    def update(self):
        self.execute(None)
        user = get_current()
        validated = getattr(self, 'validated', {})
        posted = self.request.POST or self.request.GET or {}
        posted = posted.copy()
        clear_posted = False
        if not validated:
            if posted:
                clear_posted = True
                searcinstance = SearchView(self.context, self.request,
                                           filter_result=True)
                if searcinstance.validated:
                    validated = searcinstance.validated

        objects = find_entities(
            user=user,
            sort_on='release_date', reverse=True,
            include_site=True,
            **validated)
        url = self.request.resource_url(
            self.context, self.request.view_name, query=posted)
        batch = Batch(objects, self.request,
                      default_size=core.BATCH_DEFAULT_SIZE,
                      url=url)
        #clear posted values: See usermenu panel
        if clear_posted:
            if self.request.POST:
                self.request.POST.clear()
            elif self.request.GET:
                self.request.GET.clear()

        batch.target = "#results_contents"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'nember': len_result})
        result_body = []
        for obj in batch:
            render_dict = {'object': obj,
                           'current_user': user,
                           'state': get_states_mapping(user, obj,
                                   getattr(obj, 'state_or_none', [None])[0])}
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        result = {}
        values = {'bodies': result_body,
                  'batch': batch}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #29
0
    def update(self):
        self.execute(None)
        user = get_current()
        filter_form, filter_data = self._add_filter(user)
        args = merge_with_filter_view(self, {})
        args['request'] = self.request
        objects = find_entities(user=user,
                                intersect=self._get_content_ids(user),
                                include_archived=self.include_archived,
                                **args)
        objects, sort_body = sort_view_objects(self,
                                               objects,
                                               self.content_types,
                                               user,
                                               intersect=getattr(
                                                   self, 'sorts', None))
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = self._get_title(index=index,
                                     len_result=len_result,
                                     user=user)
        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body, result = render_listing_objs(self.request,
                                                  batch,
                                                  user,
                                                  display_state=getattr(
                                                      self, 'display_state',
                                                      True))
        if filter_form:
            result = merge_dicts(
                {
                    'css_links': filter_form['css_links'],
                    'js_links': filter_form['js_links']
                }, result)

        values = {
            'bodies': result_body,
            'batch': batch,
            'filter_body': filter_body,
            'sort_body': sort_body
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #30
0
    def update(self):
        self.execute(None)
        user = get_current()
        filter_form, filter_data = self._add_filter(user)
        content_types = list(core.SEARCHABLE_CONTENTS.keys())
        args = {'metadata_filter': {'content_types': content_types}}
        args = merge_with_filter_view(self, args)
        args['request'] = self.request
        objects = find_entities(user=user,
                                sort_on='release_date',
                                reverse=True,
                                include_site=True,
                                **args)
        url = self.request.resource_url(self.context, 'contentstomoderate')
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=core.BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'nember': len_result})
        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body = []
        for obj in batch:
            render_dict = {
                'object':
                obj,
                'current_user':
                user,
                'state':
                get_states_mapping(user, obj,
                                   getattr(obj, 'state_or_none', [None])[0])
            }
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        result = {}
        values = {
            'bodies': result_body,
            'batch': batch,
            'filter_body': filter_body
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        result['css_links'] = filter_form['css_links']
        result['js_links'] = filter_form['js_links']
        return result
예제 #31
0
    def update(self):
        self.execute(None)
        user = get_current()
        filter_form, filter_data = self._add_filter(user)
        filters = [{
            'metadata_filter': {
                'negation': True,
                'states': ['examined']
            }
        }, {
            'metadata_filter': {
                'content_types': ['idea'],
                'states': ['published']
            }
        }]
        args = {}
        args = merge_with_filter_view(self, args)
        args['request'] = self.request
        objects = find_entities(user=user, filters=filters, **args)
        objects, sort_body = sort_view_objects(self, objects, ['idea'], user,
                                               'nbsupport')
        url = self.request.resource_url(self.context, 'seeideastoexamine')
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body, result = render_listing_objs(self.request, batch, user)
        if filter_form:
            result = merge_dicts(
                {
                    'css_links': filter_form['css_links'],
                    'js_links': filter_form['js_links']
                }, result)

        values = {
            'bodies': result_body,
            'batch': batch,
            'filter_body': filter_body,
            'sort_body': sort_body
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #32
0
    def update(self):
        current_date = datetime.datetime.combine(
            datetime.datetime.now(), datetime.time(0, 0, 0, tzinfo=pytz.UTC))
        alert_date_min = current_date - datetime.timedelta(
            days=INACTIVITY_DURATION)
        user = get_current()
        filters = [{
            'metadata_filter': {
                'content_types': ['person'],
                'states': ['active']
            },
            'temporal_filter': {
                'negation': True,
                'connected_date': {
                    'connected_before': None,
                    'connected_after': alert_date_min
                }
            }
        }]
        filter_form, filter_data = self._add_filter(user, alert_date_min)
        args = merge_with_filter_view(self, {})
        args['request'] = self.request
        objects = find_entities(user=user,
                                sort_on='last_connection',
                                filters=filters,
                                **args)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_users"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = self._get_title(index=index,
                                     len_result=len_result,
                                     user=user)
        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body, result = render_listing_objs(self.request, batch, user)
        values = {
            'bodies': result_body,
            'batch': batch,
            'filter_body': filter_body
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        result['css_links'] = filter_form['css_links']
        result['js_links'] = filter_form['js_links']
        return result
예제 #33
0
    def update(self):
        body = ''
        result = {}
        if self.isactive or self.params('on_demand') == 'load':
            current_user = get_current()
            validated = {
                'metadata_filter': {
                    'content_types': [self.content_type],
                    'states': ['active', 'published']
                }
            }
            novaideo_catalog = find_catalog('novaideo')
            organizations_index = novaideo_catalog['organizations']
            query = organizations_index.any([self.context.__oid__])
            objects = find_entities(user=current_user,
                                    filters=[validated],
                                    add_query=query)
            sort_url = self.request.resource_url(
                self.context,
                '@@index',
                query={'view_content_attr': self.content_id})
            objects, sort_body = sort_view_objects(self,
                                                   objects,
                                                   [self.content_type],
                                                   current_user,
                                                   sort_url=sort_url)
            url = self.request.resource_url(
                self.context,
                '@@index',
                query={'view_content_attr': self.content_id})
            batch = Batch(objects,
                          self.request,
                          url=url,
                          default_size=BATCH_DEFAULT_SIZE)
            batch.target = "#results-" + self.content_type
            self.title = _(self.title, mapping={'nb': batch.seqlen})
            result_body, result = render_listing_objs(
                self.request,
                batch,
                current_user,
                display_state=getattr(self, 'display_state', True))
            values = {
                'bodies': result_body,
                'batch': batch,
                'empty_message': self.empty_message,
                'empty_icon': self.empty_icon,
                'sort_body': sort_body
            }
            body = self.content(args=values, template=self.template)['body']

        item = self.adapt_item(body, self.viewid)
        item['isactive'] = getattr(self, 'isactive', False)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #34
0
    def update(self):
        current_date = datetime.datetime.combine(
            datetime.datetime.now(),
            datetime.time(0, 0, 0, tzinfo=pytz.UTC))
        alert_date_min = current_date - datetime.timedelta(
            days=INACTIVITY_DURATION)
        user = get_current()
        filters = [
            {'metadata_filter': {
                'content_types': ['person'],
                'states': ['active']
             },
             'temporal_filter': {
                 'negation': True,
                 'connected_date': {
                     'connected_before': None,
                     'connected_after': alert_date_min
                 }
             }}
        ]
        filter_form, filter_data = self._add_filter(user, alert_date_min)
        args = merge_with_filter_view(self, {})
        args['request'] = self.request
        objects = find_entities(
            user=user,
            sort_on='last_connection',
            filters=filters,
            **args)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_users"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = self._get_title(
            index=index, len_result=len_result, user=user)
        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body, result = render_listing_objs(
            self.request, batch, user)
        values = {'bodies': result_body,
                  'batch': batch,
                  'filter_body': filter_body}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        result['css_links'] = filter_form['css_links']
        result['js_links'] = filter_form['js_links']
        return result
예제 #35
0
    def update(self):
        body = ''
        result = {}
        if self.isactive or self.params('on_demand') == 'load':
            user = self.context
            current_user = get_current()
            objects = []
            if current_user is user:
                objects = list(
                    filter(lambda o: 'archived' not in o.state,
                           getattr(user, self.content_attr, [])))
            else:
                objects = list(
                    filter(
                        lambda o: can_access(current_user, o) and 'archived'
                        not in o.state, getattr(user, self.content_attr, [])))
            sort_url = self.request.resource_url(
                self.context,
                '@@index',
                query={'view_content_id': self.content_id})
            objects, sort_body = sort_view_objects(self,
                                                   objects,
                                                   [self.content_type],
                                                   user,
                                                   sort_url=sort_url)
            url = self.request.resource_url(
                self.context,
                '@@index',
                query={'view_content_id': self.content_id})
            batch = Batch(objects,
                          self.request,
                          url=url,
                          default_size=BATCH_DEFAULT_SIZE)
            batch.target = "#results-" + self.content_id
            self.title = _(self.title, mapping={'nb': batch.seqlen})
            result_body, result = render_listing_objs(
                self.request,
                batch,
                current_user,
                display_state=getattr(self, 'display_state', True))
            values = {
                'bodies': result_body,
                'batch': batch,
                'empty_message': self.empty_message,
                'empty_icon': self.empty_icon,
                'sort_body': sort_body
            }
            body = self.content(args=values, template=self.template)['body']

        item = self.adapt_item(body, self.viewid)
        item['isactive'] = getattr(self, 'isactive', False)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #36
0
    def update(self):
        self.execute(None)
        user = get_current()
        filter_form, filter_data = self._add_filter(user)
        filters = [
            {'metadata_filter': {
                'negation': True,
                'states': ['examined']
            }},
            {'metadata_filter': {
                'content_types': ['idea'],
                'states': ['published']
            }}
        ]
        args = {}
        args = merge_with_filter_view(self, args)
        args['request'] = self.request
        objects = find_entities(user=user,
                                filters=filters,
                                **args)
        objects, sort_body = sort_view_objects(
            self, objects, ['idea'], user, 'nbsupport')
        url = self.request.resource_url(self.context, 'seeideastoexamine')
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body, result = render_listing_objs(
            self.request, batch, user)
        if filter_form:
            result = merge_dicts(
                {'css_links': filter_form['css_links'],
                'js_links': filter_form['js_links']
                }, result)

        values = {'bodies': result_body,
                  'batch': batch,
                  'filter_body': filter_body,
                  'sort_body': sort_body
                  }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #37
0
    def update(self):
        self.execute(None)
        user = get_current()
        is_manager = has_role(user=user, role=('PortalManager', ))
        filters = [{'metadata_filter': {'content_types': ['person']}}]
        filter_form, filter_data = self._add_filter(user, is_manager)
        args = merge_with_filter_view(self, {})
        args['request'] = self.request
        objects = find_entities(user=user, filters=filters, **args)
        objects, sort_body = sort_view_objects(self, objects, ['person'], user)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_users"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = self._get_title(index=index,
                                     len_result=len_result,
                                     user=user)
        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body, result = render_listing_objs(self.request, batch, user)
        novaideo_catalog = find_catalog('novaideo')
        last_connection_index = novaideo_catalog['last_connection']
        current_date = datetime.datetime.combine(
            datetime.datetime.now(), datetime.time(0, 0, 0, tzinfo=pytz.UTC))
        inactive_users = find_users(last_connection_index, current_date,
                                    (INACTIVITY_DURATION, None))
        if filter_form:
            result = merge_dicts(
                {
                    'css_links': filter_form['css_links'],
                    'js_links': filter_form['js_links']
                }, result)

        values = {
            'bodies': result_body,
            'batch': batch,
            'is_manager': is_manager,
            'inactivity_duration': INACTIVITY_DURATION,
            'inactive_users': inactive_users.__len__(),
            'filter_body': filter_body,
            'sort_body': sort_body
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #38
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = [proposal for proposal
                   in self.context.related_proposals
                   if proposal.working_group and
                   'archived' not in proposal.state and
                   'censored' not in proposal.state and
                   can_access(user, proposal)]
        objects = sorted(
            objects,
            key=lambda e: getattr(e, 'modified_at'),
            reverse=True)
        is_small = True
        current_is_small = self.params('is_small')
        if current_is_small is not None:
            current_is_small = current_is_small.lower()
            is_small = current_is_small == 'true'
        elif self.parent or self.request.view_name == self.name:
            is_small = False

        url = self.request.resource_url(
            self.context, self.name, query={'is_small': str(is_small)})
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_idea_working_groups" + \
            str(self.context.__oid__) + \
            (is_small and 'is_small' or '')
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(WG_MESSAGES[index], mapping={'number': len_result})
        result = {}
        if is_small:
            result_body = render_small_listing_objs(
                self.request, batch, user)
        else:
            result_body, result = render_listing_objs(
                self.request, batch, user)

        values = {
            'bodies': result_body,
            'batch': batch,
            'empty_message': _("No working group created"),
            'empty_icon': 'novaideo-icon icon-wg'
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #39
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = [
            proposal for proposal in self.context.related_proposals
            if proposal.working_group and 'archived' not in proposal.state and
            'censored' not in proposal.state and can_access(user, proposal)
        ]
        objects = sorted(objects,
                         key=lambda e: getattr(e, 'modified_at'),
                         reverse=True)
        is_small = True
        current_is_small = self.params('is_small')
        if current_is_small is not None:
            current_is_small = current_is_small.lower()
            is_small = current_is_small == 'true'
        elif self.parent or self.request.view_name == self.name:
            is_small = False

        url = self.request.resource_url(self.context,
                                        self.name,
                                        query={'is_small': str(is_small)})
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_idea_working_groups" + \
            str(self.context.__oid__) + \
            (is_small and 'is_small' or '')
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(WG_MESSAGES[index], mapping={'number': len_result})
        result = {}
        if is_small:
            result_body = render_small_listing_objs(self.request, batch, user)
        else:
            result_body, result = render_listing_objs(self.request, batch,
                                                      user)

        values = {
            'bodies': result_body,
            'batch': batch,
            'empty_message': _("No working group created"),
            'empty_icon': 'novaideo-icon icon-wg'
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #40
0
    def find_entities_by_artist(self):
        user = get_current()
        artist_id = self.params('artist')
        if not artist_id:
            objects = []
        else:
            artist = get_obj(int(artist_id), None)
            if not artist:
                objects = []
            else:
                objects = find_entities(
                    user=user,
                    metadata_filter={'states': ['published']},
                    contribution_filter={'artists_ids': [artist]},
                    sort_on='release_date', reverse=True,
                    include_site=True)

        batch = Batch(objects,
                      self.request,
                      url=self.request.url,
                      default_size=core.BATCH_DEFAULT_SIZE)
        batch.target = "#results"
        len_result = batch.seqlen
        result_body = []
        for obj in batch:
            object_values = {'object': obj,
                             'current_user': user,
                             'state': None}
            body = self.content(args=object_values,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        values = {
                'bodies': result_body,
                'batch': batch,
                 }
        body = self.content(args=values, template=self.template)['body']
        len_result = len(objects)
        index = str(len_result)
        if len_result > 1:
            index = '*'

        title = _(CONTENTS_MESSAGES[index],
                  mapping={'nember': len_result})
        values = {
                'body': body,
                'title': title
                 }
        body = self.content(args=values,
                            template=self.wrapper_template)['body']
        return {'body': body}
예제 #41
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = [
            event for event in self.context.events
            if 'published' in event.state and can_access(user, event)
        ]
        objects = sorted(objects,
                         key=lambda e: getattr(e, 'modified_at'),
                         reverse=True)
        is_small = True
        current_is_small = self.params('is_small')
        if current_is_small is not None:
            current_is_small = current_is_small.lower()
            is_small = current_is_small == 'true'
        elif self.parent or self.request.view_name == self.name:
            is_small = False

        url = self.request.resource_url(self.context,
                                        self.name,
                                        query={'is_small': str(is_small)})
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_eventobject_events" + \
            str(self.context.__oid__) + \
            (is_small and 'is_small' or '')
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(EVENTS_MESSAGES[index], mapping={'number': len_result})
        result = {}
        if is_small:
            result_body = render_small_listing_objs(self.request, batch, user)
        else:
            result_body, result = render_listing_objs(self.request, batch,
                                                      user)

        values = {
            'bodies': result_body,
            'batch': batch,
            'empty_message': _("No organized event"),
            'empty_icon': 'glyphicon glyphicon-calendar'
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #42
0
    def find_entities_by_artist(self):
        user = get_current()
        artist_id = self.params('artist')
        if not artist_id:
            objects = []
        else:
            artist = get_obj(int(artist_id), None)
            if not artist:
                objects = []
            else:
                objects = find_entities(
                    user=user,
                    metadata_filter={'states': ['published']},
                    contribution_filter={'artists_ids': [artist]},
                    sort_on='release_date',
                    reverse=True,
                    include_site=True)

        batch = Batch(objects,
                      self.request,
                      url=self.request.url,
                      default_size=core.BATCH_DEFAULT_SIZE)
        batch.target = "#results"
        len_result = batch.seqlen
        result_body = []
        for obj in batch:
            object_values = {
                'object': obj,
                'current_user': user,
                'state': None
            }
            body = self.content(args=object_values,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        values = {
            'bodies': result_body,
            'batch': batch,
        }
        body = self.content(args=values, template=self.template)['body']
        len_result = len(objects)
        index = str(len_result)
        if len_result > 1:
            index = '*'

        title = _(CONTENTS_MESSAGES[index], mapping={'nember': len_result})
        values = {'body': body, 'title': title}
        body = self.content(args=values,
                            template=self.wrapper_template)['body']
        return {'body': body}
예제 #43
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = [content for content in
                   self.context.related_ideas
                   if can_access(user, content)]
        objects = sorted(
            objects,
            key=lambda e: getattr(e, 'modified_at'),
            reverse=True)
        is_small = True
        current_is_small = self.params('is_small')
        if current_is_small is not None:
            current_is_small = current_is_small.lower()
            is_small = current_is_small == 'true'
        elif self.parent or self.request.view_name == self.name:
            is_small = False

        url = self.request.resource_url(
            self.context, self.name, query={'is_small': str(is_small)})
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_related_ideas" + \
            str(self.context.__oid__) + \
            (is_small and 'is_small' or '')
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'
        result = {}
        if is_small:
            result_body = render_small_listing_objs(
                self.request, batch, user)
        else:
            result_body, result = render_listing_objs(
                self.request, batch, user)

        self.title = _(ADDIDEAS_MESSAGES[index],
                       mapping={'number': len_result})
        values = {
            'bodies': result_body,
            'batch': batch
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #44
0
    def update(self):
        self.execute(None)
        try:
            navbars = generate_navbars(self, self.context, self.request)
        except ObjectRemovedException:
            return HTTPFound(self.request.resource_url(getSite(), ''))

        user = self.context
        current_user = get_current()
        objects = self.context.members
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        result_body = []
        result = {}
        for obj in batch:
            object_values = {
                'object': obj,
                'current_user': current_user,
                'state': None
            }
            body = self.content(args=object_values,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        values = {'bodies': result_body, 'length': len_result, 'batch': batch}
        contents_body = self.content(
            args=values, template=SearchResultView.template)['body']

        values = {
            'contents': (result_body and contents_body) or None,
            'proposals':
            None,
            'user':
            self.context,
            'state':
            get_states_mapping(current_user, user,
                               getattr(user, 'state_or_none', [None])[0]),
            'navbar_body':
            navbars['navbar_body']
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        item['messages'] = navbars['messages']
        item['isactive'] = navbars['isactive']
        result.update(navbars['resources'])
        result['coordinates'] = {self.coordinates: [item]}
        return result
    def update(self):
        self.execute(None)
        user = get_current()
        filter_form, filter_data = self._add_filter(user)
        content_types = list(core.SEARCHABLE_CONTENTS.keys())
        args = {'metadata_filter': {'content_types': content_types}}
        args = merge_with_filter_view(self, args)
        args['request'] = self.request
        objects = find_entities(user=user,
                                sort_on='release_date', reverse=True,
                                include_site=True,
                                **args)
        url = self.request.resource_url(self.context, 'contentstomoderate')
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=core.BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'nember': len_result})
        filter_data['filter_message'] = self.title
        filter_body = self.filter_instance.get_body(filter_data)
        result_body = []
        for obj in batch:
            render_dict = {'object': obj,
                           'current_user': user,
                           'state': get_states_mapping(user, obj,
                                   getattr(obj, 'state_or_none', [None])[0])}
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        result = {}
        values = {'bodies': result_body,
                  'batch': batch,
                  'filter_body': filter_body}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        result['css_links'] = filter_form['css_links']
        result['js_links'] = filter_form['js_links']
        return result
예제 #46
0
    def update(self):
        body = ''
        result = {}
        if self.isactive or self.params('on_demand') == 'load':
            current_user = get_current()
            validated = {
                'metadata_filter':
                    {'content_types': [self.content_type],
                     'states': ['active', 'published']}
            }
            novaideo_catalog = find_catalog('novaideo')
            organizations_index = novaideo_catalog['organizations']
            query = organizations_index.any([self.context.__oid__])
            objects = find_entities(
                user=current_user,
                filters=[validated],
                add_query=query)
            sort_url = self.request.resource_url(
                self.context, '@@index',
                query={'view_content_attr': self.content_id})
            objects, sort_body = sort_view_objects(
                self, objects, [self.content_type], current_user,
                sort_url=sort_url)
            url = self.request.resource_url(
                self.context, '@@index',
                query={'view_content_attr': self.content_id})
            batch = Batch(objects,
                          self.request,
                          url=url,
                          default_size=BATCH_DEFAULT_SIZE)
            batch.target = "#results-" + self.content_type
            self.title = _(self.title, mapping={'nb': batch.seqlen})
            result_body, result = render_listing_objs(
                self.request, batch, current_user,
                display_state=getattr(self, 'display_state', True))
            values = {'bodies': result_body,
                      'batch': batch,
                      'empty_message': self.empty_message,
                      'empty_icon': self.empty_icon,
                      'sort_body': sort_body}
            body = self.content(args=values, template=self.template)['body']

        item = self.adapt_item(body, self.viewid)
        item['isactive'] = getattr(self, 'isactive', False)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #47
0
파일: search.py 프로젝트: jean/nova-ideo
    def update(self):
        user = get_current()
        formviewinstance = SearchView(self.context, self.request)
        formviewinstance.postedform = self.request.POST
        appstruct = formviewinstance.get_appstruct()
        content_types = appstruct['content_types']
        text = appstruct['text_to_search']
        objects = search(text, content_types, user)
        url = self.request.resource_url(self.context, '', 
                                        query={'content_types':content_types,
                                               'text_to_search':appstruct['text_to_search']})
        batch = Batch(objects, 
                      self.request, 
                      url=url, 
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index] , 
                       mapping={'nember': len_result})
        result_body = []
        for obj in batch:
            object_values = {'object':obj, 
                             'current_user': user, 
                             'state': get_states_mapping(user, obj, 
                                   getattr(obj, 'state', [None])[0])}
            body = self.content(result=object_values,
                                template=obj.result_template)['body']
            result_body.append(body)

        result = {}
        values = {
                'bodies': result_body,
                'length': len_result,
                'batch': batch
                 }
        body = self.content(result=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates:[item]}
        result  = merge_dicts(self.requirements_copy, result)
        return result
예제 #48
0
    def update(self):
        user = get_current()
        site = get_site_folder(True, self.request)
        objects = []
        if hasattr(user, 'get_alerts'):
            objects = user.get_alerts(
                user.all_alerts,
                site=site)

        now = datetime.datetime.now(tz=pytz.UTC)
        objects = sorted(
            objects,
            key=lambda e: getattr(e, 'modified_at', now),
            reverse=True)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_alerts"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'nember': len_result})
        result_body = []
        for obj in batch:
            render_dict = {
                'object': obj,
                'current_user': user
            }
            body = self.content(args=render_dict,
                                template=obj.get_templates()['default'])['body']
            result_body.append(body)

        result = {}
        values = {'bodies': result_body,
                  'batch': batch}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        self.execute(None)
        return result
예제 #49
0
    def update(self):
        self.execute(None)
        try:
            navbars = generate_navbars(self, self.context, self.request)
        except ObjectRemovedException:
            return HTTPFound(self.request.resource_url(getSite(), ''))

        user = self.context
        current_user = get_current()
        objects = self.context.members
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_contents"
        len_result = batch.seqlen
        result_body = []
        result = {}
        for obj in batch:
            object_values = {'object': obj,
                             'current_user': current_user,
                             'state': None
                             }
            body = self.content(args=object_values,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        values = {'bodies': result_body,
                  'length': len_result,
                  'batch': batch
                  }
        contents_body = self.content(args=values,
                                     template=SearchResultView.template)['body']

        values = {'contents': (result_body and contents_body) or None,
                  'proposals': None,
                  'user': self.context,
                  'state': get_states_mapping(current_user, user,
                                getattr(user, 'state_or_none', [None])[0]),
                  'navbar_body': navbars['navbar_body']}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        item['messages'] = navbars['messages']
        item['isactive'] = navbars['isactive']
        result.update(navbars['resources'])
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #50
0
    def update(self):
        body = ''
        result = {}
        if self.isactive or self.params('on_demand') == 'load':
            user = self.context
            current_user = get_current()
            objects = []
            if current_user is user:
                objects = list(filter(lambda o: 'archived' not in o.state,
                                 getattr(user, self.content_attr, [])))
            else:
                objects = list(filter(lambda o: can_access(current_user, o) and
                                           'archived' not in o.state,
                                 getattr(user, self.content_attr, [])))
            sort_url = self.request.resource_url(
                self.context, '@@index',
                query={'view_content_id': self.content_id})
            objects, sort_body = sort_view_objects(
                self, objects, [self.content_type], user,
                sort_url=sort_url)
            url = self.request.resource_url(
                self.context, '@@index',
                query={'view_content_id': self.content_id})
            batch = Batch(objects,
                          self.request,
                          url=url,
                          default_size=BATCH_DEFAULT_SIZE)
            batch.target = "#results-" + self.content_id
            self.title = _(self.title, mapping={'nb': batch.seqlen})
            result_body, result = render_listing_objs(
                self.request, batch, current_user,
                display_state=getattr(self, 'display_state', True))
            values = {'bodies': result_body,
                      'batch': batch,
                      'empty_message': self.empty_message,
                      'empty_icon': self.empty_icon,
                      'sort_body': sort_body}
            body = self.content(args=values, template=self.template)['body']

        item = self.adapt_item(body, self.viewid)
        item['isactive'] = getattr(self, 'isactive', False)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #51
0
    def update(self):
        user = get_current()
        objects = list(getattr(user, 'alerts', []))
        len_result = len(objects)
        objects.extend(getattr(user, 'old_alerts', []))
        now = datetime.datetime.now(tz=pytz.UTC)
        objects = sorted(
            objects,
            key=lambda e: getattr(e, 'modified_at', now),
            reverse=True)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_alerts"
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        result_body = []
        for obj in batch:
            render_dict = {
                'object': obj,
                'current_user': user
            }
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)
        
        addon = self.content(
            args={'user': user}, template=self.addon_template)['body'] if result_body else ''
        result = {}
        values = {'bodies': result_body,
                  'batch': batch,
                  'addon': addon}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        self.execute(None)
        return result
예제 #52
0
    def update(self):
        self.execute(None) 
        user = get_current()
        objects = [o for o in getattr(user, 'selections', []) \
                   if not('archived' in o.state)]
        objects = sorted(objects, 
                         key=lambda e: getattr(e, 'modified_at', 
                                               datetime.datetime.today()),
                         reverse=True)
        batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_selections"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(MY_CONTENTS_MESSAGES[index], 
                       mapping={'nember': len_result})
        result_body = []
        for obj in batch:
            state = None
            if getattr(obj, 'state', []):
                state = obj.state[0]
                
            object_values = {'object': obj, 
                             'current_user': user, 
                             'state': get_states_mapping(user, obj, state)}
            body = self.content(result=object_values, 
                                template=obj.result_template)['body']
            result_body.append(body)

        result = {}
        values = {
                'bodies': result_body,
                'length': len_result,
                'batch': batch,
               }
        body = self.content(result=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates:[item]}
        return result
예제 #53
0
    def update(self):
        self.execute(None)
        user = get_current()
        objects = [member for member
                   in self.context.invited_users
                   if can_access(user, member)]
        objects = sorted(
            objects,
            key=lambda e: getattr(e, 'modified_at'),
            reverse=True)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects, self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_challenge_members"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(WG_MESSAGES[index], mapping={'number': len_result})
        result = {}
        # if included in another view
        if self.parent or self.request.view_name == self.name:
            result_body, result = render_listing_objs(
                self.request, batch, user)
        else:
            result_body = render_small_listing_objs(
                self.request, batch, user)

        values = {
            'bodies': result_body,
            'batch': batch,
            'empty_message': _("No participant"),
            'empty_icon': 'ion-person-stalker'
        }
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        return result
예제 #54
0
 def auditing(self):
     log = self.get_auditlog(self.context)
     log_exists = False
     results = []
     if log is not None:
         log_exists = True
         for gen, idx, event in log:
             tz = self.request.user.timezone
             dt = datetime.datetime.fromtimestamp(event.timestamp, tz)
             time = dt.strftime('%Y-%m-%d %H:%M:%S %Z')
             results.insert(0, (gen, idx, time, event))
     batch = Batch(results, self.request, default_size=100)
     return {'batch': batch, 'results': results, 'log_exists': log_exists}
예제 #55
0
    def update(self):
        user = get_current()
        site = get_site_folder(True, self.request)
        objects = []
        if hasattr(user, 'get_alerts'):
            objects = user.get_alerts(user.all_alerts, site=site)

        now = datetime.datetime.now(tz=pytz.UTC)
        objects = sorted(objects,
                         key=lambda e: getattr(e, 'modified_at', now),
                         reverse=True)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_alerts"
        len_result = batch.seqlen
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'nember': len_result})
        result_body = []
        for obj in batch:
            render_dict = {'object': obj, 'current_user': user}
            body = self.content(
                args=render_dict,
                template=obj.get_templates()['default'])['body']
            result_body.append(body)

        result = {}
        values = {'bodies': result_body, 'batch': batch}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        self.execute(None)
        return result
예제 #56
0
 def update(self):
     self.execute(None)
     user = get_current()
     objects = find_entities(user=user,
                             interfaces=[IFile],
                             sort_on='release_date',
                             reverse=True)
     batch = Batch(objects, self.request, default_size=BATCH_DEFAULT_SIZE)
     batch.target = "#results_files"
     len_result = batch.seqlen
     is_portalmanager = has_role(user=user, role=('PortalManager', )),
     result_body, result = render_listing_objs(
         self.request, batch, user, is_portalmanager=is_portalmanager)
     values = {
         'bodies': result_body,
         'length': len_result,
         'batch': batch,
     }
     body = self.content(args=values, template=self.template)['body']
     item = self.adapt_item(body, self.viewid)
     result['coordinates'] = {self.coordinates: [item]}
     return result
예제 #57
0
    def update(self):
        user = get_current()
        objects = list(getattr(user, 'alerts', []))
        len_result = len(objects)
        objects.extend(getattr(user, 'old_alerts', []))
        now = datetime.datetime.now(tz=pytz.UTC)
        objects = sorted(objects,
                         key=lambda e: getattr(e, 'modified_at', now),
                         reverse=True)
        url = self.request.resource_url(self.context, self.name)
        batch = Batch(objects,
                      self.request,
                      url=url,
                      default_size=BATCH_DEFAULT_SIZE)
        batch.target = "#results_alerts"
        index = str(len_result)
        if len_result > 1:
            index = '*'

        self.title = _(CONTENTS_MESSAGES[index],
                       mapping={'number': len_result})
        result_body = []
        for obj in batch:
            render_dict = {'object': obj, 'current_user': user}
            body = self.content(args=render_dict,
                                template=obj.templates['default'])['body']
            result_body.append(body)

        addon = self.content(args={
            'user': user
        }, template=self.addon_template)['body'] if result_body else ''
        result = {}
        values = {'bodies': result_body, 'batch': batch, 'addon': addon}
        body = self.content(args=values, template=self.template)['body']
        item = self.adapt_item(body, self.viewid)
        result['coordinates'] = {self.coordinates: [item]}
        self.execute(None)
        return result