diff options
| author | Bobby <[email protected]> | 2022-10-02 11:18:46 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-10-02 11:18:46 -0400 |
| commit | fb1225d85d9291a394e9b371231b02a85272d121 (patch) | |
| tree | 4cd3fad8990d931e827026c12c37e3d5a20a7efc /dev_status | |
| parent | 8d8192ee4204ab6a9680a3103bbe14292c70b39a (diff) | |
| download | thatcomputerscientist-fb1225d85d9291a394e9b371231b02a85272d121.tar.xz thatcomputerscientist-fb1225d85d9291a394e9b371231b02a85272d121.zip | |
source code rendered through a single function
Diffstat (limited to 'dev_status')
| -rw-r--r-- | dev_status/urls.py | 7 | ||||
| -rw-r--r-- | dev_status/views.py | 66 |
2 files changed, 27 insertions, 46 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 |
