Commits

Apostolis Bessas committed 012e1db

Speed up the project_resources pages.

  • Participants
  • Parent commits 323428c

Comments (0)

Files changed (3)

File transifex/addons/priorities/models.py

         """Cycle through the states of the priority object."""
         self.level = str((int(self.level) + 1) % int(len(PRIORITY_LEVELS)))
         self.save()
+
+
+def level_display(level):
+    """Return the display name for the specified level."""
+    for lvl, name in PRIORITY_LEVELS:
+        if lvl == level:
+            return name

File transifex/projects/views/project.py

 from django.contrib import messages
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.urlresolvers import reverse
-from django.db.models import Q, get_model
+from django.db.models import Q, get_model, Sum, Max
 from django.http import HttpResponseRedirect
 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext
 from transifex.languages.models import Language
 from transifex.projects.permissions.project import ProjectPermission
 from transifex.releases.handlers import update_all_release
-from transifex.resources.models import RLStats
+from transifex.resources.models import Resource, RLStats
 from transifex.resources.utils import invalidate_template_cache
 from transifex.teams.forms import TeamRequestSimpleForm
 
 # To calculate user_teams
 from transifex.teams.models import Team
 
+from priorities.models import level_display
+
 Lock = get_model('locks', 'Lock')
 TranslationWatch = get_model('watches', 'TranslationWatch')
 
+
 def _project_create_update(request, project_slug=None,
     template_name='projects/project_form.html'):
     """
             project = form.save(commit=False)
             project_hub = project.outsource
             hub_request = None
-            
+
             if 'outsourced' != project_type:
                 project.outsource = None
             else:
                 check = ProjectPermission(request.user)
                 if not (check.maintain(project) and check.maintain(project_hub)):
-                    # If the user is not maintainer of both projects it does 
+                    # If the user is not maintainer of both projects it does
                     # not associate the outsource project directly.
                     # It does a request instead.
                     try:
                     hub_request.project_hub = project_hub
                     hub_request.user = request.user
                     hub_request.save()
-                    
+
                     messages.success(request,
                         _("Requested to join the '%s' project hub.") % project_hub)
                     # ActionLog & Notification
                     action_logging(request.user, [project, project_hub], nt, context=context)
 
                     if settings.ENABLE_NOTICES:
-                        # Send notification for project hub maintainers 
+                        # Send notification for project hub maintainers
                         notification.send(project_hub.maintainers.all(), nt, context)
 
                     return HttpResponseRedirect(request.POST['next'])
                 project.is_hub = True
             else:
                 project.is_hub = False
-            
-            if ('free_for_all' == access_control and 
+
+            if ('free_for_all' == access_control and
                 project_type != "outsourced"):
                 project.anyone_submit = True
             else:
             if outsourced and not project.outsource:
                 # Drop resources from all-resources release of the hub project
                 update_all_release(outsourced)
-                
+
                 # Logging action
                 nt = 'project_hub_left'
                 context = {'project': project, 'project_hub': outsourced,
 def project_resources(request, project_slug):
     project = get_object_or_404(Project.objects.select_related(), slug=project_slug)
 
-    statslist = RLStats.objects.select_related(
-        'resource', 'resource__project', 'resource__category',
-        'last_committer', 'resource__priority'
-    ).by_project_aggregated(project)
+    # statslist = RLStats.objects.select_related(
+    #     'resource', 'resource__project', 'resource__category',
+    #     'last_committer', 'resource__priority'
+    # ).by_project_aggregated(project)
+    statslist = Resource.objects.filter(
+        project=project
+    ).values(
+        'slug', 'name', 'category', 'priority__level',
+        'total_entities', 'wordcount'
+    ).annotate(
+        last_update=Max('rlstats__last_update')
+    )
+    for stat in statslist:
+        stat['priority__display'] = level_display(stat['priority__level'])
 
     return render_to_response('projects/project_resources.html', {
         'project_resources': True,

File transifex/templates/projects/project_resources.html

   	<div class="separate-buttons"><span id="create_new_resource" title="{% trans 'Add new resource' %}" class="i16 nude-button add houdini_toggler linkstyle">{% trans "Add New Resource" %}</span></div>
 		{% endif %}
 	</div>
-	
+
 
 <script type="text/javascript">
     $(document).ready(function(){
               0: function(node) {
                   var category = $(node).html();
                   if(category == "None")
-                    return "zzzzzzzzzzzz"; 
+                    return "zzzzzzzzzzzz";
                   else
                     return category;
               },
   </thead>
   <tbody>
   {% endif %}
-    <tr onclick="javascript:window.location.href='{% url resource_detail project.slug stat.object.slug %}';">
-		{% cache 604800 project_resource_details project.slug stat.object.slug LANGUAGE_CODE %}
-        
+    <tr onclick="javascript:window.location.href='{% url resource_detail project.slug stat.slug %}';">
+		{% cache 604800 project_resource_details project.slug stat.slug LANGUAGE_CODE %}
+
         <td><!--icon padding 27px+20px list padding...so that aligns with the rest-->
-          <h5 class="linkstyle" style="font-weight:bold">{{ stat.object.name }}&nbsp;&raquo;</h5>
+          <h5 class="linkstyle" style="font-weight:bold">{{ stat.name }}&nbsp;&raquo;</h5>
         </td>
-        <td class="category_td_class">{{ stat.object.category }}</td>
-        <td> {% blocktrans with stat.object.total_entities as strings and stat.object.wordcount as words %}{{ strings }} strings <span style="color:#888;">({{ words }} words)</span>{% endblocktrans %}</td>
+        <td class="category_td_class">{{ stat.category }}</td>
+        <td> {% blocktrans with stat.total_entities as strings and stat.wordcount as words %}{{ strings }} strings <span style="color:#888;">({{ words }} words)</span>{% endblocktrans %}</td>
         <td class="tablelastupd">
           {% with stat.last_committer as last_committer %}
             <span class="res_tipsy_enable" style="border:0" title="{% if last_committer %}{% blocktrans %}Committed by {{ last_committer }}{% endblocktrans %}<br/>{% else %}{% blocktrans %}No committers yet{% endblocktrans %}{% endif %}">
         </td>
 		{% endcache %}
         <td class="priority_level" style="width:100px;text-align:center">
-            {% with stat.object.priority.level as priority_level %}
-            {% with stat.object.priority.display_level as display_level %}
+            {% with stat.priority__level as priority_level %}
+            {% with stat.priority__display as display_level %}
             {% if is_maintainer %}
-              <a id="priority_{{ stat.object.slug }}" class="resource_priority_trigger" style="cursor:pointer">
+              <a id="priority_{{ stat.slug }}" class="resource_priority_trigger" style="cursor:pointer">
                 <span class="priority_sort" style="display:none">{{ priority_level }}</span>
                 <img class="res_tipsy_enable" src="{{ STATIC_URL }}priorities/images/{{ display_level }}.png" style="border:0" title="{{ display_level }}"/>
               </a>