コード例 #1
0
    def obj_create(self, bundle, request=None, **kwargs):
        val = None
        try:
            bundle.data['date'] = datetime.datetime.strptime(
                bundle.data['date']['_d'], '%Y-%m-%dT%H:%M:%S.%fZ')
            val = super(ChatMessageResource, self).obj_create(
                bundle, request, **kwargs)

            notify_message(chat=val.obj)
        except Exception, e:
            logger.exception(e)
コード例 #2
0
    def obj_create(self, bundle, request=None, **kwargs):
        val = None
        try:
            bundle.data['date'] = datetime.datetime.strptime(
                bundle.data['date']['_d'], '%Y-%m-%dT%H:%M:%S.%fZ')
            val = super(ChatMessageResource,
                        self).obj_create(bundle, request, **kwargs)

            notify_message(chat=val.obj)
        except Exception, e:
            logger.exception(e)
コード例 #3
0
    def obj_create(self, bundle, request=None, **kwargs):
        url = bundle.data['url']
        domain = url_domain(url)

        bundle.data['domain'] = domain

        title = bundle.data['title']
        start_time = bundle.data['start_time']
        start_event = bundle.data['start_event']
        end_time = bundle.data['end_time']
        end_event = bundle.data['end_event']
        favicon_url = bundle.data.get('favIconUrl')
        bundle.data['favicon_url'] = favicon_url
        src = bundle.data['src']

        end_time = datetime.datetime.strptime(
            end_time, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=pytz.utc)
        start_time = datetime.datetime.strptime(
            start_time, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=pytz.utc)

        message = bundle.data.get('message')

        if message and message.strip() == '':
            message = None

        if message:
            bundle.data.pop('message', None)

        try:
            exists = EyeHistory.objects.filter(user=request.user, url=url,
                                               title=title, src=src, favicon_url=favicon_url,
                                               start_time__gt=start_time -
                                               datetime.timedelta(minutes=1),
                                               start_event=start_event)
            if exists.count() > 0:
                eye_his = exists[0]
                eye_his.end_time = end_time
                eye_his.end_event = end_event
                elapsed_time = end_time - start_time
                eye_his.total_time = int(round(
                    (elapsed_time.microseconds / 1.0E3) + (elapsed_time.seconds * 1000) + (elapsed_time.days * 8.64E7)))
                eye_his.humanize_time = humanize_time(elapsed_time)
                eye_his.save()
                if message:
                    eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                        eyehistory=eye_his, message=message)
                    notify_message(message=eye_message)
            else:
                # save_raw_eyehistory(request.user, url, title, start_event, end_event, start_time, end_time, src, domain, favicon_url)
                dup_histories = EyeHistory.objects.filter(
                    user=request.user, url=url, title=title, end_time__gt=start_time - datetime.timedelta(minutes=5))
                if dup_histories.count() > 0:
                    obj = merge_histories(dup_histories, end_time, end_event)
                    if message:
                        eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                            eyehistory=obj, message=message)
                        notify_message(message=eye_message)
                else:
                    bundle_res = super(EyeHistoryResource, self).obj_create(
                        bundle, request, user=request.user, **kwargs)
                    check_bumps(request.user, start_time, end_time, url)

                    if message:
                        eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                            eyehistory=bundle_res.obj, message=message)
                        notify_message(message=eye_message)

                    return bundle_res
        except MultipleObjectsReturned as e:
            logger.info(e)
            # multiple items created, delete duplicates
            call_command('remove_duplicate_history')

        return bundle
コード例 #4
0
    def obj_create(self, bundle, request=None, **kwargs):
        url = bundle.data['url']
        domain = url_domain(url)

        bundle.data['domain'] = domain

        title = bundle.data['title']
        start_time = bundle.data['start_time']
        start_event = bundle.data['start_event']
        end_time = bundle.data['end_time']
        end_event = bundle.data['end_event']
        favicon_url = bundle.data.get('favIconUrl')
        bundle.data['favicon_url'] = favicon_url
        src = bundle.data['src']

        end_time = datetime.datetime.strptime(
            end_time, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=pytz.utc)
        start_time = datetime.datetime.strptime(
            start_time, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=pytz.utc)

        message = bundle.data.get('message')

        if message and message.strip() == '':
            message = None

        if message:
            bundle.data.pop('message', None)

        try:
            exists = EyeHistory.objects.filter(user=request.user,
                                               url=url,
                                               title=title,
                                               src=src,
                                               favicon_url=favicon_url,
                                               start_time__gt=start_time -
                                               datetime.timedelta(minutes=1),
                                               start_event=start_event)
            if exists.count() > 0:
                eye_his = exists[0]
                eye_his.end_time = end_time
                eye_his.end_event = end_event
                elapsed_time = end_time - start_time
                eye_his.total_time = int(
                    round((elapsed_time.microseconds / 1.0E3) +
                          (elapsed_time.seconds * 1000) +
                          (elapsed_time.days * 8.64E7)))
                eye_his.humanize_time = humanize_time(elapsed_time)
                eye_his.save()
                if message:
                    eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                        eyehistory=eye_his, message=message)
                    notify_message(message=eye_message)
            else:
                # save_raw_eyehistory(request.user, url, title, start_event, end_event, start_time, end_time, src, domain, favicon_url)
                dup_histories = EyeHistory.objects.filter(
                    user=request.user,
                    url=url,
                    title=title,
                    end_time__gt=start_time - datetime.timedelta(minutes=5))
                if dup_histories.count() > 0:
                    obj = merge_histories(dup_histories, end_time, end_event)
                    if message:
                        eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                            eyehistory=obj, message=message)
                        notify_message(message=eye_message)
                else:
                    bundle_res = super(EyeHistoryResource,
                                       self).obj_create(bundle,
                                                        request,
                                                        user=request.user,
                                                        **kwargs)
                    check_bumps(request.user, start_time, end_time, url)

                    if message:
                        eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                            eyehistory=bundle_res.obj, message=message)
                        notify_message(message=eye_message)

                    return bundle_res
        except MultipleObjectsReturned as e:
            logger.info(e)
            # multiple items created, delete duplicates
            call_command('remove_duplicate_history')

        return bundle
コード例 #5
0
ファイル: resources.py プロジェクト: kifleW/eyebrowse-server
    def obj_create(self, bundle, request=None, **kwargs):
        url = bundle.data['url']
        domain = url_domain(url)

        bundle.data['domain'] = domain

        title = bundle.data.get('title')
        start_time = bundle.data.get('start_time')
        start_event = bundle.data.get('start_event')
        end_time = bundle.data.get('end_time')
        end_event = bundle.data.get('end_event')
        favicon_url = bundle.data.get('favIconUrl')
        bundle.data['favicon_url'] = favicon_url
        src = bundle.data.get('src')
        tags = bundle.data.get('tags')

        if tags:
            tags = json.loads(tags);

        if end_time and start_time:
            end_time = datetime.datetime.strptime(
                end_time, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=pytz.utc)
            start_time = datetime.datetime.strptime(
                start_time, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=pytz.utc)
        else:
            end_time = datetime.datetime.now().replace(tzinfo=pytz.utc)
            start_time = datetime.datetime.now().replace(tzinfo=pytz.utc)

        message = bundle.data.get('message')
        highlight = bundle.data.get('highlight')
        parent_comment = bundle.data.get('parent_comment')

        if message and message.strip() == '':
            message = None

        if message:
            bundle.data.pop('message', None)
        if highlight:
            bundle.data.pop('highlight', None)
        if parent_comment:
            bundle.data.pop('parent_comment', None)

        try:
            exists = EyeHistory.objects.filter(user=request.user, url=url,
                                               title=title, src=src, favicon_url=favicon_url,
                                               start_time__gt=start_time -
                                               datetime.timedelta(minutes=1),
                                               start_event=start_event)
            if exists.count() > 0:
                eye_his = exists[0]
                eye_his.end_time = end_time
                eye_his.end_event = end_event
                elapsed_time = end_time - start_time
                eye_his.total_time = int(round(
                    (elapsed_time.microseconds / 1.0E3) + (elapsed_time.seconds * 1000) + (elapsed_time.days * 8.64E7)))
                eye_his.humanize_time = humanize_time(elapsed_time)
                eye_his.save()
                if message:
                    eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                        eyehistory=eye_his, message=message)
                    notify_message(message=eye_message)
            else:
                # save_raw_eyehistory(request.user, url, title, start_event, end_event, start_time, end_time, src, domain, favicon_url)
                dup_histories = EyeHistory.objects.filter(
                    user=request.user, url=url, title=title, end_time__gt=start_time - datetime.timedelta(minutes=5))
                if dup_histories.count() > 0:
                    obj = merge_histories(dup_histories, end_time, end_event)
                    if message:
                        eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                            eyehistory=obj, message=message)
                        notify_message(message=eye_message)
                else:
                    bundle_res = super(EyeHistoryResource, self).obj_create(
                        bundle, request, user=request.user, **kwargs)
                    check_bumps(request.user, start_time, end_time, url)
                    if message:
                        eye_message = None
                        if parent_comment:
                            h = Highlight.objects.get(id=highlight)
                            eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                                eyehistory=bundle_res.obj, message=message, highlight=h, parent_comment=parent_comment)
                        elif highlight:
                            h = Highlight.objects.get(id=highlight)
                            eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                                eyehistory=bundle_res.obj, message=message, highlight=h)
                        else:
                            eye_message, _ = EyeHistoryMessage.objects.get_or_create(
                                eyehistory=bundle_res.obj, message=message)

                        if tags:
                            for tag in tags:
                                if len(Tag.objects.filter(comment=eye_message, common_tag__name=tag)) == 0:
                                    try:
                                        common_tag = CommonTag.objects.get(name=tag)
                                        vt = Tag(
                                            common_tag=common_tag,
                                            user=request.user,
                                            comment=eye_message,
                                        )
                                        vt.save()
                                    except CommonTag.DoesNotExist:
                                        pass


                        notify_message(message=eye_message)
                    return bundle_res
        except MultipleObjectsReturned as e:
            logger.info(e)
            # multiple items created, delete duplicates
            call_command('remove_duplicate_history')

        return bundle