summaryrefslogtreecommitdiffstats
path: root/bn_django/git_browse/models.py
blob: 93a22b3715835de6eb9ae4cdc13ace507d93cb50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)