models.py

1
""" models.py - Describes the models of Gitar.
2
    Copyright © 2016 Maarten "Vngngdn" Vangeneugden
3
4
    This program is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU Affero General Public License as
6
    published by the Free Software Foundation, either version 3 of the
7
    License, or (at your option) any later version.
8
9
    This program is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU Affero General Public License for more details.
13
14
    You should have received a copy of the GNU Affero General Public License
15
    along with this program. If not, see https://www.gnu.org/licenses/agpl.html.
16
"""
17
18
from django.db import models
19
20
# Create your models here.
21
class Repository(models.Model):
22
    # Repository itself, does not store a name, nor a description. These are
23
    # saved inside a git repo. "Repository" should store other info.
24
    """ The directory of the repository on the system. 
25
    
26
    This field contains the directory path from the repository, starting from
27
    the root directory (thus, start with a slash).
28
    """
29
    # FIXME: Django doesn't have a DirectoryPathField yet (it does have a
30
    # FilePathField). If it does in the future, change this field accordingly.
31
    directory_path = models.CharField(max_length=64)
32
    programmingLanguage = models.CharField(max_length=64) 
33
    # Most prominently used programming language
34
    license = models.CharField(max_length=64)  # The copyright license.
35
    #name = __str__()  # The name of the repository (defined by directory name)
36
37
    
38
    def __str__(self):
39
        # Removes the path leading to the actual directory (for example:
40
        # "/repos/public/code.git" becomes "code.git").
41
        directory_name = self.directory_path.rsplit(sep="/", maxsplit=1)[1]
42
        # Stripping ".git", returning the repository name:
43
        repository_name = directory_name.split(sep=".")[0]
44
        return repository_name
45
46
    class Meta:
47
        verbose_name_plural = "repositories"
48
49
# If I may be honest, I cannot believe I don't have more data structures than
50
# this. Maybe this'll change in the future, and I kinda hope so. =|
51