diff options
author | 2009-08-10 20:57:01 +0200 | |
---|---|---|
committer | 2009-08-10 20:57:01 +0200 | |
commit | cf75a67914798739e22e90ec134bd7a6b822b8b7 (patch) | |
tree | c95c20667caf32a4bc1d202b429cabbd290923a3 | |
parent | Prepared urls and settings for templates (diff) | |
download | collagen-cf75a67914798739e22e90ec134bd7a6b822b8b7.tar.gz collagen-cf75a67914798739e22e90ec134bd7a6b822b8b7.tar.bz2 collagen-cf75a67914798739e22e90ec134bd7a6b822b8b7.zip |
Basic functions of web working
This is really big commit, since there was no use putting in absolutely
non functional code until now.
Some templates might be simplified later on...
-rw-r--r-- | web/collagen/urls.py | 6 | ||||
-rw-r--r-- | web/collagen/views.py | 8 | ||||
-rw-r--r-- | web/main/__init__.py (renamed from web/collagen/__init__.py) | 0 | ||||
-rw-r--r-- | web/main/admin.py (renamed from web/collagen/admin.py) | 2 | ||||
l--------- | web/main/models.py (renamed from web/collagen/models.py) | 0 | ||||
-rw-r--r-- | web/main/urls.py | 16 | ||||
-rw-r--r-- | web/main/views.py | 91 | ||||
-rw-r--r-- | web/media/css/main.css | 35 | ||||
-rw-r--r-- | web/settings.py | 4 | ||||
-rw-r--r-- | web/templates/404.html | 11 | ||||
-rw-r--r-- | web/templates/500.html | 2 | ||||
-rw-r--r-- | web/templates/base.html | 32 | ||||
-rw-r--r-- | web/templates/browse-categories.html | 20 | ||||
-rw-r--r-- | web/templates/index.html | 19 | ||||
-rw-r--r-- | web/templates/list-packages-with-file.html | 9 | ||||
-rw-r--r-- | web/templates/view-content.html | 21 | ||||
-rw-r--r-- | web/templates/view-package-props.html | 33 | ||||
-rw-r--r-- | web/templates/view-package.html | 18 | ||||
-rw-r--r-- | web/urls.py | 3 |
19 files changed, 313 insertions, 17 deletions
diff --git a/web/collagen/urls.py b/web/collagen/urls.py deleted file mode 100644 index 5ac48ed..0000000 --- a/web/collagen/urls.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.conf.urls.defaults import * - - -urlpatterns = patterns('web.collagen.views', - (r'^$', 'index'), -) diff --git a/web/collagen/views.py b/web/collagen/views.py deleted file mode 100644 index 9c231bd..0000000 --- a/web/collagen/views.py +++ /dev/null @@ -1,8 +0,0 @@ -# Create your views here. - -from django.shortcuts import render_to_response -from web.collagen.models import Package - -def index(request): - last_pkgs = Package.objects.all().order_by('-id')[:5] - return render_to_response('index.html', {'latest_packages': last_pkgs}) diff --git a/web/collagen/__init__.py b/web/main/__init__.py index e69de29..e69de29 100644 --- a/web/collagen/__init__.py +++ b/web/main/__init__.py diff --git a/web/collagen/admin.py b/web/main/admin.py index a45bedb..97350cb 100644 --- a/web/collagen/admin.py +++ b/web/main/admin.py @@ -1,4 +1,4 @@ -from web.collagen.models import * +from web.main.models import * from django.contrib import admin admin.site.register(Package) diff --git a/web/collagen/models.py b/web/main/models.py index 92e8020..92e8020 120000 --- a/web/collagen/models.py +++ b/web/main/models.py diff --git a/web/main/urls.py b/web/main/urls.py new file mode 100644 index 0000000..2aa40d9 --- /dev/null +++ b/web/main/urls.py @@ -0,0 +1,16 @@ +from django.conf.urls.defaults import * +from django.conf import settings + +prefix = 'web.main.views.' + +urlpatterns = patterns('', + (r'^$', prefix+'index'), + (r'^browse$', prefix+'browse'), + (r'^browse/(?P<category_name>\w+-\w+)$', prefix+'browse'), + (r'^browse/(?P<category_name>\w+(-\w+){0,1})/(?P<pkg_name>.*)$', prefix+'browse'), + (r'^view/package/(?P<category_name>\w+(-\w*){0,1})/(?P<pkg_name>[a-zA-Z_-]+)-(?P<pkg_ver>[0-9_.r-]+)$', prefix+'view'), + (r'^view/attachment/(?P<attachment_id>\d+)$', prefix+'view_attachment'), + (r'^view/content/(?P<packageproperties_id>\d+)$', prefix+'view_content'), + (r'^search/by-path/(?P<path>.*)$', prefix+'search_by_path'), + (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_DIR, 'show_indexes': True}), +) diff --git a/web/main/views.py b/web/main/views.py new file mode 100644 index 0000000..a1cafe0 --- /dev/null +++ b/web/main/views.py @@ -0,0 +1,91 @@ +# Create your views here. + +from django.shortcuts import render_to_response, get_object_or_404 +from django.http import Http404,HttpResponse +from django.utils.html import escape +from django.core.exceptions import ObjectDoesNotExist + + +from web.main.models import * + +def index(request): + last_pkgs = Package.objects.all().order_by('-id')[:5] + cats = PackageCategory.objects.all() + print cats + return render_to_response('index.html', {'latest_packages': last_pkgs,'categories':cats}) + +def browse(request, category_name=None, pkg_name=None): + cats = PackageCategory.objects.all() + only_failed = False + if request.method == "GET" and "failed" in request.GET: + only_failed=True + if not category_name and not pkg_name: + if not only_failed: + cats = PackageCategory.objects.all() + else: + pprops = PackageProperties.objects.filter(error_code__gt=0) + cats = set() + for pprop in pprops: + cats.add(pprop.packageversion.category) + return render_to_response('browse-categories.html', {'objects':cats,'failed': only_failed}) + cat = PackageCategory.objects.get(name=category_name) + if category_name and not pkg_name: + pversions = cat.packageversion_set.all() + packages = set() + for pv in pversions: + pprops = pv.packageproperties_set.filter(error_code__gt=0) + if len(pprops) == 0 and only_failed: + continue + packages.add(pv.package.name) + return render_to_response('browse-categories.html',{'objects':packages,'category':cat, 'failed': only_failed}) + + pkg = Package.objects.get(name=pkg_name) + pversions = PackageVersion.objects.filter(package=pkg, category=cat) + + return render_to_response('view-package.html',{'pversions':pversions}) + + +def view(request, category_name, pkg_name, pkg_ver): + cat = PackageCategory.objects.get(name=category_name) + pkg = Package.objects.get(name=pkg_name) + pv = PackageVersion.objects.filter(package=pkg, category = cat, version = pkg_ver) + if not pv or len(pv) == 0: + raise Http404 + + pv = pv[0] + pprops = pv.packageproperties_set.all() + cpv = "%s/%s-%s" % (category_name, pkg_name, pkg_ver) + return render_to_response('view-package-props.html',{'pprops':pprops,'cpv':cpv}) + +def view_attachment(request, attachment_id): + try: + at = Attachment.objects.get(pk=attachment_id) + return HttpResponse(at.content, mimetype=at.mimetype) + except Attachment.DoesNotExist: + raise Http404 + + +def view_content(request, packageproperties_id): + try: + pp = PackageProperties.objects.get(pk=packageproperties_id) + ppfs = pp.packageproperties_file_set.order_by('file') + return render_to_response('view-content.html', {'ppfs':ppfs}) + except PackageProperties.DoesNotExist: + raise Http404 + + +def search_by_path(request, path): + if request.method == "GET" and "path" in request.GET: + path = request.GET["path"] + try: + file = File.objects.get(path=path) + ppfs = file.packageproperties_file_set.all() + cpvs = set() + for ppf in ppfs: + cpvs.add("%s/%s-%s" % (ppf.packageproperties.packageversion.category.name, + ppf.packageproperties.packageversion.package.name, + ppf.packageproperties.packageversion.version)) + cpvs = sorted(cpvs) + except File.DoesNotExist: + return render_to_response('404.html', {'path':path}) + return render_to_response('list-packages-with-file.html',{'cpvs': cpvs, 'path':path}) diff --git a/web/media/css/main.css b/web/media/css/main.css new file mode 100644 index 0000000..81ba1d2 --- /dev/null +++ b/web/media/css/main.css @@ -0,0 +1,35 @@ + +div.header { + background-color: black; + color: white; + font-weight: bolder; + font-size: x-large; + text-align: center; +} + +div.footer { + background-color: black; + color: white; + font-weight: bolder; +} + +div.compileinfo-odd { + background-color: #DDDAEC; +} + +div.intro { + font-size: 120%; + font-weight: bold; +} + +th { + background-color: #AF7BDB; +} + +tr.odd { + background-color: #DDDAEC; +} + +a:link { color: #0000ff; } +a:visited { color: #52188c; } + diff --git a/web/settings.py b/web/settings.py index abc2473..3608f13 100644 --- a/web/settings.py +++ b/web/settings.py @@ -72,10 +72,12 @@ TEMPLATE_DIRS = ( '/home/w0rm/Projects/GSoC/collagen/web/templates' ) +MEDIA_DIR = "/home/w0rm/Projects/GSoC/collagen/web/media" + INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', - 'web.collagen', + 'web.main', 'django.contrib.admin' ) diff --git a/web/templates/404.html b/web/templates/404.html new file mode 100644 index 0000000..716b7b3 --- /dev/null +++ b/web/templates/404.html @@ -0,0 +1,11 @@ + +{% extends "base.html" %} +{% block intro %}Not found<br />{% endblock %} + +{% block main %} +{% if path %} +Requested path was not found in any packages, sorry.<br /> +{% endif %} + +Whatever you were doing is lost. Please <a href="javascript:javascript:history.go(-1)">go back and try again</a>. +{% endblock %} diff --git a/web/templates/500.html b/web/templates/500.html new file mode 100644 index 0000000..5bf115d --- /dev/null +++ b/web/templates/500.html @@ -0,0 +1,2 @@ + +Internal server error, sorry diff --git a/web/templates/base.html b/web/templates/base.html new file mode 100644 index 0000000..57ff056 --- /dev/null +++ b/web/templates/base.html @@ -0,0 +1,32 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html> + <head> + <title>{% block title %}Collagen - browse categories{% endblock %}</title> + <link rel="stylesheet" href="/collagen/media/css/main.css" type="text/css" media="screen" /> + </head> + <body> + <div class="header"> + {% block header %} + Collagen - Gentoo portage tree files database + {% endblock %} + </div> + <br /> + <div class="main"> + <div class="intro"> + {% block intro %} + {% endblock %} + </div> + + + {% block main %} + How did you get here? + {% endblock %} + </div> + <br /> + <div class="footer"> + {% block footer %} + Gentoo Linux (c) 2009 + {% endblock %} + </div> + </body> +</html> diff --git a/web/templates/browse-categories.html b/web/templates/browse-categories.html new file mode 100644 index 0000000..52ad2fe --- /dev/null +++ b/web/templates/browse-categories.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block intro %} +We have information about these {% if category %}packages{% else %}categories{% endif %}: +{% endblock %} + +{% block main %} + +<ul> +{% for obj in objects %} + <li>{% if category %} + <a href="/collagen/browse/{{category.name}}/{{ obj }}{% if failed %}?failed{% endif %}">{{ obj }}/</a> + {% else %} + <a href="/collagen/browse/{{obj.name}}{% if failed %}?failed{% endif %}">{{ obj.name }}</a> + {% endif %} + </li> +{% endfor %} +</ul> + +{% endblock %} diff --git a/web/templates/index.html b/web/templates/index.html new file mode 100644 index 0000000..e2985e8 --- /dev/null +++ b/web/templates/index.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block intro %} +Collagen is here! +{% endblock %} + +{% block main %} + +You can use this web interface in several different ways: +<ul> + <li><a href="/collagen/browse">Browse packages</a></li> + <li><a href="/collagen/browse?failed">Browse only failed packages</a></li> + <li>Search packages containing certain path + <form method="get" action="/collagen/search/by-path"> + <input type="text" name="path" value="" /> + <button type="submit">Submit</button> + </form></li> +</ul> +{% endblock %} diff --git a/web/templates/list-packages-with-file.html b/web/templates/list-packages-with-file.html new file mode 100644 index 0000000..1b368f5 --- /dev/null +++ b/web/templates/list-packages-with-file.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block intro %}Packages containing file {{path}}<br />{% endblock %} + +{% block main %} +{% for cpv in cpvs %} +<a href="/collagen/view/package/{{cpv}}">{{cpv}}</a> <br /> +{% endfor %} + +{% endblock %} diff --git a/web/templates/view-content.html b/web/templates/view-content.html new file mode 100644 index 0000000..eb7d291 --- /dev/null +++ b/web/templates/view-content.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} + + +{% block main %} + +<table> +<tr> + <th>Type</th> + <th>Path</th> + <th>Hash</th> +</tr> + +{% for ppf in ppfs %} +<tr class="{% cycle odd,even %}"> + <td>{{ppf.filetype.name}}</td> + <td>{{ppf.file.path}} <a href="/collagen/search/by-path/{{ppf.file.path}}" title="see list of packages containing this file">[I]</a><br /></td> + <td>{{ppf.hash}}</td> +</tr> +{% endfor %} +</table> +{% endblock %} diff --git a/web/templates/view-package-props.html b/web/templates/view-package-props.html new file mode 100644 index 0000000..16e27ea --- /dev/null +++ b/web/templates/view-package-props.html @@ -0,0 +1,33 @@ +{% extends "base.html" %} + +{% block intro %} +Compile information for: {{cpv}} +{% endblock %} + +{% block main %} +{% if pprops %} + + + {% for prop in pprops %} + <div class="compileinfo-{% cycle odd,even %}"> + Portage profile: {{prop.profile.name}}<br /> + Error code: {{prop.error_code}} <br /> + Tinderbox IP: {{prop.tinderbox.ip}} <br /> + Useflags: {% for uf in prop.useflags.all %} + {{uf.name}} + {% endfor %} <br /> + Attachments: + {% for attachment in prop.attachment_set.all %} + <a href="/collagen/view/attachment/{{attachment.id}}">{{attachment.name}}</a> + {% endfor %}<br /> + Content: <a href="/collagen/view/content/{{prop.id}}">list</a> + </div> + <br /> + {% endfor %} + + +{% else %} + No information available +{% endif %} + +{% endblock %} diff --git a/web/templates/view-package.html b/web/templates/view-package.html new file mode 100644 index 0000000..847b878 --- /dev/null +++ b/web/templates/view-package.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} + +{% block intro %} +We have information about these package versions: +{% endblock %} + +{% block main %} +{% if pversions %} + <ul> + {% for pv in pversions %} + <li><a href="/collagen/view/package/{{pv.category.name}}/{{pv.package.name}}-{{pv.version}}">{{ pv.category.name }}/{{pv.package.name}}-{{pv.version}}</a></li> + {% endfor %} + </ul> +{% else %} + <p>No information available.</p> +{% endif %} + +{% endblock %} diff --git a/web/urls.py b/web/urls.py index 044e341..f614eed 100644 --- a/web/urls.py +++ b/web/urls.py @@ -1,12 +1,13 @@ from django.conf.urls.defaults import * + # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Example: - (r'^collagen/', include('web.collagen.urls')), + (r'^collagen/', include('web.main.urls')), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: |