from django.db import models from django.conf import settings try: GITBROWSE_BASE = settings.GITBROWSE_BASE except AttributeError: GITBROWSE_BASE='/home' try: ADMIN_URL = settings.ADMIN_URL except AttributeError: ADMIN_URL='/admin' if ADMIN_URL[-1] == '/': ADMIN_URL=ADMIN_URL[:-1] # Create your models here. class Repository(models.Model): path = models.FilePathField("relative path to repository", path=GITBROWSE_BASE,recursive=True,match="^.*\.git$",unique=True,blank=False) #path = models.FilePathField("relative path to repository", path='/home/bnewbold/code/',recursive=True,match=".*\.git$",unique=True,blank=False) name = models.CharField(_("name"), maxlength=80) slug = models.SlugField(prepopulate_from=("path",),unique=True) git_version = models.CharField(_("git version"), maxlength=100,default="git version 1.4.4", blank=True, help_text="Output of \'git --version\'") description = models.TextField("description of repo",blank=True) class Admin: ordering = ['slug'] def __str__(self): return self.name def get_absolute_url(self): return "/code/%s/" % self.slug def get_admin_url(self): return "%s/code/repository/%s/" % (ADMIN_URL, self.slug) class Tree(models.Model): repo = models.ForeignKey(Repository) mode = models.CharField("file mode/permissions", blank=False,maxlength=4) path = models.CharField("relative path from repo base", maxlength=512) id = models.CharField("hash", maxlength=40,blank=False,primary_key=True) name = models.CharField("name of dir", maxlength=128,blank=False) type = 'tree' class Admin: ordering = ['repo','path'] def __str__(self): return self.name def get_absolute_url(self): return "/code/%s/%s" % (self.repo.slug, self.hash) def get_admin_url(self): return "%s/code/tree/%s/" % (ADMIN_URL, self.id) def tree_from_str(s): s = s.split(); if len(s) != 4: return return Tree(mode=s[0],id=s[2],name=s[3]) class Blob(models.Model): repo = models.ForeignKey(Repository) mode = models.CharField("file mode/permissions", blank=False,maxlength=4) path = models.CharField("relative path from repo base", maxlength=512) id = models.CharField("hash", maxlength=40,blank=False,primary_key=True) name = models.CharField("name of dir", maxlength=128,blank=False) type='blob' class Admin: ordering = ['repo','path'] def __str__(self): return self.name def get_absolute_url(self): return "/code/%s/%s" % (self.repo.slug, self.hash) def get_admin_url(self): return "%s/code/tree/%s/" % (ADMIN_URL, self.id) def blob_from_str(s): s = s.split(); if len(s) != 4: return return Blob(mode=s[0],id=s[2],name=s[3])