Removed some old information from the previous version (That version had to be deleted, because it (accidentally) contained sensitive information). More deletions in the same sense may follow.
- Author
- Vngngdn
- Date
- Sept. 6, 2016, 5:59 p.m.
- Hash
- 49913600fa2dd9d6f70eb5480189de2e688e992c
- Parent
- e15cfdf9ce610943b6caa901b40bd1581227b894
- Modified file
- models.py
models.py ¶
0 additions and 13 deletions.
View changes Hide changes
1 |
1 |
Copyright © 2016 Maarten "Vngngdn" Vangeneugden |
2 |
2 |
|
3 |
3 |
This program is free software: you can redistribute it and/or modify |
4 |
4 |
it under the terms of the GNU Affero General Public License as |
5 |
5 |
published by the Free Software Foundation, either version 3 of the |
6 |
6 |
License, or (at your option) any later version. |
7 |
7 |
|
8 |
8 |
This program is distributed in the hope that it will be useful, |
9 |
9 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 |
11 |
GNU Affero General Public License for more details. |
12 |
12 |
|
13 |
13 |
You should have received a copy of the GNU Affero General Public License |
14 |
14 |
along with this program. If not, see https://www.gnu.org/licenses/agpl.html. |
15 |
15 |
""" |
16 |
16 |
|
17 |
17 |
from django.db import models |
18 |
18 |
from django.contrib.postgres.fields import ArrayField |
19 |
- | # About the ArrayField: |
20 |
- | # The ArrayField allows me to easily store multiple values in a single field. I |
21 |
- | # use this because a lot of my projects consist of more than 1 programming |
22 |
- | # language. The ArrayField allows me to easily store this multitude. |
23 |
- | # However, this also implies that Gitar is not database agnostic. |
24 |
- | # To make it database agnostic, I suggest an extra table that consists of |
25 |
- | # programming languages, which use a repository as a foreign key. If demand |
26 |
- | # for this is high enough, I'll do this, but for now, ArrayField is more handy. |
27 |
- | |
28 |
19 |
# Create your models here. |
29 |
20 |
class Repository(models.Model): |
30 |
21 |
# Repository itself, does not store a name, nor a description. These are |
31 |
22 |
# saved inside a git repo. "Repository" should store other info. |
32 |
23 |
# But why do I then store the name? Simple: this name is used in the |
33 |
- | # directory variable/member/whateverYouFancy. As such, the name must be |
34 |
- | # correct, otherwise, tests will fail. This way, I can rest assured that the |
35 |
- | # names in my database are 100% correct. |
36 |
- | """ The directory of the repository on the system. |
37 |
24 |
|
38 |
25 |
This field contains the directory path from the repository, starting from |
39 |
26 |
the root directory (thus, start with a slash). |
40 |
27 |
""" |
41 |
28 |
# FIXME: Django doesn't have a DirectoryPathField yet (it does have a |
42 |
29 |
# FilePathField). If it does in the future, change this field accordingly. |
43 |
30 |
directory_path = models.CharField(max_length=64) |
44 |
31 |
programmingLanguage = models.CharField(max_length=64) |
45 |
32 |
# Most prominently used programming language |
46 |
33 |
license = models.CharField(max_length=64) # The copyright license. |
47 |
34 |
|
48 |
35 |
|
49 |
36 |
def __str__(self): |
50 |
37 |
# Removes the path leading to the actual directory (for example: |
51 |
38 |
# "/repos/public/code.git" becomes "code.git"). |
52 |
39 |
directory_name = self.directory_path.rsplit(sep="/", maxsplit=1)[1] |
53 |
40 |
# Stripping ".git", returning the repository name: |
54 |
41 |
repository_name = directory_name.split(sep=".")[0] |
55 |
42 |
return repository_name |
56 |
43 |
|
57 |
44 |
class Meta: |
58 |
45 |
verbose_name_plural = "repositories" |
59 |
46 |
|
60 |
47 |
# If I may be honest, I cannot believe I don't have more data structures than |
61 |
48 |
# this. Maybe this'll change in the future, and I kinda hope so. =| |
62 |
49 |