Make git repos to be a Django model. So, a list of repos will be now in the DB, not in settings.py.

portnov [2008-06-20 09:11:12]
Make git repos to be a Django model. So, a list of repos will be now in the DB, not in settings.py.
Filename
pygit/models.py
pygit/pygit.py
settings.py
diff --git a/pygit/models.py b/pygit/models.py
index 71a8362..320f9d7 100644
--- a/pygit/models.py
+++ b/pygit/models.py
@@ -1,3 +1,17 @@
 from django.db import models
+from django.utils.translation import gettext_lazy as _

-# Create your models here.
+class GitRepo(models.Model):
+  name = models.CharField(_("Name"),max_length=64)
+  path = models.CharField(_("Path"),max_length=255)
+
+  def __unicode(self):
+    return self.name
+
+  class Meta:
+    ordering = ("name",)
+    verbose_name = _("Git repository")
+    verbose_name_plural = _("Git repositories")
+
+  class Admin:
+    pass
diff --git a/pygit/pygit.py b/pygit/pygit.py
index cef4d22..f13d44f 100644
--- a/pygit/pygit.py
+++ b/pygit/pygit.py
@@ -8,14 +8,18 @@ from django.conf import settings
 from django.core.cache import cache

 from decorators import count
+from models import GitRepo

 rp = None
 curr_path = None

+def get_repo(rid):
+  return GitRepo.objects.get(pk=rid)
+
 @count
 def open_repo(rid):
   global curr_path,rp
-  path = settings.REPOS[int(rid)]
+  path = get_repo(rid).path
   if rp and curr_path==path:
     return rp
   curr_path = path
@@ -34,7 +38,8 @@ def dirs(tree):

 @count
 def repos():
-  return [(i,basename(settings.REPOS[i])) for i in range(len(settings.REPOS))]
+  rs = GitRepo.objects.all()
+  return [(r.id,r.name) for r in rs]

 @count
 def description(rid):
@@ -59,7 +64,7 @@ def date(tp):
 def tarball(rid,branch):
   r = open_repo(rid)
   cid = r.commits(branch)[0].id_abbrev
-  name = basename(settings.REPOS[int(rid)])
+  name = get_repo(rid).name
   path = "/media/tarballs/%s-%s-%s.tar.gz" % (name,branch,cid)
   if not exists(settings.ROOT+path):
     f = gzip.open(settings.ROOT+path,'w')
diff --git a/settings.py b/settings.py
index 14b9c19..e673ff8 100644
--- a/settings.py
+++ b/settings.py
@@ -93,6 +93,7 @@ INSTALLED_APPS = (
     'mgmt',
     'kb',
     'dburls',
+    'pygit',
 )

 SHOW_BLOCKS = dict(
@@ -124,10 +125,6 @@ MENU_USER = [(u'Главная',BASE_URL+'/'),
              (u'KB', BASE_URL+'/kb/'),
              (u'Выход', BASE_URL+'/logout/')]

-REPOS = ['/home/portnov/www/projects',
-         '/home/portnov/www/projects/mgmt/hms',
-         '/home/portnov/git/pylambda']
-
 ROOT = "/home/portnov/www/projects/"

 COLORS = [(0.9,0.9,0.5),
ViewGit