Diego Búrigo Zacarão avatar Diego Búrigo Zacarão committed 6b91ba2

Added projects lookup for django-ajax-select queries

Comments (0)

Files changed (2)

transifex/projects/lookups.py

 from django.db.models import Q
-from projects.models import Component
+from projects.models import Project, Component
 
-class ComponentsLookup(object):
-    """A lookup class, used by django-ajax-select app to search model data."""
+class ProjectsLookup(object):
+    """A lookup class, used by django-ajax-select app to search Project objects."""
 
     def get_query(self, q, request):
         """
         Return a query set.
-        
+
+        You also have access to request.user if needed.
+        """
+        return Project.objects.filter(Q(slug__istartswith=q) |
+                                      Q(name__istartswith=q))
+
+    def format_item(self, project):
+        """Simple display of an project object when displayed in the list."""
+        return unicode(project)
+
+    def format_result(self, project):
+        """
+        A more verbose display, used in the search results display.
+
+        It may contain html and multi-lines.
+        """
+        return u"%s" % (project)
+
+    def get_objects(self, ids):
+        """Given a list of ids, return the projects ordered."""
+        return Project.objects.filter(pk__in=ids).order_by('name')
+
+
+class ComponentsLookup(object):
+    """
+    A lookup class, used by django-ajax-select app to search Component 
+    objects.
+    """
+
+    def get_query(self, q, request):
+        """
+        Return a query set.
+
         You also have access to request.user if needed.
         """
         return Component.objects.filter(Q(slug__istartswith=q) |
                                         Q(project__name__istartswith=q))
 
     def format_item(self, component):
-        """Simple display of an object when displayed in the list of objects """
+        """Simple display of an component when displayed in the list."""
         return unicode(component)
 
     def format_result(self, component):
         """
         A more verbose display, used in the search results display.
-        
+
         It may contain html and multi-lines.
         """
         return u"%s" % (component)
 
     def get_objects(self, ids):
-        """Given a list of ids, return the objects ordered."""
+        """Given a list of ids, return the components ordered."""
         return Component.objects.filter(pk__in=ids).order_by('name')

transifex/settings/40-apps.conf

 AJAX_LOOKUP_CHANNELS = {
     # the simplest case, pass a DICT with the model and field to search against :
     'users' : ('txcommon.lookups', 'UsersLookup'),
+    'projects' : ('projects.lookups', 'ProjectsLookup'),
     'components' : ('projects.lookups', 'ComponentsLookup'),
 }
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.