euscanwww: Basic user dashboard

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-07-14 13:56:21 +02:00
parent aa09812f6f
commit bd2af29ff7
5 changed files with 149 additions and 19 deletions

View File

@ -74,3 +74,35 @@ class catch_and_return(object):
except self.err:
return self.response
return wrapper
def get_account_categories(user):
from djeuscan.models import Package, CategoryAssociation
# TODO: This is quite ugly
category_names = [obj.category for obj in
CategoryAssociation.objects.filter(user=user)]
return [c for c in Package.objects.categories()
if c["category"] in category_names]
def get_account_herds(user):
from djeuscan.models import Package, HerdAssociation
ids = [obj.herd.pk for obj in
HerdAssociation.objects.filter(user=user)]
return Package.objects.herds(ids=ids)
def get_account_maintainers(user):
from djeuscan.models import Package, MaintainerAssociation
ids = [obj.maintainer.pk for obj in
MaintainerAssociation.objects.filter(user=user)]
return Package.objects.maintainers(ids=ids)
def get_account_packages(user):
from djeuscan.models import PackageAssociation
return [obj.package for obj in
PackageAssociation.objects.filter(user=user)]

View File

@ -1,5 +1,6 @@
{% extends "_base.html" %}
{% load url from future %}
{% load sub %}
{% block title %}
{{ block.super }} - Welcome {{ user }}
@ -8,4 +9,88 @@
{% block content %}
<h2>Welcome {{ user }}</h2>
<h3 class="padded">Summary</h3>
<div class="row-fluid padded">
<div class="padded span6">
{% with categories|length as num_categories %}
Watching {{ num_categories }} categor{{ num_categories|pluralize:"y,es"}}
<ul>
<li>{{ categories_upstream }} new upstream version{{ categories_upstream|pluralize:"s"}}</li>
{% if categories_upstream %}
<li>
Hot categories:
<ul>
{% for c in categories|slice:":3" %}
<li><a href="{% url "category" c.category %}">{{ c.category }}</a> ({{ c.n_versions|sub:c.n_packaged }})</li>
{% endfor %}
</ul>
</li>
{% endif %}
</ul>
{% endwith %}
</div>
<div class="padded span6">
{% with herds|length as num_herds %}
Watching {{ num_herds }} herd{{ num_herds|pluralize:"s"}}
<ul>
<li>{{ herds_upstream }} new upstream version{{ herds_upstream|pluralize:"s"}}</li>
{% if herds_upstream %}
<li>
Hot herds:
<ul>
{% for c in herds|slice:":3" %}
<li><a href="{% url "herd" c.herds__herd %}">{{ c.herds__herd }}</a> ({{ c.n_versions|sub:c.n_packaged }})</li>
{% endfor %}
</ul>
</li>
{% endif %}
</ul>
{% endwith %}
</div>
</div>
<div class="padded row-fluid">
<div class="padded span6">
{% with maintainers|length as num_maintainers %}
Watching {{ num_maintainers }} maintainer{{ num_maintainers|pluralize:"s"}}
<ul>
<li>{{ maintainers_upstream }} new upstream version{{ maintainers_upstream|pluralize:"s"}}</li>
{% if maintainers_upstream %}
<li>
Hot maintainers:
<ul>
{% for c in maintainers|slice:":3" %}
<li><a href="{% url "maintainer" c.maintainers__id %}">{{ c.maintainers__name }}</a> ({{ c.n_versions|sub:c.n_packaged }})</li>
{% endfor %}
</ul>
</li>
{% endif %}
</ul>
{% endwith %}
</div>
<div class="padded span6">
{% with packages|length as num_packages %}
Watching {{ num_packages }} package{{ num_packages|pluralize:"s"}}
<ul>
<li>{{ packages_upstream }} new upstream version{{ packages_upstream|pluralize:"s"}}</li>
{% if packages_upstream %}
<li>
Hot packages:
<ul>
{% for c in packages|slice:":3" %}
<li><a href="{% url "package" c.category c.name %}">{{ c }}</a> ({{ c.n_versions|sub:c.n_packaged }})</li>
{% endfor %}
</ul>
</li>
{% endif %}
</ul>
{% endwith %}
</div>
</div>
{% endblock %}

View File

@ -36,6 +36,6 @@
</td>
</tr>
</table>
<input type="hidden" name="next" value="/" />
<input type="hidden" name="next" value="{% url "accounts_index" %}" />
</form>
{% endblock %}

View File

@ -8,7 +8,9 @@ from django.shortcuts import get_object_or_404
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_POST
from djeuscan.helpers import version_key, packages_from_names
from djeuscan.helpers import version_key, packages_from_names, \
get_account_categories, get_account_herds, get_account_maintainers, \
get_account_packages
from djeuscan.models import Version, Package, Herd, Maintainer, EuscanResult, \
VersionLog, RefreshPackageQuery, HerdAssociation, MaintainerAssociation, \
CategoryAssociation, PackageAssociation, OverlayAssociation, ProblemReport
@ -359,43 +361,50 @@ def refresh_package(request, category, package):
@login_required
@render_to('euscan/accounts/index.html')
def accounts_index(request):
return {}
upstream_k = lambda c: c["n_versions"] - c["n_packaged"]
categories = sorted(get_account_categories(request.user),
key=upstream_k, reverse=True)
c_upstream = sum([c["n_versions"] - c["n_packaged"] for c in categories])
herds = sorted(get_account_herds(request.user),
key=upstream_k, reverse=True)
h_upstream = sum([c["n_versions"] - c["n_packaged"] for c in herds])
maintainers = sorted(get_account_maintainers(request.user),
key=upstream_k, reverse=True)
m_upstream = sum([c["n_versions"] - c["n_packaged"] for c in maintainers])
packages = sorted(get_account_packages(request.user),
key=lambda p: p.n_versions - p.n_packaged, reverse=True)
p_upstream = sum([c.n_versions - c.n_packaged for c in packages])
return {
"categories": categories, "categories_upstream": c_upstream,
"herds": herds, "herds_upstream": h_upstream,
"maintainers": maintainers, "maintainers_upstream": m_upstream,
"packages": packages, "packages_upstream": p_upstream,
}
@login_required
@render_to('euscan/accounts/categories.html')
def accounts_categories(request):
category_names = [obj.category for obj in
CategoryAssociation.objects.filter(user=request.user)]
categories = [c for c in Package.objects.categories()
if c["category"] in category_names]
return {"categories": categories}
return {"categories": get_account_categories(request.user)}
@login_required
@render_to('euscan/accounts/herds.html')
def accounts_herds(request):
ids = [obj.herd.pk for obj in
HerdAssociation.objects.filter(user=request.user)]
herds = Package.objects.herds(ids=ids)
return {"herds": herds}
return {"herds": get_account_herds(request.user)}
@login_required
@render_to('euscan/accounts/maintainers.html')
def accounts_maintainers(request):
ids = [obj.maintainer.pk for obj in
MaintainerAssociation.objects.filter(user=request.user)]
maintainers = Package.objects.maintainers(ids=ids)
return {"maintainers": maintainers}
return {"maintainers": get_account_maintainers(request.user)}
@login_required
@render_to('euscan/accounts/packages.html')
def accounts_packages(request):
packages = [obj.package for obj in
PackageAssociation.objects.filter(user=request.user)]
return {"packages": packages}
return {"packages": get_account_packages(request.user)}
@login_required

View File

@ -234,6 +234,10 @@ th {
border-radius: 10px;
}
.padded {
padding: 10px;
}
textarea {
width: inherit;
}