Clawing away at the notification job a little more...
diff -r dd73283c4752 -r 14e352e5b840 projects/models.py
--- a/projects/models.py Fri Jan 23 01:11:53 2009 -0500
+++ b/projects/models.py Sat Jan 31 05:01:44 2009 -0500
@@ -314,5 +314,9 @@
self.unit.prepare_repo()
del(self.trans)
+ def get_rev(self, path=None):
+ """Get revision of a path from the underlying Unit"""
+ return self.unit.get_rev(path)
+
log_model(Component)
log_model(Unit)
diff -r dd73283c4752 -r 14e352e5b840 vcs/models.py
--- a/vcs/models.py Fri Jan 23 01:11:53 2009 -0500
+++ b/vcs/models.py Sat Jan 31 05:01:44 2009 -0500
@@ -145,6 +145,11 @@
new_name))
self.browser.rename_repo(new_name)
+ @need_browser
+ def get_rev(self, path=None):
+ """Get revision of a path from the underlying VCS"""
+ return self.browser.get_rev(path)
+
def suite():
"""
Define the testing suite for Django's test runner.
diff -r 14e352e5b840 -r 509bc9169e8b repowatch/__init__.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/repowatch/__init__.py Sat Jan 31 05:44:56 2009 -0500
@@ -0,0 +1,23 @@
+from django.contrib.sites.models import Site
+from django.core.mail import send_mail
+from django.template import loader, Context
+
+class WatchException(Exception):
+ pass
+
+#TODO: patch update routine to compare revs
+
+def send_email(site, component, user, repo_changed, files):
+ """
+ Sends email to a watcher for a specific component
+ """
+ context = Context({'component': component.name,
+ 'first_name': user.first_name, 'hostname': site.domain,
+ 'url': 'http://%s/' % site.domain, 'files': files,
+ 'repo_changed': repo_changed})
+ subject = loader.get_template('templates/subject.tmpl').render(
+ context)
+ message = loader.get_template('templates/body.tmpl').render(
+ context)
+ from_address = 'Transifex <donotreply@%s>' % site.domain
+ send_mail(subject, message, from_address, [user.email])
diff -r 14e352e5b840 -r 509bc9169e8b repowatch/admin.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/repowatch/admin.py Sat Jan 31 05:44:56 2009 -0500
@@ -0,0 +1,4 @@
+from django.contrib import admin
+from models import Watch
+
+admin.site.register(Watch)
diff -r 14e352e5b840 -r 509bc9169e8b repowatch/models.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/repowatch/models.py Sat Jan 31 05:44:56 2009 -0500
@@ -0,0 +1,39 @@
+from django.db import models
+from django.contrib.auth.models import User
+from django.utils.translation import ugettext_lazy as _
+
+from projects.models import Component
+from repowatch import WatchException
+
+# Create your models here.
+
+class WatchManager(models.Manager):
+ def add_watch(user, component, path=None):
+ watch, found = self.get_or_create(path=path, component=component,
+ user=user)
+ if not found:
+ try:
+ rev = component.get_rev(path)
+ except ValueError:
+ raise WatchException('Unable to add watch for path %r' %
+ path)
+ watch.rev = rev
+ watch.save()
+ return watch
+
+class Watch(models.Model):
+ path = models.CharField(max_length=128, null=True, default=None)
+ rev = models.CommaSeparatedIntegerField(max_length=64)
+ component = models.ForeignKey(Component)
+ user = models.ManyToManyField(User)
+
+ object = WatchManager()
+
+ def __unicode__(self):
+ if self.path is None:
+ return u'repo of %s' % (self.component,)
+ return u'%s in %s' % (self.path, self.component)
+
+ class Meta:
+ verbose_name = _('watch')
+ verbose_name_plural = _('watches')
diff -r 14e352e5b840 -r 509bc9169e8b repowatch/templates/body.tmpl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/repowatch/templates/body.tmpl Sat Jan 31 05:44:56 2009 -0500
@@ -0,0 +1,19 @@
+{% load i18n %}
+{% blocktrans %}Hello {{ first_name }}, this is Transifex at {{ hostname }}.{% endblocktrans %}
+
+{% if repo_changed %}
+{% blocktrans %}The repo for {{ component }} has been updated.{% endblocktrans %}
+
+{% endif %}
+{% if files %}
+{% blocktrans %}The following files in {{ component }} have been updated:{% endblocktrans %}
+
+{% for file in files %}
+{{ file }}
+{% endfor %}
+
+{% endfor %}
+{% blocktrans %}Please log into Transifex at {{ url }} in order to see the changes.{% endblocktrans %}
+
+{% blocktrans %}Thanks,{% endblocktrans %}
+ Transifex
diff -r 14e352e5b840 -r 509bc9169e8b repowatch/templates/subject.tmpl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/repowatch/templates/subject.tmpl Sat Jan 31 05:44:56 2009 -0500
@@ -0,0 +1,1 @@
+{% blocktrans %}Files changed in {{ component }}{% endblocktrans %}
diff -r 14e352e5b840 -r 509bc9169e8b repowatch/views.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/repowatch/views.py Sat Jan 31 05:44:56 2009 -0500
@@ -0,0 +1,1 @@
+# Create your views here.
diff -r 14e352e5b840 -r 509bc9169e8b settings.py
--- a/settings.py Sat Jan 31 05:01:44 2009 -0500
+++ b/settings.py Sat Jan 31 05:44:56 2009 -0500
@@ -148,8 +148,9 @@
'languages',
'projects',
'txcollections',
- 'releases'
+ 'releases',
#'management',
+ 'repowatch',
]
####################