Seraphim Mellos avatar Seraphim Mellos committed a3a4e49

More work on the translation wordcount and rlstats

Comments (0)

Files changed (5)

transifex/resources/formats/core.py

             self._post_save2db(is_source , user, overwrite_translations)
 
             # Invalidate cache after saving file
-            invalidate_stats_cache(self.resource, self.language)
+            invalidate_stats_cache(self.resource, self.language, user=user)
 
 
             if strings_added + strings_updated > 0:

transifex/resources/handlers.py

         # Get or create new RLStat object
         rl, created = RLStats.objects.get_or_create(resource=resource,
             language=language)
-        # If it's new it's updated. Otherwise update now.
-        if not created:
-            rl.update_translated_wordcount(save=False)
-            rl.update_translated()
-        rl.update_now( kwargs['user'] if kwargs.has_key('user') else None)
+        rl.update( kwargs['user'] if kwargs.has_key('user') else None)
         # Check to see if the lang has zero translations and is not a team
         # lang. If yes, delete RLStats object
         if rl.translated == 0 and rl.language.id not in\
         # Source file was updated. Update all language statistics
         stats = RLStats.objects.filter(resource=resource)
         for s in stats:
-            s.update_translated_wordcount(save=False)
-            s.update_translated()
-            s.update_now( kwargs['user'] if kwargs.has_key('user') else None)
-
+            s.update(kwargs['user'] if kwargs.has_key('user') else None)
             if s.translated == 0 and s.language.id not in\
               s.resource.project.team_set.all().values_list('language',
               flat=True):

transifex/resources/migrations/0009_added_translation_wordcount.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding field 'Translation.wordcount'
+        db.add_column('resources_translation', 'wordcount', self.gf('django.db.models.fields.PositiveIntegerField')(default=0), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'Translation.wordcount'
+        db.delete_column('resources_translation', 'wordcount')
+
+
+    models = {
+        'actionlog.logentry': {
+            'Meta': {'ordering': "('-action_time',)", 'object_name': 'LogEntry'},
+            'action_time': ('django.db.models.fields.DateTimeField', [], {}),
+            'action_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['notification.NoticeType']"}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'actionlogs'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'message': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'object_id': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'object_name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'actionlogs'", 'null': 'True', 'to': "orm['auth.User']"})
+        },
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'languages.language': {
+            'Meta': {'ordering': "('name',)", 'object_name': 'Language', 'db_table': "'translations_language'"},
+            'code': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50'}),
+            'code_aliases': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '100', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50'}),
+            'nplurals': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
+            'pluralequation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'rule_few': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'rule_many': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'rule_one': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'rule_other': ('django.db.models.fields.CharField', [], {'default': "'everything'", 'max_length': '255'}),
+            'rule_two': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'rule_zero': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'specialchars': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'})
+        },
+        'notification.noticetype': {
+            'Meta': {'object_name': 'NoticeType'},
+            'default': ('django.db.models.fields.IntegerField', [], {}),
+            'description': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'display': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'label': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+        },
+        'projects.project': {
+            'Meta': {'ordering': "('name',)", 'object_name': 'Project'},
+            'anyone_submit': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'bug_tracker': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'feed': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'homepage': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'long_description': ('django.db.models.fields.TextField', [], {'max_length': '1000', 'blank': 'True'}),
+            'long_description_html': ('django.db.models.fields.TextField', [], {'max_length': '1000', 'blank': 'True'}),
+            'maintainers': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'projects_maintaining'", 'null': 'True', 'to': "orm['auth.User']"}),
+            'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+            'outsource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['projects.Project']", 'null': 'True', 'blank': 'True'}),
+            'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+            'private': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '30', 'db_index': 'True'}),
+            'tags': ('tagging.fields.TagField', [], {})
+        },
+        'resources.resource': {
+            'Meta': {'ordering': "('_order',)", 'unique_together': "(('slug', 'project'),)", 'object_name': 'Resource'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'accept_translations': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'i18n_type': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'project': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'resources'", 'null': 'True', 'to': "orm['projects.Project']"}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}),
+            'source_file': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['storage.StorageFile']", 'null': 'True', 'blank': 'True'}),
+            'source_language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['languages.Language']"}),
+            'total_entities': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'wordcount': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+        },
+        'resources.rlstats': {
+            'Meta': {'ordering': "('_order',)", 'unique_together': "(('resource', 'language'),)", 'object_name': 'RLStats'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['languages.Language']"}),
+            'last_committer': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['auth.User']", 'null': 'True'}),
+            'last_update': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'auto_now': 'True', 'blank': 'True'}),
+            'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['resources.Resource']"}),
+            'translated': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+            'translated_perc': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+            'translated_wordcount': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+            'untranslated': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+            'untranslated_perc': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'})
+        },
+        'resources.sourceentity': {
+            'Meta': {'ordering': "('_order',)", 'unique_together': "(('string_hash', 'context', 'resource'),)", 'object_name': 'SourceEntity'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'context': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'developer_comment': ('django.db.models.fields.TextField', [], {'max_length': '1000', 'blank': 'True'}),
+            'flags': ('django.db.models.fields.TextField', [], {'max_length': '100', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'occurrences': ('django.db.models.fields.TextField', [], {'max_length': '1000', 'null': 'True', 'blank': 'True'}),
+            'pluralized': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'resource': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'source_entities'", 'to': "orm['resources.Resource']"}),
+            'string': ('django.db.models.fields.TextField', [], {}),
+            'string_hash': ('django.db.models.fields.CharField', [], {'max_length': '32'})
+        },
+        'resources.template': {
+            'Meta': {'ordering': "['resource']", 'object_name': 'Template'},
+            'content': ('transifex.txcommon.db.models.CompressedTextField', [], {'null': 'False', 'blank': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'resource': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'source_file_template'", 'unique': 'True', 'to': "orm['resources.Resource']"})
+        },
+        'resources.translation': {
+            'Meta': {'ordering': "('_order',)", 'unique_together': "(('source_entity', 'language', 'rule'),)", 'object_name': 'Translation'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['languages.Language']", 'null': 'True'}),
+            'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'rule': ('django.db.models.fields.IntegerField', [], {'default': '5'}),
+            'source_entity': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'to': "orm['resources.SourceEntity']"}),
+            'string': ('django.db.models.fields.TextField', [], {}),
+            'string_hash': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+            'wordcount': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'})
+        },
+        'storage.storagefile': {
+            'Meta': {'object_name': 'StorageFile'},
+            'bound': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['languages.Language']", 'null': 'True'}),
+            'mime_type': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'size': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'total_strings': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+            'uuid': ('django.db.models.fields.CharField', [], {'max_length': '1024'})
+        }
+    }
+
+    complete_apps = ['resources']

transifex/resources/migrations/0010_calculate_translation_wordcount.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+from transifex.resources.models import Translation
+
+class Migration(DataMigration):
+
+    def forwards(self, orm):
+        "Write your forwards methods here."
+        for t in Translation.objects.all():
+            t.save()
+
+
+    def backwards(self, orm):
+        "Write your backwards methods here."
+
+
+    models = {
+        'actionlog.logentry': {
+            'Meta': {'ordering': "('-action_time',)", 'object_name': 'LogEntry'},
+            'action_time': ('django.db.models.fields.DateTimeField', [], {}),
+            'action_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['notification.NoticeType']"}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'actionlogs'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'message': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'object_id': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'object_name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'actionlogs'", 'null': 'True', 'to': "orm['auth.User']"})
+        },
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'languages.language': {
+            'Meta': {'ordering': "('name',)", 'object_name': 'Language', 'db_table': "'translations_language'"},
+            'code': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50'}),
+            'code_aliases': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '100', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50'}),
+            'nplurals': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
+            'pluralequation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'rule_few': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'rule_many': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'rule_one': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'rule_other': ('django.db.models.fields.CharField', [], {'default': "'everything'", 'max_length': '255'}),
+            'rule_two': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'rule_zero': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'specialchars': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'})
+        },
+        'notification.noticetype': {
+            'Meta': {'object_name': 'NoticeType'},
+            'default': ('django.db.models.fields.IntegerField', [], {}),
+            'description': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'display': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'label': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+        },
+        'projects.project': {
+            'Meta': {'ordering': "('name',)", 'object_name': 'Project'},
+            'anyone_submit': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'bug_tracker': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'feed': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'homepage': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'long_description': ('django.db.models.fields.TextField', [], {'max_length': '1000', 'blank': 'True'}),
+            'long_description_html': ('django.db.models.fields.TextField', [], {'max_length': '1000', 'blank': 'True'}),
+            'maintainers': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'projects_maintaining'", 'null': 'True', 'to': "orm['auth.User']"}),
+            'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+            'outsource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['projects.Project']", 'null': 'True', 'blank': 'True'}),
+            'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+            'private': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '30', 'db_index': 'True'}),
+            'tags': ('tagging.fields.TagField', [], {})
+        },
+        'resources.resource': {
+            'Meta': {'ordering': "('_order',)", 'unique_together': "(('slug', 'project'),)", 'object_name': 'Resource'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'accept_translations': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'i18n_type': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'project': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'resources'", 'null': 'True', 'to': "orm['projects.Project']"}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}),
+            'source_file': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['storage.StorageFile']", 'null': 'True', 'blank': 'True'}),
+            'source_language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['languages.Language']"}),
+            'total_entities': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'wordcount': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+        },
+        'resources.rlstats': {
+            'Meta': {'ordering': "('_order',)", 'unique_together': "(('resource', 'language'),)", 'object_name': 'RLStats'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['languages.Language']"}),
+            'last_committer': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['auth.User']", 'null': 'True'}),
+            'last_update': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'auto_now': 'True', 'blank': 'True'}),
+            'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['resources.Resource']"}),
+            'translated': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+            'translated_perc': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+            'translated_wordcount': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+            'untranslated': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+            'untranslated_perc': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'})
+        },
+        'resources.sourceentity': {
+            'Meta': {'ordering': "('_order',)", 'unique_together': "(('string_hash', 'context', 'resource'),)", 'object_name': 'SourceEntity'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'context': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'developer_comment': ('django.db.models.fields.TextField', [], {'max_length': '1000', 'blank': 'True'}),
+            'flags': ('django.db.models.fields.TextField', [], {'max_length': '100', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'occurrences': ('django.db.models.fields.TextField', [], {'max_length': '1000', 'null': 'True', 'blank': 'True'}),
+            'pluralized': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'position': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'resource': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'source_entities'", 'to': "orm['resources.Resource']"}),
+            'string': ('django.db.models.fields.TextField', [], {}),
+            'string_hash': ('django.db.models.fields.CharField', [], {'max_length': '32'})
+        },
+        'resources.template': {
+            'Meta': {'ordering': "['resource']", 'object_name': 'Template'},
+            'content': ('transifex.txcommon.db.models.CompressedTextField', [], {'null': 'False', 'blank': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'resource': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'source_file_template'", 'unique': 'True', 'to': "orm['resources.Resource']"})
+        },
+        'resources.translation': {
+            'Meta': {'ordering': "('_order',)", 'unique_together': "(('source_entity', 'language', 'rule'),)", 'object_name': 'Translation'},
+            '_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['languages.Language']", 'null': 'True'}),
+            'last_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'rule': ('django.db.models.fields.IntegerField', [], {'default': '5'}),
+            'source_entity': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'to': "orm['resources.SourceEntity']"}),
+            'string': ('django.db.models.fields.TextField', [], {}),
+            'string_hash': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+            'wordcount': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'})
+        },
+        'storage.storagefile': {
+            'Meta': {'object_name': 'StorageFile'},
+            'bound': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['languages.Language']", 'null': 'True'}),
+            'mime_type': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'size': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'total_strings': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
+            'uuid': ('django.db.models.fields.CharField', [], {'max_length': '1024'})
+        }
+    }
+
+    complete_apps = ['resources']

transifex/resources/models.py

                     "It's 0=zero, 1=one, 2=two, 3=few, 4=many and 5=other. "
                     "For translations that have its entity not pluralized, "
                     "the rule must be 5 (other)."))
+    wordcount = models.PositiveIntegerField(_("Wordcount for this string."),
+        blank=False, null=False, default=0, help_text="The number of words "
+        " contained in this translation string.")
 
     # Timestamps
     created = models.DateTimeField(auto_now_add=True, editable=False)
         """
         # encoding happens to support unicode characters
         self.string_hash = md5(self.string.encode('utf-8')).hexdigest()
+        self._update_wordcount()
         super(Translation, self).save(*args, **kwargs)
 
-    @property
-    def wordcount(self):
+    def _update_wordcount(self):
         """
         Return the number of words for this translation string.
         """
         # use None to split at any whitespace regardless of length
         # so for instance double space counts as one space
-        return len(self.string.split(None))
+        self.wordcount = len(self.string.split(None))
 
 
 
     def untranslated_wordcount(self):
         return self.resource.wordcount - self.translated_wordcount
 
-    def save(self, *args, **kwargs):
-        self.calculate_translated()
-        self.update_last_translation()
-        self._calculate_perc()
+    def save(self, update=True, *args, **kwargs):
+        if update:
+            self.update(user=None, save=False)
         super(RLStats, self).save(*args, **kwargs)
 
     def _calculate_perc(self):
             self.translated_perc = 0
             self.untranslated_perc = 0
 
-    def calculate_translated_wordcount(self):
+    def _calculate_translated_wordcount(self):
         """Calculate wordcount of translated/untranslated entries"""
         wc = 0
         translated = SourceEntity.objects.filter(
             id__in=Translation.objects.filter(language=self.language,
             source_entity__resource=self.resource).distinct().values_list(
             'source_entity', flat=True))
-        source_trans = Translation.objects.filter(source_entity__in=translated,
-            language=self.resource.source_language)
-        for t in source_trans:
-            if t:
-                wc += t.wordcount
-        return wc
+        wordcount = Translation.objects.filter(source_entity__in=translated,
+            language=self.resource.source_language).aggregate(Sum('wordcount'))['wordcount__sum']
+        self.translated_wordcount = wordcount or 0
 
-    def calculate_translated(self):
+    def _calculate_translated(self):
         """
         Calculate translated/untranslated entities.
         """
             language=self.language, source_entity__resource=self.resource
             ).distinct().count()
         untranslated = total - translated
+        self.translated = translated
+        self.untranslated = untranslated
 
-        return translated, untranslated
+    def update(self, user, save=True):
+        """
+        Update the RLStat object
+        """
+        self._calculate_translated()
+        self._calculate_translated_wordcount()
+        self._calculate_perc()
+        self._update_now(user)
+        if save:
+            self.save(update=False)
 
-    def update_now(self, user=None):
+    def _update_now(self, user=None):
         """
         Update the last update and last committer.
         """
         if user:
             self.last_committer = user
 
-        self.save()
-
-    def update_translated(self, save=True):
-        """
-        Update the translated/untranslated entities
-        """
-        translated, untranslated = self.calculate_translated()
-        self.translated = translated
-        self.untranslated = untranslated
-
-        if save:
-            self.save()
-
-
-    def update_translated_wordcount(self, save=True):
-        """
-        Update the wordcount of the translated entities
-        """
-        self.translated_wordcount = self.calculate_translated_wordcount()
-        if save:
-            self.save()
-
-    def update_last_translation(self):
-        lt = Translation.objects.filter(language=self.language,
-            source_entity__resource=self.resource).select_related(
-            'last_update', 'user').order_by('-last_update')[:1]
-        if lt:
-            self.last_update = lt[0].last_update
-            self.last_committer = lt[0].user
-            return lt[0].last_update, lt[0].user
-        return None, None
-
-
-
 class Template(models.Model):
     """
     Source file template for a specific resource.
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.