Esempio n. 1
0
        def get(self, request, *args, **kwargs):
            org = self.request.org
            user = self.request.user
            page = int(self.request.GET.get('page', 1))

            search = self.derive_search()
            items = Outgoing.search_replies(org, user, search)

            paginator = LazyPaginator(items, 50)
            outgoing = paginator.page(page)
            has_more = paginator.num_pages > page

            def as_json(msg):
                delay = (msg.created_on - msg.reply_to.created_on).total_seconds()
                obj = msg.as_json()
                obj.update({
                    'reply_to': {
                        'text': msg.reply_to.text,
                        'flagged': msg.reply_to.is_flagged,
                        'labels': [l.as_json(full=False) for l in msg.reply_to.labels.all()],
                    },
                    'response': {
                        'delay': timesince(msg.reply_to.created_on, now=msg.created_on),
                        'warning': delay > RESPONSE_DELAY_WARN_SECONDS
                    }
                })
                return obj

            return JsonResponse({'results': [as_json(o) for o in outgoing], 'has_more': has_more}, encoder=JSONEncoder)
Esempio n. 2
0
        def get_context_data(self, **kwargs):
            context = super(MessageCRUDL.Search, self).get_context_data(**kwargs)

            org = self.request.org
            user = self.request.user
            page = int(self.request.GET.get('page', 1))

            search = self.derive_search()

            # this is a refresh of messages
            if self.request.GET.get('last_refresh', None):
                new_messages = Message.search(org, user, search)

                search['last_refresh'] = self.request.GET['last_refresh']

                updated_messages = Message.search(org, user, search)

                context['object_list'] = list(new_messages) + list(set(updated_messages) - set(new_messages))

                context['has_more'] = False
                return context

            messages = Message.search(org, user, search)
            paginator = LazyPaginator(messages, per_page=50)

            context['object_list'] = paginator.page(page)
            context['has_more'] = paginator.num_pages > page
            return context
Esempio n. 3
0
        def get_context_data(self, **kwargs):
            context = super(MessageCRUDL.Search,
                            self).get_context_data(**kwargs)

            org = self.request.org
            user = self.request.user
            page = int(self.request.GET.get("page", 1))
            last_refresh = self.request.GET.get("last_refresh")

            search = self.derive_search()

            # this is a refresh of new and modified messages
            if last_refresh:
                search["last_refresh"] = last_refresh

                messages = Message.search(org, user, search)

                # don't use paging for these messages
                context["object_list"] = list(messages)
                context["has_more"] = False
                return context

            messages = Message.search(org, user, search)
            paginator = LazyPaginator(messages, per_page=50)

            context["object_list"] = paginator.page(page)
            context["has_more"] = paginator.num_pages > page
            return context
Esempio n. 4
0
        def get(self, request, *args, **kwargs):
            org = self.request.org
            user = self.request.user
            page = int(self.request.GET.get("page", 1))

            search = self.derive_search()
            items = Outgoing.search_replies(org, user, search).exclude(reply_to=None)

            paginator = LazyPaginator(items, 50)
            outgoing = paginator.page(page)
            has_more = paginator.num_pages > page

            def as_json(msg):
                delay = (msg.created_on - msg.reply_to.created_on).total_seconds()
                obj = msg.as_json()
                obj.update(
                    {
                        "reply_to": {
                            "text": msg.reply_to.text,
                            "flagged": msg.reply_to.is_flagged,
                            "labels": [l.as_json(full=False) for l in msg.reply_to.labels.all()],
                        },
                        "response": {
                            "delay": timesince(msg.reply_to.created_on, now=msg.created_on),
                            "warning": delay > RESPONSE_DELAY_WARN_SECONDS,
                        },
                    }
                )
                return obj

            return JsonResponse({"results": [as_json(o) for o in outgoing], "has_more": has_more}, encoder=JSONEncoder)
Esempio n. 5
0
        def get_context_data(self, **kwargs):
            context = super(CaseCRUDL.Search, self).get_context_data(**kwargs)

            org = self.request.org
            user = self.request.user
            page = int(self.request.GET.get("page", 1))

            search = self.derive_search()
            cases = Case.search(org, user, search)
            paginator = LazyPaginator(cases, 50)

            context["object_list"] = paginator.page(page)
            context["has_more"] = paginator.num_pages > page
            return context
Esempio n. 6
0
        def get_context_data(self, **kwargs):
            context = super(OutgoingCRUDL.Search, self).get_context_data(**kwargs)

            org = self.request.org
            user = self.request.user
            page = int(self.request.GET.get('page', 1))

            search = self.derive_search()
            messages = Outgoing.search(org, user, search)
            paginator = LazyPaginator(messages, per_page=50)

            context['object_list'] = paginator.page(page)
            context['has_more'] = paginator.num_pages > page
            return context