django-last-used / last_used / __init__.py

from models import LastUsed, ContentType


LIMIT = 10


def use(object, user, key=None, when=None):
    args = {
       'user': user,
       'content_object': object
    }

    if when:
        args['last_used'] = when

    if key:
        args['key'] = key

    obj = LastUsed.objects.create(**args)

    filters = args.copy()

    del filters['content_object']
    filters['content_type'] = obj.content_type

    for lu in LastUsed.objects.filter(**filters)[LIMIT:]:
        lu.delete()

    return obj


def get(model=None, user=None, key=None, limit=0):

    filters = {}
    if model:
        filters['content_type'] = ContentType.objects.get_for_model(model)

    if user:
        filters['user'] = user

    if key:
        filters['key'] = key

    objects = LastUsed.objects.filter(**filters)

    if limit:
        objects = objects[:limit]

    return objects
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.