Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 61ae0ca

Browse files
committed
Migration browsefiles to django
1 parent 01a069f commit 61ae0ca

5 files changed

Lines changed: 51 additions & 70 deletions

File tree

app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
(re.compile(r'/\w+/\w+/commits'), django_app),
3535
(re.compile(r'/\w+/\w+/blame'), django_app),
3636
(re.compile(r'/\w+/\w+/raw'), django_app),
37+
(re.compile(r'/\w+/\w+/browsefiles'), django_app),
3738
(re.compile(r'/vilya'), django_app),
3839
(re.compile(r'/.*'), web)]
3940

vilya/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/raw/(?P<revision>\w+)/(?P<path>.*)$', project.ProjectRawView.as_view(), name="project_raw"),
106106
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/commits/(?P<revision>\w+)/(?P<path>.*)$', project.ProjectCommitsView.as_view(), name="project_commits"),
107107
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/tree/(?P<revision>\w+)/(?P<path>.*)$', project.ProjectTreeView.as_view(), name="project_tree"),
108+
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/browsefiles/?$', project.browsefiles, name="project_browsefiles"),
108109
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/watchers/?$', project.watchers, name="project_watchers"),
109110
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/forkers/?$', project.forkers, name="project_forkers"),
110111
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/archive/(?P<revision>\w+)/?$', project.archive, name="project_archive"),

vilya/views/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from vilya.libs.text import render_markdown
99
from vilya.libs.template import st, request
1010
from vilya.views.uis.graph import GraphUI
11-
from vilya.views.uis.browsefiles import BrowsefilesUI
1211
from vilya.views.uis.sphinx_docs import SphinxDocsUI
1312
from vilya.views.uis.docs import DocsUI
1413
from vilya.views.uis.source import SourceUI
@@ -128,7 +127,7 @@ def _q_lookup(self, request, url_part):
128127
class CodeUI:
129128
_q_exports = [
130129
'hooks', 'graph', 'commit', 'pull', 'newpull', 'comments',
131-
'compare', 'line_comments', 'browsefiles', 'pulls',
130+
'compare', 'line_comments', 'pulls',
132131
'docs', 'remove', 'code_review', 'pr_comment', 'issues',
133132
'issue_comments', 're_index_docs', 'src_index',
134133
'search', 'pages', 'xdocs', 'dashboard',
@@ -220,10 +219,6 @@ def code_review(self):
220219
def pr_comment(self):
221220
return PrCommentUI(self.proj_name)
222221

223-
@property
224-
def browsefiles(self):
225-
return BrowsefilesUI(self.proj_name)
226-
227222
@property
228223
def docs(self):
229224
return SphinxDocsUI(self.proj_name)

vilya/views/django/project.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,51 @@ def _make_links(project, rev, author, path, page, query):
595595
'graph_data': graph_data,
596596
})
597597
return tdt
598+
599+
600+
def browsefiles(request, username, projectname):
601+
from vilya.models.project import CodeDoubanProject
602+
603+
def _add_file_type_and_warns(node):
604+
code_file_exts = 'py rb c h html mako ptl js css less handlebars coffee sql'.split() # noqa
605+
bad_exts = 'pyc exe'.split()
606+
node_ext = node['path'].rsplit('.')[1] if '.' in node['path'] else ''
607+
if node['type'] == 'tree':
608+
icon_type = 'directory'
609+
elif node['type'] == 'commit':
610+
icon_type = 'submodule'
611+
elif node_ext in code_file_exts:
612+
icon_type = 'code-file'
613+
else:
614+
icon_type = 'text-file'
615+
node['icon-type'] = icon_type
616+
if node_ext in bad_exts:
617+
node['warn'] = 'bad'
618+
else:
619+
node['warn'] = 'no'
620+
return node
621+
622+
name = '/'.join([username, projectname])
623+
624+
if 'json' in request.environ['HTTP_ACCEPT']:
625+
output = 'json'
626+
else:
627+
output = 'html'
628+
project = CodeDoubanProject.get_by_name(name)
629+
user = request.user
630+
path = request.GET.get('path', '')
631+
rev = request.GET.get('rev', project.default_branch)
632+
allfiles = project.repo.get_tree(rev, path=path)
633+
allfiles = [_add_file_type_and_warns(f) for f in allfiles]
634+
errors = ''
635+
ref = rev
636+
if ref is None:
637+
ref = project.default_branch
638+
branches = project.repo.branches
639+
tags = project.repo.tags
640+
ref_type = 'branch' if ref in branches else 'tag' \
641+
if ref in tags else 'tree'
642+
if output == 'json':
643+
return HttpResponse(json.dumps(allfiles))
644+
else:
645+
return HttpResponse(st('browsefiles.html', **locals()))

vilya/views/uis/browsefiles.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)