Exemple #1
0
def _log_to_recent_project_actions(p, user_id, action_time, message):
    """Log actions that refer to projects to a queue of most recent actions.

    We use redis' list for that. We skip actions that refer to private projects.
    """
    Project = get_model('projects', 'Project')
    if p.private:
        return
    private_slugs = Project.objects.filter(
        private=True
    ).values_list('slug', flat=True)
    for slug in private_slugs:
        if ('/projects/p/%s/' % slug) in message:
            return

    key = 'event_feed'
    data = {
        'name': force_unicode(p)[:200],
        'user_id': user_id,
        'action_time': action_time,
        'message': message
    }
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 11)
Exemple #2
0
def _log_to_resource_history(resource, action_time, action_type, message):
    """Log a message to a resource's history queue."""
    Resource = get_model("resources", "Resource")
    key = redis_key_for_resource(resource)
    data = {"action_time": action_time, "message": message, "action_type": action_type}
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 4)
Exemple #3
0
def _log_to_team_history(team, action_time, action_type, message):
    """Log a message to a team's history queue."""
    Resource = get_model("teams", "Team")
    key = redis_key_for_team(team)
    data = {"action_time": action_time, "message": message, "action_type": action_type}
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 4)
Exemple #4
0
def _log_to_team_history(team, action_time, action_type, message):
    """Log a message to a team's history queue."""
    Resource = get_model('teams', 'Team')
    key = redis_key_for_team(team)
    data = {
        'action_time': action_time,
        'message': message,
        'action_type': action_type,
    }
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 4)
Exemple #5
0
def _log_to_user_history(user, action_time, action_type, message):
    """Log a message to a user's history queue."""
    key = redis_key_for_user(user)
    data = {
        'action_time': action_time,
        'message': message,
        'action_type': action_type,
        'user': user.username
    }
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 11)
Exemple #6
0
def _log_to_resource_history(resource, action_time, action_type, message):
    """Log a message to a resource's history queue."""
    Resource = get_model('resources', 'Resource')
    key = redis_key_for_resource(resource)
    data = {
        'action_time': action_time,
        'message': message,
        'action_type': action_type,
    }
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 4)
Exemple #7
0
def _log_to_project_history(project, action_time, action_type, message):
    """Log a message to a project's history queue."""
    Project = get_model("projects", "Project")
    key = redis_key_for_project(project)
    data = {"action_time": action_time, "message": message, "action_type": action_type}
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 4)

    # Store logs in hubs, too
    if project.outsource:
        _log_to_project_history(project.outsource, action_time, action_type, message)
 def _populate_history(self, team):
     """Store the latest action log items for the specified team."""
     Team = get_model('teams', 'Team')
     entries = LogEntry.objects.filter(
         content_type=ContentType.objects.get_for_model(Team),
         object_id=team.id
     )[:5]
     r = TxRedisMapper()
     key = redis_key_for_team(team)
     for entry in entries:
         data = {
             'action_time': entry.action_time,
             'message': entry.message,
             'action_type': entry.action_type,
         }
         r.rpush(key, data=data)
     r.ltrim(key, 0, 4)
 def _populate_history(self, resource):
     """Store the latest action log items for the specified resources."""
     Resource = get_model('resources', 'Resource')
     entries = LogEntry.objects.filter(
         content_type=ContentType.objects.get_for_model(Resource),
         object_id=resource.id
     )[:5]
     r = TxRedisMapper()
     key = redis_key_for_resource(resource)
     for entry in entries:
         data = {
             'action_time': entry.action_time,
             'message': entry.message,
             'action_type': entry.action_type,
         }
         r.rpush(key, data=data)
     r.ltrim(key, 0, 4)
Exemple #10
0
def _log_to_recent_project_actions(p, user_id, action_time, message):
    """Log actions that refer to projects to a queue of most recent actions.

    We use redis' list for that. We skip actions that refer to private projects.
    """
    Project = get_model("projects", "Project")
    if p.private:
        return
    private_slugs = Project.objects.filter(private=True).values_list("slug", flat=True)
    for slug in private_slugs:
        if ("/projects/p/%s/" % slug) in message:
            return

    key = "event_feed"
    data = {"name": force_unicode(p)[:200], "user_id": user_id, "action_time": action_time, "message": message}
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 11)
 def _populate_history(self, project):
     """Store the latest action log items for the specified project."""
     ids = [project.id]
     if project.is_hub:
         ids += project.outsourcing.all().values_list('id', flat=True)
     entries = LogEntry.objects.filter(
         content_type=ContentType.objects.get_for_model(Project),
         object_id__in=ids
     )[:5]
     r = TxRedisMapper()
     key = redis_key_for_project(project)
     for entry in entries:
         data = {
             'action_time': entry.action_time,
             'message': entry.message,
             'action_type': entry.action_type
         }
         r.rpush(key, data=data)
     r.ltrim(key, 0, 4)
Exemple #12
0
def _log_to_resource_history(resource, action_time, action_type, message):
    """Log a message to a resource's history queue."""
    Resource = get_model('resources', 'Resource')
    key = redis_key_for_resource(resource)
    data = {
        'action_time': action_time,
        'message': message,
        'action_type': action_type,
    }
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 4)
Exemple #13
0
def _log_to_user_history(user, action_time, action_type, message):
    """Log a message to a user's history queue."""
    key = redis_key_for_user(user)
    data = {
        'action_time': action_time,
        'message': message,
        'action_type': action_type,
        'user': user.username
    }
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 11)
Exemple #14
0
def _log_to_team_history(team, action_time, action_type, message):
    """Log a message to a team's history queue."""
    Resource = get_model('teams', 'Team')
    key = redis_key_for_team(team)
    data = {
        'action_time': action_time,
        'message': message,
        'action_type': action_type,
    }
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 4)
 def _populate_history(self, user):
     """Store the latest action log items for the specified team."""
     entries = LogEntry.objects.by_user(user)[:12]
     r = TxRedisMapper()
     key = redis_key_for_user(user)
     for entry in entries:
         data = {
             'action_time': entry.action_time,
             'message': entry.message,
             'action_type': entry.action_type,
             'user': entry.user.username
         }
         r.rpush(key, data=data)
     r.ltrim(key, 0, 11)
 def _populate_history(self, resource):
     """Store the latest action log items for the specified resources."""
     Resource = get_model('resources', 'Resource')
     entries = LogEntry.objects.filter(
         content_type=ContentType.objects.get_for_model(Resource),
         object_id=resource.id)[:5]
     r = TxRedisMapper()
     key = redis_key_for_resource(resource)
     for entry in entries:
         data = {
             'action_time': entry.action_time,
             'message': entry.message,
             'action_type': entry.action_type,
         }
         r.rpush(key, data=data)
     r.ltrim(key, 0, 4)
 def _populate_history(self, team):
     """Store the latest action log items for the specified team."""
     Team = get_model('teams', 'Team')
     entries = LogEntry.objects.filter(
         content_type=ContentType.objects.get_for_model(Team),
         object_id=team.id)[:5]
     r = TxRedisMapper()
     key = redis_key_for_team(team)
     for entry in entries:
         data = {
             'action_time': entry.action_time,
             'message': entry.message,
             'action_type': entry.action_type,
         }
         r.rpush(key, data=data)
     r.ltrim(key, 0, 4)
Exemple #18
0
def _log_to_project_history(project, action_time, action_type, message):
    """Log a message to a project's history queue."""
    Project = get_model('projects', 'Project')
    key = redis_key_for_project(project)
    data = {
        'action_time': action_time,
        'message': message,
        'action_type': action_type,
    }
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 4)

    # Store logs in hubs, too
    if project.outsource:
        _log_to_project_history(project.outsource, action_time, action_type,
                                message)
 def _populate_history(self, project):
     """Store the latest action log items for the specified project."""
     ids = [project.id]
     if project.is_hub:
         ids += project.outsourcing.all().values_list('id', flat=True)
     entries = LogEntry.objects.filter(
         content_type=ContentType.objects.get_for_model(Project),
         object_id__in=ids)[:5]
     r = TxRedisMapper()
     key = redis_key_for_project(project)
     for entry in entries:
         data = {
             'action_time': entry.action_time,
             'message': entry.message,
             'action_type': entry.action_type
         }
         r.rpush(key, data=data)
     r.ltrim(key, 0, 4)
Exemple #20
0
def _log_to_recent_project_actions(p, user_id, action_time, message):
    """Log actions that refer to projects to a queue of most recent actions.

    We use redis' list for that. We skip actions that refer to private projects.
    """
    Project = get_model('projects', 'Project')
    if p.private:
        return
    private_slugs = Project.objects.filter(private=True).values_list('slug',
                                                                     flat=True)
    for slug in private_slugs:
        if ('/projects/p/%s/' % slug) in message:
            return

    key = 'event_feed'
    data = {
        'name': force_unicode(p)[:200],
        'user_id': user_id,
        'action_time': action_time,
        'message': message
    }
    r = TxRedisMapper()
    r.lpush(key, data=data)
    r.ltrim(key, 0, 11)
 def _set_datetime_mark(self, when):
     """Set the datetime mark for static pages to when."""
     r = TxRedisMapper()
     r.set(STATIC_CACHE_KEY_LAST_MODIFIED, data=when)
     etag = hashlib.md5(when.isoformat()).hexdigest()
     r.set(STATIC_CACHE_KEY_ETAG, data=etag)
Exemple #22
0
def static_last_modified(*args, **kwargs):
    r = TxRedisMapper()
    return r.get(STATIC_CACHE_KEY_LAST_MODIFIED)
 def _set_datetime_mark(self, when):
     """Set the datetime mark for static pages to when."""
     r = TxRedisMapper()
     r.set(STATIC_CACHE_KEY_LAST_MODIFIED, data=when)
     etag = hashlib.md5(when.isoformat()).hexdigest()
     r.set(STATIC_CACHE_KEY_ETAG, data=etag)
 def _action_logs_from_redis(self, key):
     """Get the action logs for the key from redis."""
     if not settings.USE_REDIS:
         return None
     r = TxRedisMapper()
     return r.lrange(key, 0, -1)
Exemple #25
0
def static_etag(*args, **kwargs):
    r = TxRedisMapper()
    return r.get(STATIC_CACHE_KEY_ETAG)
Exemple #26
0
def static_last_modified(*args, **kwargs):
    r = TxRedisMapper()
    return r.get(STATIC_CACHE_KEY_LAST_MODIFIED)
Exemple #27
0
def static_etag(*args, **kwargs):
    r = TxRedisMapper()
    return r.get(STATIC_CACHE_KEY_ETAG)
Exemple #28
0
 def _action_logs_from_redis(self, key):
     """Get the action logs for the key from redis."""
     if not settings.USE_REDIS:
         return None
     r = TxRedisMapper()
     return r.lrange(key, 0, -1)