damned-lies r1075 - in branches/djamnedlies: . stats stats/management/commands
- From: stephaner svn gnome org
- To: svn-commits-list gnome org
- Subject: damned-lies r1075 - in branches/djamnedlies: . stats stats/management/commands
- Date: Wed, 22 Oct 2008 21:48:50 +0000 (UTC)
Author: stephaner
Date: Wed Oct 22 21:48:50 2008
New Revision: 1075
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1075&view=rev
Log:
2008-10-22 StÃphane Raimbault <stephane raimbault gmail com>
Updated Person and Team classes.
* stats/management/commands/migrate.py: Removed app argument. Try
to split first name and last name. Use svn_accound or email for
username.
* stats/models.py: Updated Person and Team classes to respectively
inherit from User and Group. Replaced too short CharField by
URLField. Removed duplicate fields (with Django Auth ones). Team
and Person are now associated by Django.
* stats/utils.py: PEP-8 changes.
Modified:
branches/djamnedlies/ChangeLog
branches/djamnedlies/stats/management/commands/migrate.py
branches/djamnedlies/stats/models.py
branches/djamnedlies/stats/utils.py
Modified: branches/djamnedlies/stats/management/commands/migrate.py
==============================================================================
--- branches/djamnedlies/stats/management/commands/migrate.py (original)
+++ branches/djamnedlies/stats/management/commands/migrate.py Wed Oct 22 21:48:50 2008
@@ -1,6 +1,6 @@
-from django.core.management.base import BaseCommand
import os
-
+import sys
+from django.core.management.base import BaseCommand
from stats.models import Person, Team, Language, Module, Branch, Domain, Release, Category, Statistics
class Command(BaseCommand):
@@ -10,11 +10,10 @@
output_transaction = False
xml_base = "/home/claude/Bureau/TraductionsGNOME/damned-lies/trunk"
- import sys
- sys.path.append (xml_base)
+ sys.path.append(xml_base)
import data
- def handle(self, app, **options):
+ def handle(self, **options):
#drop table language;drop table module;drop table module_maintainer;drop table person;drop table release;drop table category;drop table team;drop table branch;
print self.migratePeople()
@@ -29,14 +28,29 @@
def migratePeople(self):
people = self.data.readFromFile(os.path.join(self.xml_base, "people.xml.in"))
for key, p in people.items():
+
if not p.has_key('bugzilla-account'):
p['bugzilla-account'] = None
+
if p['id'][:2] != "x-":
p['svn-account'] = p['id']
else:
p['svn-account'] = None
- new_p = Person(old_id=p['id'], name=p['name'],
- email=p['email'], svn_account=p['svn-account'], image=p['icon'],
+
+ # WARNING The old data model stores first_name and
+ # last_name in the same field.
+ # This rule won't work in all cases.
+ l_name = p['name'].split()
+ first_name = l_name[0]
+ last_name = ' '.join(l_name[1:])
+ # Claude, please have a look at this and the username (unique key)
+ print "Name '%s' becomes '%s' and '%s'" % (p['name'], first_name, last_name)
+ new_p = Person(_old_id=p['id'],
+ username=p['svn-account'] or p['email'][:30],
+ first_name=l_name[0],
+ last_name=' '.join(l_name[1:]),
+ email=p['email'],
+ svn_account=p['svn-account'], image=p['icon'],
webpage_url=p['webpage'], irc_nick=p['nick'],
bugzilla_account=p['bugzilla-account'])
new_p.save()
@@ -47,7 +61,7 @@
for key, team in teams.items():
if len(team['_language'].items()) <= 1:
team['_description'] = team['_language'].items()[0][1]['content']
- coord = Person.objects.get(old_id=team['coordinator'].keys()[0])
+ coord = Person.objects.get(_old_id=team['coordinator'].keys()[0])
if not team.has_key('mailing-list'):
team['mailing-list'] = None
if not team.has_key('mailing-list-subscribe'):
@@ -55,7 +69,7 @@
if not team.has_key('_description'):
team['_description'] = 'Catalan'
print "Forced Catalan description"
- new_t = Team(lang_code=key, description=team['_description'], coordinator=coord,
+ new_t = Team(name=key, description=team['_description'], coordinator=coord,
webpage_url=team['webpage'],
mailing_list=team['mailing-list'],
mailing_list_subscribe=team['mailing-list-subscribe'])
@@ -74,15 +88,21 @@
module[prop] = None
if not module.has_key('_description'):
module['_description'] = module['id']
- new_m = Module(name=module['id'], description=module['_description'],
- homepage=module['webpage'], comment=module['_comment'],
- bugs_base=module['bugs-baseurl'], bugs_product=module['bugs-product'], bugs_component=module['bugs-component'],
- vcs_type=module['scmroot']['type'], vcs_root=module['scmroot']['path'], vcs_web=module['scmweb'])
+ new_m = Module(name=module['id'],
+ description=module['_description'],
+ homepage=module['webpage'],
+ comment=module['_comment'],
+ bugs_base=module['bugs-baseurl'],
+ bugs_product=module['bugs-product'],
+ bugs_component=module['bugs-component'],
+ vcs_type=module['scmroot']['type'],
+ vcs_root=module['scmroot']['path'],
+ vcs_web=module['scmweb'])
new_m.save()
# Adding maintainers
if module.has_key('maintainer'):
for m in module['maintainer'].items():
- person = Person.objects.get(old_id=m[0])
+ person = Person.objects.get(_old_id=m[0])
new_m.maintainers.add(person)
# Adding branches
for bkey, bval in module['branch'].items():
Modified: branches/djamnedlies/stats/models.py
==============================================================================
--- branches/djamnedlies/stats/models.py (original)
+++ branches/djamnedlies/stats/models.py Wed Oct 22 21:48:50 2008
@@ -18,30 +18,53 @@
# along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import os, re, commands
+from time import tzname
from django.db import models, connection
+from django.contrib.auth.models import User, Group
from django.utils.translation import ungettext, ugettext as _, ugettext_noop as N_
from stats.conf import settings
from stats import utils
-from time import tzname
-import os, sys, re, commands
import potdiff
-class Person(models.Model):
- old_id = models.CharField(max_length=50)
- name = models.CharField(max_length=50)
- email = models.CharField(max_length=50)
- svn_account = models.CharField(max_length=20, null=True)
- image = models.CharField(max_length=50, null=True)
- webpage_url = models.CharField(max_length=50, null=True)
- irc_nick = models.CharField(max_length=20, null=True)
- bugzilla_account = models.CharField(max_length=50, null=True)
+class Person(User):
+ """ The User class of D-L. """
+
+ # Deprecated - This field will be removed after the first
+ # production deployment
+ _old_id = models.CharField(max_length=50)
+
+ svn_account = models.SlugField(max_length=20, null=True)
+ image = models.URLField(null=True)
+ webpage_url = models.URLField(null=True)
+ irc_nick = models.SlugField(max_length=20, null=True)
+ bugzilla_account = models.SlugField(null=True)
+
class Meta:
db_table = 'person'
- def nospamemail(self):
- return utils.obfuscateEmail(self.email)
- def nospambugzillaaccount(self):
- return utils.obfuscateEmail(self.bugzilla_account)
+ def no_spam_email(self):
+ return utils.obfuscate_email(self.email)
+
+ def no_spam_bugzilla_account(self):
+ return utils.obfuscate_email(self.bugzilla_account)
+
+
+class Team(Group):
+ """ The name of the team is stored in Group.name.
+ The lang_code is generally used. """
+
+ description = models.TextField()
+ coordinator = models.ForeignKey('Person')
+ webpage_url = models.URLField(null=True)
+ mailing_list = models.URLField(null=True)
+ mailing_list_subscribe = models.URLField(null=True)
+
+ class Meta:
+ db_table = 'team'
+
+ def __unicode__(self):
+ return self.description
class Language(models.Model):
name = models.CharField(max_length=50)
@@ -63,24 +86,10 @@
for rel in releases:
stats.append(rel.total_for_lang(self))
return stats
-
-class Team(models.Model):
- lang_code = models.CharField(max_length=15, unique=True)
- description = models.TextField()
- coordinator = models.ForeignKey('Person')
- webpage_url = models.CharField(max_length=50, null=True)
- mailing_list = models.CharField(max_length=50, null=True)
- mailing_list_subscribe = models.CharField(max_length=50, null=True)
-
- class Meta:
- db_table = 'team'
-
- def __unicode__(self):
- return self.description
class Module(models.Model):
name = models.CharField(max_length=50)
- homepage = models.CharField(max_length=50, null=True)
+ homepage = models.URLField(null=True)
description = models.TextField(null=True)
comment = models.TextField(null=True)
bugs_base = models.CharField(max_length=50)
@@ -91,8 +100,8 @@
('git', 'Git'),
('hg', 'Mercurial'),
('bzr', 'Bazaar')))
- vcs_root = models.CharField(max_length=50)
- vcs_web = models.CharField(max_length=50)
+ vcs_root = models.URLField()
+ vcs_web = models.URLField()
maintainers = models.ManyToManyField(Person, db_table='module_maintainer')
class Meta:
Modified: branches/djamnedlies/stats/utils.py
==============================================================================
--- branches/djamnedlies/stats/utils.py (original)
+++ branches/djamnedlies/stats/utils.py Wed Oct 22 21:48:50 2008
@@ -23,7 +23,7 @@
from stats.conf import settings
import sys, os, re, time, commands
-def obfuscateEmail(email):
+def obfuscate_email(email):
if email:
return email.replace('@', ' at ').replace('.', ' dot ')
return ""
@@ -258,7 +258,7 @@
s.sendmail(settings.WHOAREWE, settings.NOTIFICATIONS_TO, msg.as_string())
s.close()
-class Profiler():
+class Profiler(object):
def __init__(self):
self.start = time.clock()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]