aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-10-02 11:18:46 -0400
committerBobby <[email protected]>2022-10-02 11:18:46 -0400
commitfb1225d85d9291a394e9b371231b02a85272d121 (patch)
tree4cd3fad8990d931e827026c12c37e3d5a20a7efc
parent8d8192ee4204ab6a9680a3103bbe14292c70b39a (diff)
downloadthatcomputerscientist-fb1225d85d9291a394e9b371231b02a85272d121.tar.xz
thatcomputerscientist-fb1225d85d9291a394e9b371231b02a85272d121.zip
source code rendered through a single function
-rw-r--r--dev_status/urls.py7
-rw-r--r--dev_status/views.py66
-rw-r--r--templates/blog/partials/base.html2
-rw-r--r--templates/dev_status/home.html41
4 files changed, 47 insertions, 69 deletions
diff --git a/dev_status/urls.py b/dev_status/urls.py
index c9bcf35a..acbd96dc 100644
--- a/dev_status/urls.py
+++ b/dev_status/urls.py
@@ -4,8 +4,7 @@ from . import views
app_name = 'dev_status'
urlpatterns = [
- path('', views.home, name='home'),
- path('tree/', views.tree, name='roottree'),
- path('tree/<path:path>', views.tree, name='tree'),
- path('raw/<path:path>', views.raw, name='raw'),
+ path('<str:r>', views.home, name='repo'),
+ path('<str:r>/<path:p>', views.home, name='repo-path'),
+ path('', RedirectView.as_view(url='thatcomputerscientist'))
]
diff --git a/dev_status/views.py b/dev_status/views.py
index 1d511293..5b607436 100644
--- a/dev_status/views.py
+++ b/dev_status/views.py
@@ -1,3 +1,4 @@
+from multiprocessing import context
from django.shortcuts import render
from github import Github
from dotenv import load_dotenv
@@ -7,46 +8,27 @@ load_dotenv()
# Create your views here.
-def home(request):
+def home(request, r='thatcomputerscientist', p=None):
g = Github(os.getenv('GH_TOKEN'))
- repo = g.get_repo('luciferreeves/thatcomputerscientist')
- contents = repo.get_contents('')
- files = []
- while contents:
- file_content = contents.pop(0)
- files.append(file_content)
- context = {
- 'title': 'Source Code',
- 'files': files,
- }
- return render(request, 'dev_status/home.html', context)
-
-def tree(request, path=None):
- g = Github(os.getenv('GH_TOKEN'))
- repo = g.get_repo('luciferreeves/thatcomputerscientist')
- path = '' if not path else path
- parent = '' if len(path.split('/')) == 1 else '/'.join(path.split('/')[:-1])
- contents = repo.get_contents(path)
- files = []
- while contents:
- file_content = contents.pop(0)
- files.append(file_content)
- context = {
- 'title': 'Tree - {}'.format(path),
- 'files': files,
- 'parent': parent,
- }
- return render(request, 'dev_status/home.html', context)
-
-def raw(request, path):
- g = Github(os.getenv('GH_TOKEN'))
- repo = g.get_repo('luciferreeves/thatcomputerscientist')
- path = '' if not path else path
- parent = '' if len(path.split('/')) == 1 else '/'.join(path.split('/')[:-1])
- contents = repo.get_contents(path)
- context = {
- 'title': 'File - {}'.format(path),
- 'file': contents.html_url,
- 'parent': parent,
- }
- return render(request, 'dev_status/home.html', context) \ No newline at end of file
+ repository = 'luciferreeves/{}'.format(r)
+ parent = None
+ if p and not len(p.split('/')) == 0:
+ parent = '/'.join(p.split('/')[:-1])
+ contents = g.get_repo(repository).get_contents(p or '')
+ context = {}
+ try:
+ files = []
+ while contents:
+ file_content = contents.pop(0)
+ files.append(file_content)
+ context['title'] = 'Tree - {}'.format(p)
+ context['files'] = files
+ context['parent'] = parent
+ context['repo'] = r
+ except:
+ context['title'] = 'File - {}'.format(p)
+ context['file'] = contents.html_url
+ context['parent'] = parent
+ context['repo'] = r
+ finally:
+ return render(request, 'dev_status/home.html', context) \ No newline at end of file
diff --git a/templates/blog/partials/base.html b/templates/blog/partials/base.html
index d041c785..e3bf685a 100644
--- a/templates/blog/partials/base.html
+++ b/templates/blog/partials/base.html
@@ -39,7 +39,7 @@
<div style="width: 1000px; margin: 20px auto;">
<ul class="topnav">
{% comment %} <img src="{% static 'images/gifs/new.gif' %}" alt="new" style="margin-left: 5px;"> {% endcomment %}
- <li class="new"><a href="{% url 'dev_status:home' %}">
+ <li class="new"><a href="{% url 'dev_status:repo' 'thatcomputerscientist' %}">
Source Code
</a></li>
{% if user.is_authenticated %}
diff --git a/templates/dev_status/home.html b/templates/dev_status/home.html
index 4736b712..1b282d95 100644
--- a/templates/dev_status/home.html
+++ b/templates/dev_status/home.html
@@ -13,31 +13,28 @@
<br>
<div class="files">
{% if parent %}
- <div class="file">
- <div class="ft-dir"></div>
- <a class="file-name" href="{% url 'dev_status:tree' parent %}">..</a>
- </div>
+ <div class="file">
+ <div class="ft-dir"></div>
+ <a class="file-name" href="{% url 'dev_status:repo-path' repo parent %}">..</a>
+ </div>
{% endif %}
{% if parent == '' %}
- <div class="file">
- <div class="ft-dir"></div>
- <a class="file-name" href="{% url 'dev_status:home' %}">..</a>
- </div>
- {% endif %}
- {% if files %}
- {% for file in files %}
<div class="file">
- <div class="ft-{{ file.type }}"></div>
- {% if file.type == 'dir' %}
- <a class="file-name" href="{% url 'dev_status:tree' file.path %}">{{ file.name }}</a>
- {% else %}
- <a class="file-name" href="{% url 'dev_status:raw' file.path %}">{{ file.name }}</a>
- {% endif %}
+ <div class="ft-dir"></div>
+ <a class="file-name" href="{% url 'dev_status:repo' repo %}">..</a>
</div>
- {% endfor %}
- {% endif %}
- {% if file %}
- <script src = "https://emgithub.com/embed-v2.js?target={{ file }}&style=github-dark-dimmed&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on"></script>
- {% endif %}
+ {% endif %}
+ {% if files %}
+ {% for file in files %}
+ <div class="file">
+ <div class="ft-{{ file.type }}"></div>
+ <a class="file-name" href="{% url 'dev_status:repo-path' repo file.path %}">{{ file.name }}</a>
+ </div>
+ {% endfor %}
+ {% endif %}
+ {% if file %}
+ <script src = "https://emgithub.com/embed-v2.js?target={{ file }}&style=github-dark-dimmed&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on"></script>
+ {% endif %}
+ </div>
</div>
{% endblock %}