gitar

Remove redundant stylesheet block

Author
Maarten Vangeneugden
Date
Sept. 21, 2020, 12:11 a.m.
Hash
d4d904472ad4ac0c585fc2111aec8cba0fbbf4c1
Parent
9c2a60bba78d07539089530006d4ddc3a05a3fc1
Modified files
templates/gitar/index.djhtml
views.py

templates/gitar/index.djhtml

0 additions and 5 deletions.

View changes Hide changes
1
1
{% load i18n %}
2
2
{% load static %}
3
3
4
4
{% block stylesheets %}
5
-
    {{ block.super }}
6
-
     <link href="{% static "website/gitar.css" %}" rel="stylesheet" media="screen, projection" />
7
-
{% endblock stylesheets %}
8
-
9
-
{% block title %}{% trans "Gitar | Index page" %}{% endblock title %}
10
5
11
6
{% block description %}
12
7
{% trans "My personal answer to GitHub." %}
13
8
{% endblock description %}
14
9
15
10
{% block header %}
16
11
<header>
17
12
    <h1>Gitar</h1>  
18
13
    <label for="nav-drawer-toggle"></label>
19
14
</header>
20
15
{% endblock header %}
21
16
22
17
{% block nav %}
23
18
<input id="nav-drawer-toggle" type="checkbox" />
24
19
<nav>
25
20
    <label for="nav-drawer-toggle"><!--🡨-->🡠</label>
26
21
    <h2></h2>
27
22
    {% for repository in repositories %}
28
23
    <a class="nav-link" href="{% url 'gitar-repository' repository_name=repository.name %}">
29
24
        {{ repository.name }}
30
25
    </a>
31
26
    {% endfor %}
32
27
    <hr class="half" />
33
28
    <a class="nav-link" href="{% url 'about-index' %}">{% trans "Front page" %}</a>
34
29
  </nav>
35
30
{% endblock nav %}
36
31
37
32
38
33
{% block main %}
39
34
40
35
{# with mdac=materialDesign_accentColor %} {# You'll see why this is handy shortly. #}
41
36
{# with mdc=materialDesign_color #}
42
37
<section class="emphasis">
43
38
    <h1>{% trans "About Gitar" %}</h1>
44
39
    <p>
45
40
        {% blocktrans %}
46
41
		Gitar is a simple web app to easily host Git repositories using the Django framework.
47
42
        It's a hobby project of me, to make it easy for
48
43
        people to scroll through the code I publish, in a read-only fashion. It
49
44
        makes use of
50
45
        <a href="https://pygments.org/" target="_blank">Pygments</a>
51
46
        to read the source files, and apply the appropriate syntax coloring.
52
47
        {% endblocktrans %}
53
48
	</p>
54
49
    <p>
55
50
        {% blocktrans %}All repositories are automatically updated when changes
56
51
        have been pushed to the server, without any manual intervention from me.
57
52
        Special attention goes to clean URL design, adhering to web standards,
58
53
        and responsive design across all screen types.{% endblocktrans %}
59
54
    </p>
60
55
    <p>
61
56
        {% blocktrans %}Gitar <b>is a project under development!</b>
62
57
        While it's certainly presentable, there's still a lot of room for improvement.<br />
63
58
        Also, if you happen to walk in while I'm working, it's possible you'll
64
59
        fall through the floor, so be warned =D{% endblocktrans %}
65
60
    </p>
66
61
</section>
67
62
<section>
68
63
    <h3>{% trans "Public repositories" %}</h3>
69
64
		{% for repository in repositories %} {# ARGH DON'T YOU LOVE THE READABILITY #}
70
65
            <p>
71
66
                <a class="btn fill" href="{% url 'gitar-repository' repository_name=repository.name %}">
72
67
                    {{ repository.name }}
73
68
                </a>
74
69
                {{ repository.description }} 
75
70
            </p>
76
71
            <dl>
77
72
            <dt>🅿️</dt>
78
73
            <dd>{{ repository.programmingLanguage }}</dd>
79
74
                <!--<li><i class="material-icons">description</i> 
80
75
                    {{ repository.fileCount }}</li>-->
81
76
            <dt>©️</dt>
82
77
            <dd>{{ repository.license }}</dd>
83
78
            </dl>
84
79
            <hr class="half">
85
80
		{% endfor %}
86
81
</section>
87
82
{% endblock main %}
88
83

views.py

1 addition and 1 deletion.

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.shortcuts import get_object_or_404, render  # This allows to render the template with the view here. It's pretty cool and important.
18
18
from django.http import HttpResponseRedirect, HttpResponse
19
19
from django.urls import reverse
20
20
from .models import *
21
21
22
22
from .GitActions import RepoInfo
23
23
from django.utils.translation import ugettext as _
24
24
25
25
from django.utils.translation import ugettext as _
26
26
from git import Repo  # GitPython functionality.
27
27
import git
28
28
29
29
from .syntax import *
30
30
31
31
# First, I list some standard variables that are common for most of the sites of this app.
32
32
33
33
def footer_description():
34
34
    return _("Gitar is a simple web app that allows its users to easily share Git repos in combination with the Django framework.")
35
35
36
36
def footer_links():
37
37
    footer_links = [
38
38
            #['Source', 'OHGODHELPNOTDONEYET'],
39
39
            [_('Home page'), reverse('about-index')],
40
40
            [_('Source code'), reverse('gitar-repository', kwargs={'repository_name':'gitar'})],
41
41
            ]
42
42
    return footer_links
43
43
44
44
def standard_context():
45
45
    context = {
46
46
            'navbar_title': "Gitar",
47
47
            'navbar_backArrow': False,
48
48
            'footer_title': "Gitar",
49
49
            'footer_description': footer_description(),
50
50
            'footer_links': footer_links(),
51
51
            'stylesheet_name': "home",
52
-
            }
+
52
            }
53
53
    return context
54
54
55
55
# From here, the actual views start.
56
56
def index(request):
57
57
    """ The start page of Gitar.
58
58
59
59
    The goal of this view, is to collect all the available repositories,
60
60
    including some additional information, such as programming language,
61
61
    license, description, ... in order to give a fast overview of the most
62
62
    prominent information.
63
63
    """
64
64
65
65
    # Collecting the available repositories:
66
66
    # Template:
67
67
    template = "gitar/index.djhtml"
68
68
    # Requesting the repositories:
69
69
    modelRepos = Repository.objects.all()
70
70
    # From here, we start collecting info about all the repositories:
71
71
    class BlankRepository: pass  # Blank object in which all data will be collected.
72
72
    repositories = []
73
73
    for modelRepo in modelRepos:
74
74
        repository = BlankRepository()
75
75
        # TODO: Find a way to add all of modelRepo's fields without having to
76
76
        # hardcode them. This is prone to errors and is redundant.
77
77
        repository.name = str(modelRepo)
78
78
        repository.programmingLanguage = modelRepo.programmingLanguage
79
79
        repository.license = modelRepo.license
80
80
        repository.description = RepoInfo.get_description(modelRepo)
81
81
82
82
        #gitRepo = Repo.init(modelRepo.directory(), bare=True)  # Connects to the Git Repo.
83
83
        # See tests.py, which assures all repositories exist. Tests are handy.
84
84
        #repository.description = gitRepo.description
85
85
        # This is mostly personal taste, but I like to show the amount of files.
86
86
        #repoTree = gitRepo.heads.master.commit.tree
87
87
        #repository.fileCount = len(repoTree.blobs)  # blobs are files.
88
88
        repositories.append(repository)
89
89
    # After that, I extend the standard context with the repositories:
90
90
    context = standard_context()
91
91
    context['repositories'] = repositories
92
92
    # And finally, sending everything back.
93
93
    return render(request, template, context)
94
94
95
95
def commit(request, repository, commit):
96
96
    pass  # TODO
97
97
98
98
def repositories(request, repository_name, branch="master"):
99
99
    # A repo's root is a directory by default, so this will automatically return
100
100
    # a directory view. But still, this is a bit nicer.
101
101
    return path_explorer(request, repository_name, branch, "")
102
102
103
103
def path_explorer(request, repository_name, branch, path):
104
104
    """ Checks whether the given path is a file or a directory, and calls the
105
105
    appropriate view function accordingly.
106
106
    """
107
107
    repository = RepoInfo.get_repository_object(repository_name)
108
108
    # From the GitPython documentation:
109
109
    # You can obtain the tree object of a repository, which is the directory of
110
110
    # that repo. This tree can be accessed as if it were a native Python list,
111
111
    # where the elements are the subdirectories and files. So, the idea to
112
112
    # determine whether a file, or a directory was requested, is simple:
113
113
    # 1. Split the path with "/" as seperator.
114
114
    # 2. Replace the current tree variable with the one retrieved from the
115
115
    # subtree element
116
116
    # 3. Repeat 2. until all parts of the given path are exhausted.
117
117
    # If we now still have a tree, we're looking at a directory, so display the
118
118
    # files (and subdirectories) of this directory.
119
119
    # Else, if we hit a blob, display the file contents.
120
120
    path_parts = path.split(sep="/")
121
121
    # FIXME: This is a bug at the URL regex part that I haven't been able to fix
122
122
    # yet. This serves as a temporary fix:
123
123
    # If the last part of the path is an empty string (which happens when the
124
124
    # last symbol was a '/'), remove that part from the list.
125
125
    # Of course, this is bad monkeypatching, but I suck at regex, so as long as
126
126
    # I don't find the solution, this'll have to do.
127
127
128
128
129
129
    #print(path_parts)
130
130
131
131
    if path_parts[len(path_parts)-1] == "":
132
132
        path_parts.pop()
133
133
134
134
    if len(path_parts) == 0:
135
135
        directory = repository.heads[branch].commit.tree
136
136
        return directory_view(request, repository_name, branch, path, directory)
137
137
138
138
    assert len(path_parts) != 0
139
139
140
140
    # FIXME: If the user gives a "<something>/../<somethingElse>", that should
141
141
    # become "<something>". Obviously, although I think that's done by default
142
142
    # already.
143
143
    directory = repository.heads[branch].commit.tree
144
144
    for i in range(len(path_parts)):
145
145
        subdirectories = directory.trees
146
146
        #if len(subdirectories) == 0:
147
147
            # This can't happen, as this would imply there is a directory inside
148
148
            # a file.
149
149
        #    assert False
150
150
        #else:
151
151
        for subdirectory in subdirectories:
152
152
            if subdirectory.name == path_parts[i]:
153
153
                directory = subdirectory
154
154
                #break  # Useless optimization
155
155
    # When there are no more directories to traverse, check if the last part of
156
156
    # the path is either a file, or a directory:
157
157
    blobs = directory.blobs
158
158
    #print(path_parts)
159
159
    last_part = path_parts[len(path_parts)-1]
160
160
    for blob in directory.blobs:
161
161
        #print(blob.name)
162
162
        if blob.name == last_part:
163
163
            file_blob = blob
164
164
            #print("Returning file view")
165
165
            return file_view(request, repository_name, branch, path, file_blob)
166
166
        else:
167
167
            pass
168
168
            #print("blob name: " + blob.name)
169
169
            #print("last part: " + last_part)
170
170
    return directory_view(request, repository_name, branch, path, directory)
171
171
172
172
def directory_view(request, repository_name, branch, path, directory):
173
173
    """ Collects the given directories's files and subdirectories, and renders a
174
174
    template to display this data.
175
175
    """
176
176
177
177
    # Collecting files in this directory
178
178
    repository = RepoInfo.get_repository_object(repository_name)
179
179
    files = []
180
180
    for file in directory.blobs:
181
181
        files.append({
182
182
            "name":file.name,
183
183
            "path":file.path,
184
184
            "commit":"",#FileInfo.last_commit(repository, file).hexsha[:20],
185
185
            })
186
186
    # Collecting commits for this branch
187
187
    commits = []
188
188
    for commit in repository.iter_commits(branch):
189
189
        commits.append({
190
190
            "hash":commit.hexsha[:20],
191
191
            "author":commit.author,
192
192
            "description":commit.summary,
193
193
            })
194
194
    # Collecting subdirectories
195
195
    subdirectories = []
196
196
    for subdirectory in directory.trees:
197
197
        subdirectories.append({
198
198
            "path":subdirectory.path,
199
199
            "name":subdirectory.name,
200
200
            })
201
201
    # Collecting rendering information:
202
202
    template = "gitar/directory.djhtml"
203
203
    context = standard_context()
204
204
    context["files"] = files
205
205
    context["subdirectories"] = subdirectories
206
206
    context["commits"] = commits
207
207
    context["branch"] = branch
208
208
    context["repository_name"] = repository_name
209
209
    context["repository_description"] = repository.description
210
210
    # Collection repo information
211
211
    for repo in Repository.objects.all():
212
212
        if str(repo) == repository_name:
213
213
            context["repository_language"] = repo.programmingLanguage
214
214
            context["repository_license"] = repo.license
215
215
            break
216
216
    branches = []
217
217
    for bbranch in repository.heads:
218
218
        branches.append(bbranch.name)
219
219
    context["branches"] = branches
220
220
    return render(request, template, context)
221
221
222
222
223
223
def file_view(request, repository_name, branch, path, file):
224
224
    """ Collects the file contents of the given file path, and returns it to the
225
225
    template, with the file contents already formatted in HTML using Pygments.
226
226
    """
227
227
228
228
    # Turning the file's contents in HTML ready output:
229
229
    raw_file_data = file.data_stream.read()
230
230
    html_code = code_to_HTML(raw_file_data, file.name)
231
231
    # Collecting rendering information:
232
232
    template = "gitar/file.djhtml"
233
233
    context = standard_context()
234
234
    context["content"] = html_code
235
235
    context["file_name"] = file.name
236
236
    context["repository_name"] = repository_name
237
237
    return render(request, template, context)
238
238
    
239
239