2012-05-01 16:56:09 +02:00
|
|
|
""" Views """
|
|
|
|
|
2012-06-03 09:43:49 +02:00
|
|
|
import inspect
|
|
|
|
from annoying.decorators import render_to, ajax_request
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
from django.http import Http404
|
2011-04-15 00:24:45 +02:00
|
|
|
from django.shortcuts import get_object_or_404
|
2012-06-08 14:21:11 +02:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.views.decorators.http import require_POST
|
2011-04-14 19:28:38 +02:00
|
|
|
|
2012-07-26 14:37:03 +02:00
|
|
|
from djeuscan.helpers import version_key, packages_from_names, get_profile, \
|
|
|
|
get_account_categories, get_account_herds, get_account_maintainers
|
2012-05-01 16:56:09 +02:00
|
|
|
from djeuscan.models import Version, Package, Herd, Maintainer, EuscanResult, \
|
2012-07-26 14:37:03 +02:00
|
|
|
VersionLog, RefreshPackageQuery, ProblemReport, Category, Overlay
|
2012-08-08 10:46:36 +02:00
|
|
|
from djeuscan.forms import WorldForm, PackagesForm, ProblemReportForm, \
|
|
|
|
PreferencesForm
|
2012-06-08 14:21:11 +02:00
|
|
|
from djeuscan.tasks import admin_tasks
|
2012-05-13 14:09:22 +02:00
|
|
|
from djeuscan import charts
|
2011-04-25 22:27:32 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
@render_to('euscan/index.html')
|
|
|
|
def index(request):
|
2012-05-01 16:56:09 +02:00
|
|
|
context = {
|
|
|
|
'n_packaged': Package.objects.n_packaged(),
|
|
|
|
'n_overlay': Package.objects.n_overlay(),
|
|
|
|
'n_versions': Package.objects.n_versions(),
|
|
|
|
'n_upstream': Package.objects.n_upstream(),
|
|
|
|
'n_packages': Package.objects.count(),
|
|
|
|
'n_herds': Herd.objects.count(),
|
|
|
|
'n_maintainers': Maintainer.objects.count(),
|
|
|
|
}
|
2012-03-05 14:46:34 +01:00
|
|
|
try:
|
2012-05-01 21:15:55 +02:00
|
|
|
context['last_scan'] = EuscanResult.objects.latest().datetime
|
2012-03-05 14:46:34 +01:00
|
|
|
except EuscanResult.DoesNotExist:
|
2012-05-01 16:56:09 +02:00
|
|
|
context['last_scan'] = None
|
2012-03-05 14:46:34 +01:00
|
|
|
|
2012-05-01 16:56:09 +02:00
|
|
|
return context
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
@render_to('euscan/logs.html')
|
|
|
|
def logs(request):
|
|
|
|
return {}
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
@render_to('euscan/categories.html')
|
|
|
|
def categories(request):
|
2012-05-13 16:42:29 +02:00
|
|
|
try:
|
|
|
|
last_scan = EuscanResult.objects.latest().datetime
|
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
last_scan = None
|
|
|
|
|
|
|
|
return {'categories': Package.objects.categories(), 'last_scan': last_scan}
|
2011-04-25 22:27:32 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2011-11-15 17:08:29 +01:00
|
|
|
@render_to('euscan/category.html')
|
|
|
|
def category(request, category):
|
2012-05-05 10:54:04 +02:00
|
|
|
packages = Package.objects.for_category(category, last_versions=True)
|
2012-05-01 16:56:09 +02:00
|
|
|
|
2011-04-15 00:24:45 +02:00
|
|
|
if not packages:
|
|
|
|
raise Http404
|
2012-05-13 16:42:29 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
last_scan = \
|
|
|
|
EuscanResult.objects.for_category(category).latest().datetime
|
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
last_scan = None
|
|
|
|
|
2012-07-10 16:15:06 +02:00
|
|
|
favourited = False
|
|
|
|
if request.user.is_authenticated():
|
2012-07-28 11:39:38 +02:00
|
|
|
try:
|
|
|
|
category = Category.objects.get(name=category)
|
|
|
|
favourited = category in get_profile(request.user).categories.all()
|
|
|
|
except Category.DoesNotExist:
|
|
|
|
pass
|
2012-07-10 16:15:06 +02:00
|
|
|
|
|
|
|
return {'category': category, 'packages': packages, 'last_scan': last_scan,
|
|
|
|
'favourited': favourited}
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/herds.html')
|
|
|
|
def herds(request):
|
2012-05-01 16:56:09 +02:00
|
|
|
herds = Package.objects.herds()
|
2012-05-13 16:42:29 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
last_scan = EuscanResult.objects.latest().datetime
|
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
last_scan = None
|
|
|
|
|
|
|
|
return {'herds': herds, 'last_scan': last_scan}
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2011-11-15 17:08:29 +01:00
|
|
|
@render_to('euscan/herd.html')
|
|
|
|
def herd(request, herd):
|
2011-04-15 19:28:37 +02:00
|
|
|
herd = get_object_or_404(Herd, herd=herd)
|
2012-05-07 19:09:08 +02:00
|
|
|
packages = Package.objects.for_herd(herd, last_versions=True)
|
2012-05-13 16:42:29 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
last_scan = EuscanResult.objects.for_herd(herd).latest().datetime
|
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
last_scan = None
|
|
|
|
|
2012-07-10 16:15:06 +02:00
|
|
|
favourited = False
|
|
|
|
if request.user.is_authenticated():
|
2012-07-26 14:37:03 +02:00
|
|
|
if herd in get_profile(request.user).herds.all():
|
2012-07-10 16:15:06 +02:00
|
|
|
favourited = True
|
|
|
|
|
|
|
|
return {'herd': herd, 'packages': packages, "last_scan": last_scan,
|
|
|
|
'favourited': favourited}
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/maintainers.html')
|
|
|
|
def maintainers(request):
|
2012-05-01 16:56:09 +02:00
|
|
|
maintainers = Package.objects.maintainers()
|
2012-05-13 16:42:29 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
last_scan = EuscanResult.objects.latest().datetime
|
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
last_scan = None
|
|
|
|
|
|
|
|
return {'maintainers': maintainers, 'last_scan': last_scan}
|
2011-04-25 22:27:32 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2011-11-15 17:08:29 +01:00
|
|
|
@render_to('euscan/maintainer.html')
|
|
|
|
def maintainer(request, maintainer_id):
|
2012-05-01 21:15:55 +02:00
|
|
|
maintainer = get_object_or_404(Maintainer, pk=maintainer_id)
|
2012-05-05 10:54:04 +02:00
|
|
|
packages = Package.objects.for_maintainer(maintainer, last_versions=True)
|
2012-05-13 16:42:29 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
last_scan = \
|
|
|
|
EuscanResult.objects.for_maintainer(maintainer).latest().datetime
|
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
last_scan = None
|
|
|
|
|
2012-07-10 16:15:06 +02:00
|
|
|
favourited = False
|
|
|
|
if request.user.is_authenticated():
|
2012-07-26 14:37:03 +02:00
|
|
|
if maintainer in get_profile(request.user).maintainers.all():
|
2012-07-10 16:15:06 +02:00
|
|
|
favourited = True
|
|
|
|
|
|
|
|
return {'maintainer': maintainer, 'packages': packages,
|
|
|
|
'last_scan': last_scan, 'favourited': favourited}
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-13 08:50:24 +02:00
|
|
|
|
2011-11-23 18:03:07 +01:00
|
|
|
@render_to('euscan/overlays.html')
|
|
|
|
def overlays(request):
|
2012-05-01 16:56:09 +02:00
|
|
|
overlays = Package.objects.overlays()
|
2012-05-13 16:42:29 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
last_scan = EuscanResult.objects.latest().datetime
|
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
last_scan = None
|
|
|
|
|
|
|
|
return {'overlays': overlays, 'last_scan': last_scan}
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-11-23 18:03:07 +01:00
|
|
|
|
|
|
|
@render_to('euscan/overlay.html')
|
|
|
|
def overlay(request, overlay):
|
2012-05-12 16:07:49 +02:00
|
|
|
packages = Package.objects.for_overlay(overlay)
|
2011-11-23 18:03:07 +01:00
|
|
|
if not packages:
|
|
|
|
raise Http404
|
2012-05-13 16:42:29 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
last_scan = EuscanResult.objects.latest().datetime
|
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
last_scan = None
|
|
|
|
|
2012-07-10 16:15:06 +02:00
|
|
|
favourited = False
|
|
|
|
if request.user.is_authenticated():
|
2012-07-28 11:39:38 +02:00
|
|
|
try:
|
|
|
|
overlay = Overlay.objects.get(name=overlay)
|
|
|
|
favourited = overlay in get_profile(request.user).overlays.all()
|
|
|
|
except Overlay.DoesNotExist:
|
|
|
|
pass
|
2012-07-10 16:15:06 +02:00
|
|
|
|
|
|
|
return {'overlay': overlay, 'packages': packages, 'last_scan': last_scan,
|
|
|
|
'favourited': favourited}
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-11-23 18:03:07 +01:00
|
|
|
|
2011-11-15 17:08:29 +01:00
|
|
|
@render_to('euscan/package.html')
|
|
|
|
def package(request, category, package):
|
2011-04-15 00:24:45 +02:00
|
|
|
package = get_object_or_404(Package, category=category, name=package)
|
2012-03-14 14:07:28 +01:00
|
|
|
packaged = Version.objects.filter(package=package, packaged=True)
|
|
|
|
upstream = Version.objects.filter(package=package, packaged=False)
|
|
|
|
|
|
|
|
packaged = sorted(packaged, key=version_key)
|
|
|
|
upstream = sorted(upstream, key=version_key)
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
log = EuscanResult.objects.filter(package=package).\
|
|
|
|
order_by('-datetime')[:1]
|
2011-04-18 21:49:27 +02:00
|
|
|
log = log[0] if log else None
|
2012-05-05 11:48:12 +02:00
|
|
|
vlog = VersionLog.objects.for_package(package, order=True)
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2012-05-13 16:42:29 +02:00
|
|
|
try:
|
|
|
|
last_scan = EuscanResult.objects.for_package(package).latest().datetime
|
|
|
|
except EuscanResult.DoesNotExist:
|
|
|
|
last_scan = None
|
|
|
|
|
2012-06-14 10:03:49 +02:00
|
|
|
favourited = False
|
|
|
|
if request.user.is_authenticated():
|
2012-07-26 14:37:03 +02:00
|
|
|
if package in get_profile(request.user).packages.all():
|
2012-06-14 10:03:49 +02:00
|
|
|
favourited = True
|
|
|
|
|
2012-07-20 17:10:12 +02:00
|
|
|
try:
|
2012-07-27 12:21:48 +02:00
|
|
|
refresh_query = RefreshPackageQuery.objects.get(package=package)
|
2012-07-20 17:10:12 +02:00
|
|
|
except RefreshPackageQuery.DoesNotExist:
|
2012-07-27 12:21:48 +02:00
|
|
|
refresh_requested = False
|
|
|
|
refresh_pos = None
|
|
|
|
else:
|
|
|
|
refresh_requested = request.user in refresh_query.users.all()
|
|
|
|
refresh_pos = refresh_query.position
|
2012-07-20 17:10:12 +02:00
|
|
|
|
2012-07-25 16:52:10 +02:00
|
|
|
return {
|
|
|
|
'package': package,
|
|
|
|
'packaged': packaged,
|
|
|
|
'upstream': upstream,
|
|
|
|
'vlog': vlog,
|
2012-07-26 14:37:03 +02:00
|
|
|
'log': log,
|
2012-07-27 12:55:57 +02:00
|
|
|
'msg': log.messages if log else "",
|
2012-07-25 16:52:10 +02:00
|
|
|
'last_scan': last_scan,
|
|
|
|
'favourited': favourited,
|
2012-07-27 12:21:48 +02:00
|
|
|
'refresh_requested': refresh_requested,
|
|
|
|
'refresh_pos': refresh_pos,
|
2012-07-25 16:52:10 +02:00
|
|
|
}
|
|
|
|
|
2012-07-26 10:57:11 +02:00
|
|
|
|
2012-07-25 16:52:10 +02:00
|
|
|
@login_required
|
|
|
|
@render_to('euscan/problem.html')
|
|
|
|
def problem(request, category, package):
|
|
|
|
package = get_object_or_404(Package, category=category, name=package)
|
|
|
|
packaged = Version.objects.filter(package=package, packaged=True)
|
|
|
|
upstream = Version.objects.filter(package=package, packaged=False)
|
|
|
|
|
|
|
|
log = EuscanResult.objects.filter(package=package).\
|
|
|
|
order_by('-datetime')[:1]
|
|
|
|
log = log[0] if log else None
|
|
|
|
|
2012-07-09 14:29:42 +02:00
|
|
|
thanks_for_reporting = False
|
2012-07-25 16:52:10 +02:00
|
|
|
|
2012-07-09 14:29:42 +02:00
|
|
|
if request.method == "POST":
|
2012-07-25 16:52:10 +02:00
|
|
|
form = ProblemReportForm(package, request.POST)
|
|
|
|
if form.is_valid():
|
2012-07-09 14:29:42 +02:00
|
|
|
ProblemReport(
|
|
|
|
package=package,
|
2012-07-25 16:52:10 +02:00
|
|
|
version=form.cleaned_data["version"],
|
|
|
|
subject=form.cleaned_data["subject"],
|
|
|
|
message=form.cleaned_data["message"],
|
2012-07-09 14:29:42 +02:00
|
|
|
).save()
|
|
|
|
thanks_for_reporting = True
|
|
|
|
else:
|
2012-07-25 16:52:10 +02:00
|
|
|
form = ProblemReportForm(package)
|
2012-07-09 14:29:42 +02:00
|
|
|
|
2012-05-13 16:42:29 +02:00
|
|
|
return {
|
2012-07-25 16:52:10 +02:00
|
|
|
'form': form,
|
|
|
|
'thanks_for_reporting': thanks_for_reporting,
|
2012-05-13 16:42:29 +02:00
|
|
|
'package': package,
|
|
|
|
'packaged': packaged,
|
|
|
|
'upstream': upstream,
|
2012-07-27 12:55:57 +02:00
|
|
|
'msg': log.messages if log else "",
|
2012-05-13 16:42:29 +02:00
|
|
|
}
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-15 19:28:37 +02:00
|
|
|
|
|
|
|
@render_to('euscan/world.html')
|
|
|
|
def world(request):
|
2011-04-16 11:44:57 +02:00
|
|
|
world_form = WorldForm()
|
|
|
|
packages_form = PackagesForm()
|
2011-04-15 19:28:37 +02:00
|
|
|
|
2012-07-25 16:52:10 +02:00
|
|
|
return {
|
|
|
|
'world_form': world_form,
|
|
|
|
'packages_form': packages_form
|
2012-07-26 10:57:11 +02:00
|
|
|
}
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-15 19:28:37 +02:00
|
|
|
|
|
|
|
@render_to('euscan/world_scan.html')
|
|
|
|
def world_scan(request):
|
2011-04-16 11:44:57 +02:00
|
|
|
if 'world' in request.FILES:
|
|
|
|
data = request.FILES['world'].read()
|
|
|
|
elif 'packages' in request.POST:
|
|
|
|
data = request.POST['packages']
|
2011-04-15 19:28:37 +02:00
|
|
|
else:
|
|
|
|
data = ""
|
|
|
|
|
2012-05-01 21:15:55 +02:00
|
|
|
packages = packages_from_names(data)
|
2012-08-10 17:45:43 +02:00
|
|
|
packages_ids = [p.pk for p in packages]
|
|
|
|
|
|
|
|
favourited = False
|
|
|
|
if request.user.is_authenticated():
|
|
|
|
profile = get_profile(request.user)
|
|
|
|
if len(packages) == len(profile.packages.filter(id__in=packages_ids)):
|
|
|
|
favourited = True
|
2011-04-15 19:28:37 +02:00
|
|
|
|
2012-08-10 17:45:43 +02:00
|
|
|
return {
|
|
|
|
'packages': packages,
|
|
|
|
'packages_ids': packages_ids,
|
|
|
|
'favourited': favourited
|
|
|
|
}
|
2011-04-15 19:28:37 +02:00
|
|
|
|
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
@render_to("euscan/about.html")
|
|
|
|
def about(request):
|
|
|
|
return {}
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-11-17 14:37:59 +01:00
|
|
|
@render_to("euscan/api.html")
|
|
|
|
def api(request):
|
|
|
|
return {}
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
@render_to("euscan/statistics.html")
|
|
|
|
def statistics(request):
|
|
|
|
return {}
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
def chart(request, **kwargs):
|
|
|
|
from django.views.static import serve
|
|
|
|
|
|
|
|
chart = kwargs['chart'] if 'chart' in kwargs else None
|
|
|
|
|
|
|
|
if 'maintainer_id' in kwargs:
|
2012-04-28 18:16:05 +02:00
|
|
|
kwargs['maintainer'] = get_object_or_404(
|
|
|
|
Maintainer,
|
|
|
|
id=kwargs['maintainer_id']
|
|
|
|
)
|
2011-04-25 22:27:32 +02:00
|
|
|
if 'herd' in kwargs:
|
|
|
|
kwargs['herd'] = get_object_or_404(Herd, herd=kwargs['herd'])
|
|
|
|
|
2011-05-03 08:19:01 +02:00
|
|
|
for kw in ('-small', '-weekly', '-monthly', '-yearly'):
|
|
|
|
if chart.endswith(kw):
|
|
|
|
if kw in ('-weekly', '-monthly', '-yearly'):
|
|
|
|
kwargs['period'] = kw
|
|
|
|
kwargs[kw] = True
|
|
|
|
chart = chart[:-len(kw)]
|
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
if chart == 'pie-packages':
|
|
|
|
path = charts.pie_packages(**kwargs)
|
|
|
|
elif chart == 'pie-versions':
|
|
|
|
path = charts.pie_versions(**kwargs)
|
2011-05-03 08:19:01 +02:00
|
|
|
elif chart == 'packages':
|
|
|
|
path = charts.packages(**kwargs)
|
|
|
|
elif chart == 'versions':
|
|
|
|
path = charts.versions(**kwargs)
|
2011-04-25 22:27:32 +02:00
|
|
|
else:
|
2012-08-10 17:45:43 +02:00
|
|
|
raise Http404
|
2011-04-25 22:27:32 +02:00
|
|
|
|
|
|
|
return serve(request, path, document_root=charts.CHARTS_ROOT)
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
def chart_maintainer(request, **kwargs):
|
|
|
|
return chart(request, **kwargs)
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
def chart_herd(request, **kwargs):
|
|
|
|
return chart(request, **kwargs)
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-04-25 22:27:32 +02:00
|
|
|
def chart_category(request, **kwargs):
|
|
|
|
return chart(request, **kwargs)
|
2012-06-03 09:43:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
@ajax_request
|
|
|
|
def registered_tasks(request):
|
|
|
|
data = {}
|
2012-06-08 14:21:11 +02:00
|
|
|
for task in admin_tasks:
|
2012-06-03 09:43:49 +02:00
|
|
|
argspec = inspect.getargspec(task.run)
|
|
|
|
data[task.name] = {
|
|
|
|
"args": argspec.args,
|
|
|
|
"defaults": argspec.defaults,
|
|
|
|
"default_types": None
|
|
|
|
}
|
|
|
|
if argspec.defaults is not None:
|
|
|
|
data[task.name].update({
|
|
|
|
"defaults_types": [type(x).__name__ for x in argspec.defaults]
|
|
|
|
})
|
|
|
|
return {"tasks": data}
|
2012-06-08 14:21:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
2012-07-07 15:44:00 +02:00
|
|
|
def refresh_package(request, category, package):
|
|
|
|
pkg = get_object_or_404(Package, category=category, name=package)
|
|
|
|
|
|
|
|
obj, created = RefreshPackageQuery.objects.get_or_create(package=pkg)
|
2012-07-20 17:10:12 +02:00
|
|
|
|
|
|
|
if request.user in \
|
|
|
|
RefreshPackageQuery.objects.get(package=pkg).users.all():
|
|
|
|
return {"result": "failure"}
|
|
|
|
|
|
|
|
obj.users.add(request.user)
|
2012-06-08 14:21:11 +02:00
|
|
|
if not created:
|
|
|
|
obj.priority += 1
|
|
|
|
obj.save()
|
2012-08-03 21:58:24 +02:00
|
|
|
if created:
|
|
|
|
from djeuscan.tasks import consume_refresh_queue
|
|
|
|
consume_refresh_queue.delay()
|
2012-07-27 12:21:48 +02:00
|
|
|
return {"result": "success", "position": obj.position}
|
2012-06-12 15:27:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@render_to('euscan/accounts/index.html')
|
|
|
|
def accounts_index(request):
|
2012-08-03 21:58:24 +02:00
|
|
|
|
2012-07-26 14:37:03 +02:00
|
|
|
user = request.user
|
2012-08-03 21:58:24 +02:00
|
|
|
upstream_k = lambda c: c["n_versions"] - c["n_packaged"] - c["n_overlay"]
|
2012-07-14 13:56:21 +02:00
|
|
|
|
2012-07-26 14:37:03 +02:00
|
|
|
categories = sorted(get_account_categories(user),
|
2012-07-14 13:56:21 +02:00
|
|
|
key=upstream_k, reverse=True)
|
2012-08-03 21:58:24 +02:00
|
|
|
c_upstream = sum([upstream_k(c) for c in categories])
|
2012-07-14 13:56:21 +02:00
|
|
|
herds = sorted(get_account_herds(request.user),
|
|
|
|
key=upstream_k, reverse=True)
|
2012-08-03 21:58:24 +02:00
|
|
|
h_upstream = sum([upstream_k(c) for c in herds])
|
2012-07-14 13:56:21 +02:00
|
|
|
maintainers = sorted(get_account_maintainers(request.user),
|
|
|
|
key=upstream_k, reverse=True)
|
2012-08-03 21:58:24 +02:00
|
|
|
m_upstream = sum([upstream_k(c) for c in maintainers])
|
2012-08-07 09:39:49 +02:00
|
|
|
packages = sorted(
|
|
|
|
get_profile(user).packages.all(),
|
|
|
|
key=lambda p: p.n_versions - p.n_packaged - p.n_overlay,
|
|
|
|
reverse=True
|
|
|
|
)
|
|
|
|
p_upstream = sum(
|
|
|
|
[c.n_versions - c.n_packaged - c.n_overlay for c in packages]
|
|
|
|
)
|
2012-07-14 13:56:21 +02:00
|
|
|
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,
|
|
|
|
}
|
2012-06-12 15:27:28 +02:00
|
|
|
|
|
|
|
|
2012-08-08 10:46:36 +02:00
|
|
|
@login_required
|
|
|
|
@render_to('euscan/accounts/preferences.html')
|
|
|
|
def accounts_preferences(request):
|
|
|
|
user = request.user
|
2012-08-11 13:31:57 +02:00
|
|
|
prof = get_profile(user)
|
2012-08-08 14:33:37 +02:00
|
|
|
|
2012-08-08 10:46:36 +02:00
|
|
|
updated = False
|
|
|
|
if request.method == "POST":
|
|
|
|
form = PreferencesForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
user.first_name = form.cleaned_data["first_name"]
|
|
|
|
user.last_name = form.cleaned_data["last_name"]
|
|
|
|
user.email = form.cleaned_data["email"]
|
|
|
|
user.save(force_update=True)
|
2012-08-08 14:33:37 +02:00
|
|
|
|
2012-08-11 13:31:57 +02:00
|
|
|
prof.feed_upstream_info = form.cleaned_data["feed_upstream_info"]
|
|
|
|
prof.feed_portage_info = form.cleaned_data["feed_portage_info"]
|
2012-08-08 14:33:37 +02:00
|
|
|
|
2012-08-11 13:31:57 +02:00
|
|
|
prof.save(force_update=True)
|
2012-08-08 14:33:37 +02:00
|
|
|
|
2012-08-08 10:46:36 +02:00
|
|
|
updated = True
|
|
|
|
else:
|
|
|
|
initial_data = {
|
|
|
|
"first_name": user.first_name,
|
|
|
|
"last_name": user.last_name,
|
2012-08-08 14:33:37 +02:00
|
|
|
"email": user.email,
|
2012-08-11 13:31:57 +02:00
|
|
|
"feed_upstream_info": prof.feed_upstream_info,
|
|
|
|
"feed_portage_info": prof.feed_portage_info,
|
|
|
|
"feed_show_adds": prof.feed_show_adds,
|
|
|
|
"feed_show_removals": prof.feed_show_removals,
|
|
|
|
"feed_ignore_pre": prof.feed_ignore_pre,
|
|
|
|
"feed_ignore_pre_if_stable": prof.feed_ignore_pre_if_stable,
|
|
|
|
"email_activated": prof.email_activated,
|
|
|
|
"email_ignore_pre": prof.email_ignore_pre,
|
|
|
|
"email_ignore_pre_if_stable": prof.email_ignore_pre_if_stable,
|
2012-08-08 10:46:36 +02:00
|
|
|
}
|
|
|
|
form = PreferencesForm(initial_data)
|
|
|
|
return {"form": form, "updated": updated}
|
|
|
|
|
|
|
|
|
2012-06-12 15:27:28 +02:00
|
|
|
@login_required
|
|
|
|
@render_to('euscan/accounts/categories.html')
|
|
|
|
def accounts_categories(request):
|
2012-07-14 13:56:21 +02:00
|
|
|
return {"categories": get_account_categories(request.user)}
|
2012-06-12 15:27:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@render_to('euscan/accounts/herds.html')
|
|
|
|
def accounts_herds(request):
|
2012-07-14 13:56:21 +02:00
|
|
|
return {"herds": get_account_herds(request.user)}
|
2012-06-12 15:27:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@render_to('euscan/accounts/maintainers.html')
|
|
|
|
def accounts_maintainers(request):
|
2012-07-14 13:56:21 +02:00
|
|
|
return {"maintainers": get_account_maintainers(request.user)}
|
2012-06-12 15:27:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@render_to('euscan/accounts/packages.html')
|
|
|
|
def accounts_packages(request):
|
2012-07-26 14:37:03 +02:00
|
|
|
return {"packages": get_profile(request.user).packages.all()}
|
2012-06-12 15:27:28 +02:00
|
|
|
|
|
|
|
|
2012-07-10 16:15:06 +02:00
|
|
|
@login_required
|
|
|
|
@render_to('euscan/accounts/overlays.html')
|
|
|
|
def accounts_overlays(request):
|
2012-07-26 14:37:03 +02:00
|
|
|
overlays = [obj.name for obj in get_profile(request.user).overlays.all()]
|
2012-07-10 16:15:06 +02:00
|
|
|
return {"overlays": overlays}
|
|
|
|
|
|
|
|
|
2012-06-12 15:27:28 +02:00
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def favourite_package(request, category, package):
|
|
|
|
obj = get_object_or_404(Package, category=category, name=package)
|
2012-07-26 14:37:03 +02:00
|
|
|
get_profile(request.user).packages.add(obj)
|
|
|
|
return {"success": True}
|
2012-06-12 15:27:28 +02:00
|
|
|
|
|
|
|
|
2012-06-14 10:03:49 +02:00
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def unfavourite_package(request, category, package):
|
|
|
|
package = get_object_or_404(Package, category=category, name=package)
|
2012-07-26 14:37:03 +02:00
|
|
|
get_profile(request.user).packages.remove(package)
|
2012-06-14 10:03:49 +02:00
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
|
2012-06-12 15:27:28 +02:00
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def favourite_herd(request, herd):
|
|
|
|
obj = get_object_or_404(Herd, herd=herd)
|
2012-07-26 14:37:03 +02:00
|
|
|
get_profile(request.user).herds.add(obj)
|
|
|
|
return {"success": True}
|
2012-06-12 15:27:28 +02:00
|
|
|
|
|
|
|
|
2012-06-14 10:03:49 +02:00
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def unfavourite_herd(request, herd):
|
|
|
|
herd = get_object_or_404(Herd, herd=herd)
|
2012-07-26 14:37:03 +02:00
|
|
|
get_profile(request.user).herds.remove(herd)
|
2012-06-14 10:03:49 +02:00
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
|
2012-06-12 15:27:28 +02:00
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def favourite_maintainer(request, maintainer_id):
|
|
|
|
obj = get_object_or_404(Maintainer, pk=maintainer_id)
|
2012-07-26 14:37:03 +02:00
|
|
|
get_profile(request.user).maintainers.add(obj)
|
|
|
|
return {"success": True}
|
2012-06-12 15:27:28 +02:00
|
|
|
|
|
|
|
|
2012-06-14 10:03:49 +02:00
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def unfavourite_maintainer(request, maintainer_id):
|
|
|
|
maintainer = get_object_or_404(Maintainer, pk=maintainer_id)
|
2012-07-26 14:37:03 +02:00
|
|
|
get_profile(request.user).maintainers.remove(maintainer)
|
2012-06-14 10:03:49 +02:00
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
|
2012-06-12 15:27:28 +02:00
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def favourite_category(request, category):
|
2012-07-26 14:37:03 +02:00
|
|
|
obj = Category.objects.get(name=category)
|
|
|
|
get_profile(request.user).categories.add(obj)
|
|
|
|
return {"success": True}
|
2012-06-14 10:03:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def unfavourite_category(request, category):
|
2012-07-26 14:37:03 +02:00
|
|
|
obj = Category.objects.get(name=category)
|
|
|
|
get_profile(request.user).categories.remove(obj)
|
2012-06-14 10:03:49 +02:00
|
|
|
return {"success": True}
|
2012-07-10 16:15:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def favourite_overlay(request, overlay):
|
2012-08-08 08:58:07 +02:00
|
|
|
obj = Overlay.objects.get(name=overlay)
|
2012-07-26 14:37:03 +02:00
|
|
|
get_profile(request.user).overlays.add(obj)
|
|
|
|
return {"success": True}
|
2012-07-10 16:15:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def unfavourite_overlay(request, overlay):
|
2012-08-08 08:58:07 +02:00
|
|
|
obj = Overlay.objects.get(name=overlay)
|
2012-07-26 14:37:03 +02:00
|
|
|
get_profile(request.user).overlays.remove(obj)
|
2012-07-10 16:15:06 +02:00
|
|
|
return {"success": True}
|
2012-08-10 17:45:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def favourite_world(request):
|
|
|
|
if not "packages[]" in request.POST:
|
|
|
|
return {"success": False}
|
|
|
|
packages = request.POST.getlist("packages[]")
|
|
|
|
objs = Package.objects.filter(id__in=packages)
|
|
|
|
get_profile(request.user).packages.add(*objs)
|
|
|
|
return {"success": True}
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@require_POST
|
|
|
|
@ajax_request
|
|
|
|
def unfavourite_world(request):
|
|
|
|
if not "packages[]" in request.POST:
|
|
|
|
return {"success": False}
|
|
|
|
packages = request.POST.getlist("packages[]")
|
|
|
|
objs = Package.objects.filter(id__in=packages)
|
|
|
|
get_profile(request.user).packages.remove(*objs)
|
|
|
|
return {"success": True}
|