Ejemplo n.º 1
0
    def create(self, account_id, user_id, revision_id, resource_type,
               resource_id, action_id, resource_title, resource_category):
        """ Create a redis-hash and then addit to a redis-lits"""
        if settings.DEBUG:
            logger.info('Create ActivityStreamDAO %d %s' %
                        (action_id, resource_title))
        c = Cache(db=settings.CACHE_DATABASES['activity_resources'])

        timeformat = "%s %s %s %s" % (ugettext('APP-ON-TEXT'), "%Y-%m-%d,",
                                      ugettext('APP-AT-TEXT'), "%H:%M")
        now = datetime.datetime.now()
        time = now.strftime(timeformat)
        l_permalink = ""

        #TODO check and fix al urls.
        if int(action_id) != int(choices.ActionStreams.DELETE):
            if resource_type == settings.TYPE_DATASTREAM:
                l_permalink = reverse('manageDataviews.view',
                                      urlconf='workspace.urls',
                                      kwargs={'revision_id': revision_id})
            elif resource_type == settings.TYPE_VISUALIZATION:
                l_permalink = reverse('manageVisualizations.view',
                                      urlconf='workspace.urls',
                                      kwargs={'revision_id': revision_id})
            elif resource_type == settings.TYPE_DATASET:
                l_permalink = reverse('manageDatasets.view',
                                      urlconf='workspace.urls',
                                      kwargs={'revision_id': revision_id})
            else:
                for plugin in DatalPluginPoint.get_plugins():
                    if (plugin.is_active() and hasattr(plugin, 'doc_type')
                            and plugin.doc_type == resource_type
                            and hasattr(plugin, 'workspace_permalink')):
                        l_permalink = plugin.workspace_permalink(revision_id)

        list_key = 'activity_stream::%s' % str(account_id)
        n = c.incr(
            "%s_counter" % list_key
        )  # count any use of the list indexing hash and never repeat an ID
        activity_key = 'activity.stream_%s:%s' % (str(account_id), str(n))
        activity_value = {
            "user_id": user_id,
            "revision_id": revision_id,
            "type": resource_type,
            "resource_id": resource_id,
            "action_id": action_id,
            "title": resource_title,
            "time": time,
            "resource_link": l_permalink,
            "category": resource_category
        }

        r1 = c.hmset(activity_key, activity_value)
        r2 = c.lpush(str(list_key), activity_key)
        if settings.DEBUG:
            logger.info('Saved ActivityStreamDAO {} {} {} {} {}'.format(
                str(r1), str(r2), list_key, activity_key, activity_value))
        return list_key, activity_key, activity_value
Ejemplo n.º 2
0
    def create(self, account_id, user_id, revision_id, resource_type, resource_id, action_id, resource_title):
        """ Create a redis-hash and then addit to a redis-lits"""
        c = Cache(db=settings.CACHE_DATABASES['activity_resources'])

        timeformat = "%s %s %s %s" % (ugettext('APP-ON-TEXT'), "%B %d, %Y", ugettext('APP-AT-TEXT'), "%H:%M")
        now = datetime.datetime.now()
        time = now.strftime(timeformat)
        l_permalink=""

        #TODO check and fix al urls.
        if int(action_id) != int(choices.ActionStreams.DELETE):
            if resource_type == settings.TYPE_DATASTREAM:
                l_permalink = reverse('manageDataviews.view', urlconf='workspace.urls',
                                      kwargs={'revision_id': revision_id})
            elif resource_type == settings.TYPE_VISUALIZATION:
                l_permalink = reverse('manageVisualizations.view', urlconf='workspace.urls',
                                      kwargs={'revision_id': revision_id})
            elif resource_type == settings.TYPE_DATASET:
                l_permalink = reverse('manageDatasets.view', urlconf='workspace.urls',
                                      kwargs={'revision_id': revision_id})
            elif resource_type == settings.TYPE_DASHBOARD:
                l_permalink = LocalHelper.build_permalink('dashboard_manager.action_view',
                                                          '&dashboard_revision_id=' + str(revision_id))

        list_key = 'activity_stream::%s' % str(account_id)
        n=c.incr("%s_counter" % list_key) # count any use of the list indexing hash and never repeat an ID
        activity_key = 'activity.stream_%s:%s' % (str(account_id), str(n))
        activity_value = {"user_id": user_id, "revision_id": revision_id
                        , "type": resource_type, "resource_id": resource_id
                        ,"action_id": action_id
                        , "title": resource_title, "time":time
                        , "resource_link": l_permalink }

        c.hmset(activity_key, activity_value)
        c.lpush(str(list_key), activity_key)
        return list_key, activity_key, activity_value
Ejemplo n.º 3
0
    def create(self, account_id, user_id, revision_id, resource_type, resource_id, action_id, resource_title, resource_category):
        """ Create a redis-hash and then addit to a redis-lits"""
        if settings.DEBUG: logger.info('Create ActivityStreamDAO %d %s' % (action_id, resource_title))
        c = Cache(db=settings.CACHE_DATABASES['activity_resources'])

        timeformat = "%s %s %s %s" % (ugettext('APP-ON-TEXT'), "%Y-%m-%d,", ugettext('APP-AT-TEXT'), "%H:%M")
        now = datetime.datetime.now()
        time = now.strftime(timeformat)
        l_permalink=""

        #TODO check and fix al urls.
        if int(action_id) != int(choices.ActionStreams.DELETE):
            if resource_type == settings.TYPE_DATASTREAM:
                l_permalink = reverse('manageDataviews.view', urlconf='workspace.urls',
                                      kwargs={'revision_id': revision_id})
            elif resource_type == settings.TYPE_VISUALIZATION:
                l_permalink = reverse('manageVisualizations.view', urlconf='workspace.urls',
                                      kwargs={'revision_id': revision_id})
            elif resource_type == settings.TYPE_DATASET:
                l_permalink = reverse('manageDatasets.view', urlconf='workspace.urls',
                                      kwargs={'revision_id': revision_id})
            else:
                for plugin in DatalPluginPoint.get_plugins():
                    if (plugin.is_active() and hasattr(plugin, 'doc_type') and 
                        plugin.doc_type == resource_type and 
                        hasattr(plugin, 'workspace_permalink')):
                        l_permalink = plugin.workspace_permalink(revision_id)
            
        list_key = 'activity_stream::%s' % str(account_id)
        n=c.incr("%s_counter" % list_key) # count any use of the list indexing hash and never repeat an ID
        activity_key = 'activity.stream_%s:%s' % (str(account_id), str(n))
        activity_value = {"user_id": user_id, "revision_id": revision_id
                        , "type": resource_type, "resource_id": resource_id
                        ,"action_id": action_id
                        , "title": resource_title, "time":time
                        , "resource_link": l_permalink
                        , "category": resource_category }

        r1 = c.hmset(activity_key, activity_value)
        r2 = c.lpush(str(list_key), activity_key)
        if settings.DEBUG: logger.info('Saved ActivityStreamDAO {} {} {} {} {}'.format(str(r1), str(r2), list_key, activity_key, activity_value))
        return list_key, activity_key, activity_value