diff --git a/euscanwww/djeuscan/templates/euscan/category.html b/euscanwww/djeuscan/templates/euscan/category.html index 98101c5..78768f9 100644 --- a/euscanwww/djeuscan/templates/euscan/category.html +++ b/euscanwww/djeuscan/templates/euscan/category.html @@ -54,6 +54,7 @@

{% endblock %} diff --git a/euscanwww/djeuscan/templates/euscan/herd.html b/euscanwww/djeuscan/templates/euscan/herd.html index feaa926..a0466a4 100644 --- a/euscanwww/djeuscan/templates/euscan/herd.html +++ b/euscanwww/djeuscan/templates/euscan/herd.html @@ -52,6 +52,7 @@

{% endblock %} diff --git a/euscanwww/djeuscan/templates/euscan/maintainer.html b/euscanwww/djeuscan/templates/euscan/maintainer.html index 00ac687..49f66a2 100644 --- a/euscanwww/djeuscan/templates/euscan/maintainer.html +++ b/euscanwww/djeuscan/templates/euscan/maintainer.html @@ -53,6 +53,7 @@

{% endblock %} diff --git a/euscanwww/djeuscan/templates/euscan/overlay.html b/euscanwww/djeuscan/templates/euscan/overlay.html index 5e2a8c1..ee4e22d 100644 --- a/euscanwww/djeuscan/templates/euscan/overlay.html +++ b/euscanwww/djeuscan/templates/euscan/overlay.html @@ -26,6 +26,7 @@ {% packages packages %} {% endblock %} diff --git a/euscanwww/djeuscan/templates/euscan/world_scan.html b/euscanwww/djeuscan/templates/euscan/world_scan.html index ca96488..da5c80b 100644 --- a/euscanwww/djeuscan/templates/euscan/world_scan.html +++ b/euscanwww/djeuscan/templates/euscan/world_scan.html @@ -1,5 +1,6 @@ {% extends "euscan/_datatable.html" %} +{% load url from future %} {% load djeuscan_helpers %} {% block title %} @@ -7,6 +8,40 @@ {% endblock %} {% block content %} -

World scan:

+

+ World scan: + {% if user.is_authenticated %} + + + + + {% endif %} +

+ {% packages packages %} + + + {% endblock %} diff --git a/euscanwww/djeuscan/urls.py b/euscanwww/djeuscan/urls.py index 87de27b..d716b8f 100644 --- a/euscanwww/djeuscan/urls.py +++ b/euscanwww/djeuscan/urls.py @@ -115,6 +115,9 @@ urlpatterns = patterns('djeuscan.views', url(r'^statistics/charts/(?P[\w\-]+).png$', 'chart', name="chart"), url(r'^world/$', 'world', name="world"), url(r'^world/scan/$', 'world_scan', name="world_scan"), + url(r'^world/favourite/$', 'favourite_world', name="favourite_world"), + url(r'^world/unfavourite/$', 'unfavourite_world', + name="unfavourite_world"), # Real data url(r'^categories/', include(categories_patterns)), diff --git a/euscanwww/djeuscan/views.py b/euscanwww/djeuscan/views.py index 9ba82e3..4da919c 100644 --- a/euscanwww/djeuscan/views.py +++ b/euscanwww/djeuscan/views.py @@ -271,7 +271,6 @@ def world(request): @render_to('euscan/world_scan.html') def world_scan(request): - if 'world' in request.FILES: data = request.FILES['world'].read() elif 'packages' in request.POST: @@ -280,8 +279,19 @@ def world_scan(request): data = "" packages = packages_from_names(data) + packages_ids = [p.pk for p in packages] - return {'packages': 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 + + return { + 'packages': packages, + 'packages_ids': packages_ids, + 'favourited': favourited + } @render_to("euscan/about.html") @@ -328,7 +338,7 @@ def chart(request, **kwargs): elif chart == 'versions': path = charts.versions(**kwargs) else: - raise Http404() + raise Http404 return serve(request, path, document_root=charts.CHARTS_ROOT) @@ -568,3 +578,27 @@ def unfavourite_overlay(request, overlay): obj = Overlay.objects.get(name=overlay) get_profile(request.user).overlays.remove(obj) return {"success": True} + + +@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}