Commit 09a8d714 authored by Michal Čihař's avatar Michal Čihař

Count changes in given project

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent e3e9aae2
......@@ -35,6 +35,7 @@ class BillingAdmin(admin.ModelAdmin):
list_display = (
'user', 'plan',
'list_projects',
'count_changes_1m', 'count_changes_1q', 'count_changes_1y',
'count_repositories', 'count_strings', 'count_words',
'count_languages',
'in_limits',
......
......@@ -21,8 +21,11 @@
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from weblate.trans.models import Project, SubProject
from datetime import timedelta
from weblate.trans.models import Project, SubProject, Change
from weblate.lang.models import Language
......@@ -50,6 +53,24 @@ class Billing(models.Model):
def __unicode__(self):
return u'{0} ({1})'.format(self.user, self.plan)
def count_changes(self, interval):
return Change.objects.filter(
subproject__project__in=self.projects.all(),
timestamp__gt=timezone.now() - interval,
).count()
def count_changes_1m(self):
return self.count_changes(timedelta(days=31))
count_changes_1m.short_description = _('Changes in last month')
def count_changes_1q(self):
return self.count_changes(timedelta(days=93))
count_changes_1q.short_description = _('Changes in last quarter')
def count_changes_1y(self):
return self.count_changes(timedelta(days=365))
count_changes_1y.short_description = _('Changes in last year')
def count_repositories(self):
return SubProject.objects.filter(
project__in=self.projects.all(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment