Ejemplo n.º 1
0
    def test_favourite(self):
        category = self.categories[0]

        response = self.get("category", category=category)

        self.assertEqual(response.status_code, 200)
        self.assertNotIn("Watch", response.content)

        with self.login():
            response = self.get("category", category=category)
            self.assertEqual(response.status_code, 200)

            user = response.context["user"]
            self.assertEquals(get_profile(user).categories.count(), 0)

            self.assertIn("Watch", response.content)
            self.post("favourite_category", category=category)

            self.assertEquals(get_profile(user).categories.count(), 1)

            response = self.get("accounts_categories")
            self.assertEqual(response.status_code, 200)

            self._check_table(response, [category])

            self.post("unfavourite_category", category=category)

            self.assertEquals(get_profile(user).categories.count(), 0)
Ejemplo n.º 2
0
    def test_favourite(self):
        response = self.get("package",
                            category=self.package.category,
                            package=self.package.name)
        self.assertEqual(response.status_code, 200)

        self.assertNotIn("Watch", response.content)

        with self.login():
            response = self.get("package",
                                category=self.package.category,
                                package=self.package.name)
            self.assertEqual(response.status_code, 200)

            user = response.context["user"]
            self.assertEquals(get_profile(user).categories.count(), 0)

            self.assertIn("Watch", response.content)
            self.post("favourite_package",
                      category=self.package.category,
                      package=self.package.name)

            self.assertEquals(get_profile(user).packages.count(), 1)

            response = self.get("accounts_packages")
            self.assertEqual(response.status_code, 200)

            self.assertIn(self.package.name, response.content)

            self.post("unfavourite_package",
                      category=self.package.category,
                      package=self.package.name)
            self.assertEquals(get_profile(user).packages.count(), 0)
Ejemplo n.º 3
0
    def test_favourite(self):
        maintainer = self.maintainers[0]

        response = self.get("maintainer", maintainer_id=maintainer.pk)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn("Watch", response.content)

        with self.login():
            response = self.get("maintainer", maintainer_id=maintainer.pk)
            self.assertEqual(response.status_code, 200)

            user = response.context["user"]
            self.assertEquals(get_profile(user).maintainers.count(), 0)

            self.assertIn("Watch", response.content)
            self.post("favourite_maintainer", maintainer_id=maintainer.pk)

            self.assertEquals(get_profile(user).maintainers.count(), 1)

            response = self.get("accounts_maintainers")
            self.assertEqual(response.status_code, 200)

            self._check_table(response, [maintainer], attr="name")

            self.post("unfavourite_maintainer", maintainer_id=maintainer.pk)

            self.assertEquals(get_profile(user).maintainers.count(), 0)
Ejemplo n.º 4
0
    def test_favourite(self):
        herd = self.herds[0]

        response = self.get("herd", herd=herd.herd)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn("Watch", response.content)

        with self.login():
            response = self.get("herd", herd=herd.herd)
            self.assertEqual(response.status_code, 200)

            user = response.context["user"]
            self.assertEquals(get_profile(user).herds.count(), 0)

            self.assertIn("Watch", response.content)
            self.post("favourite_herd", herd=herd.herd)

            self.assertEquals(get_profile(user).herds.count(), 1)

            response = self.get("accounts_herds")
            self.assertEqual(response.status_code, 200)

            self._check_table(response, [herd], attr="herd")

            self.post("unfavourite_herd", herd=herd.herd)
            self.assertEquals(get_profile(user).herds.count(), 0)
Ejemplo n.º 5
0
    def test_favourite(self):
        category = self.categories[0]

        response = self.get("category", category=category)

        self.assertEqual(response.status_code, 200)
        self.assertNotIn("Watch", response.content)

        with self.login():
            response = self.get("category", category=category)
            self.assertEqual(response.status_code, 200)

            user = response.context["user"]
            self.assertEquals(get_profile(user).categories.count(), 0)

            self.assertIn("Watch", response.content)
            self.post("favourite_category", category=category)

            self.assertEquals(get_profile(user).categories.count(), 1)

            response = self.get("accounts_categories")
            self.assertEqual(response.status_code, 200)

            self._check_table(response, [category])

            self.post("unfavourite_category", category=category)

            self.assertEquals(get_profile(user).categories.count(), 0)
Ejemplo n.º 6
0
    def test_favourite(self):
        maintainer = self.maintainers[0]

        response = self.get("maintainer", maintainer_id=maintainer.pk)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn("Watch", response.content)

        with self.login():
            response = self.get("maintainer", maintainer_id=maintainer.pk)
            self.assertEqual(response.status_code, 200)

            user = response.context["user"]
            self.assertEquals(get_profile(user).maintainers.count(), 0)

            self.assertIn("Watch", response.content)
            self.post("favourite_maintainer", maintainer_id=maintainer.pk)

            self.assertEquals(get_profile(user).maintainers.count(), 1)

            response = self.get("accounts_maintainers")
            self.assertEqual(response.status_code, 200)

            self._check_table(response, [maintainer], attr="name")

            self.post("unfavourite_maintainer", maintainer_id=maintainer.pk)

            self.assertEquals(get_profile(user).maintainers.count(), 0)
Ejemplo n.º 7
0
    def test_favourite(self):
        response = self.get("package", category=self.package.category,
                            package=self.package.name)
        self.assertEqual(response.status_code, 200)

        self.assertNotIn("Watch", response.content)

        with self.login():
            response = self.get("package", category=self.package.category,
                                package=self.package.name)
            self.assertEqual(response.status_code, 200)

            user = response.context["user"]
            self.assertEquals(get_profile(user).categories.count(), 0)

            self.assertIn("Watch", response.content)
            self.post("favourite_package", category=self.package.category,
                      package=self.package.name)

            self.assertEquals(get_profile(user).packages.count(), 1)

            response = self.get("accounts_packages")
            self.assertEqual(response.status_code, 200)

            self.assertIn(self.package.name, response.content)

            self.post("unfavourite_package", category=self.package.category,
                      package=self.package.name)
            self.assertEquals(get_profile(user).packages.count(), 0)
Ejemplo n.º 8
0
    def test_favourite(self):
        herd = self.herds[0]

        response = self.get("herd", herd=herd.herd)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn("Watch", response.content)

        with self.login():
            response = self.get("herd", herd=herd.herd)
            self.assertEqual(response.status_code, 200)

            user = response.context["user"]
            self.assertEquals(get_profile(user).herds.count(), 0)

            self.assertIn("Watch", response.content)
            self.post("favourite_herd", herd=herd.herd)

            self.assertEquals(get_profile(user).herds.count(), 1)

            response = self.get("accounts_herds")
            self.assertEqual(response.status_code, 200)

            self._check_table(response, [herd], attr="herd")

            self.post("unfavourite_herd", herd=herd.herd)
            self.assertEquals(get_profile(user).herds.count(), 0)
Ejemplo n.º 9
0
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)
    if "nojs" in request.POST:
        return redirect(reverse("world"))
    return {"success": True}
Ejemplo n.º 10
0
def category(request, category):
    packages = Package.objects.for_category(category, last_versions=True)

    if not packages:
        return HttpResponseNotFound()

    try:
        last_scan = \
            EuscanResult.objects.for_category(category).latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        try:
            category = Category.objects.get(name=category)
            favourited = category in get_profile(request.user).categories.all()
        except Category.DoesNotExist:
            pass

    return {
        'category': category,
        'packages': packages,
        'last_scan': last_scan,
        'favourited': favourited
    }
Ejemplo n.º 11
0
    def _items(self, data):
        user = data["user"]

        profile = get_profile(user)
        vlogs = get_account_versionlogs(profile)

        return vlogs, 100
Ejemplo n.º 12
0
def accounts_preferences(request):
    user = request.user
    prof = get_profile(user)

    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)

            prof.feed_upstream_info = form.cleaned_data["feed_upstream_info"]
            prof.feed_portage_info = form.cleaned_data["feed_portage_info"]
            prof.feed_show_adds = form.cleaned_data["feed_show_adds"]
            prof.feed_show_removals = form.cleaned_data["feed_show_removals"]
            prof.feed_ignore_pre = form.cleaned_data["feed_ignore_pre"]
            prof.feed_ignore_pre_if_stable = \
                form.cleaned_data["feed_ignore_pre_if_stable"]

            prof.email_activated = form.cleaned_data["email_activated"]
            prof.email_every = form.cleaned_data["email_every"]
            prof.email_ignore_pre = form.cleaned_data["email_ignore_pre"]
            prof.email_ignore_pre_if_stable = \
                form.cleaned_data["email_ignore_pre_if_stable"]

            prof.save(force_update=True)

            updated = True
    else:
        initial_data = {
            "first_name": user.first_name,
            "last_name": user.last_name,
            "email": user.email,
            "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_every": prof.email_every,
            "email_ignore_pre": prof.email_ignore_pre,
            "email_ignore_pre_if_stable": prof.email_ignore_pre_if_stable,
        }
        form = PreferencesForm(initial_data)
    return {"form": form, "updated": updated}
Ejemplo n.º 13
0
def herd(request, herd):
    herd = get_object_or_404(Herd, herd=herd)
    packages = Package.objects.for_herd(herd, last_versions=True)

    try:
        last_scan = EuscanResult.objects.for_herd(herd).latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        if herd in get_profile(request.user).herds.all():
            favourited = True

    return {'herd': herd, 'packages': packages, "last_scan": last_scan,
            'favourited': favourited}
Ejemplo n.º 14
0
def maintainer(request, maintainer_id=None, maintainer_email=None):
    maintainer = get_maintainer_or_404(maintainer_id, maintainer_email)
    packages = Package.objects.for_maintainer(maintainer, last_versions=True)

    try:
        last_scan = \
            EuscanResult.objects.for_maintainer(maintainer).latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        if maintainer in get_profile(request.user).maintainers.all():
            favourited = True

    return {'maintainer': maintainer, 'packages': packages,
            'last_scan': last_scan, 'favourited': favourited}
Ejemplo n.º 15
0
    def items(self, data=None):
        user = data.get("user", None) if data else None
        options = data.get("options", {}) if data else {}

        # first of all consider options, then user preferences
        try:
            upstream_info = json.loads(options.get("upstream_info", "1"))
            portage_info = json.loads(options.get("portage_info", "1"))
            show_adds = json.loads(options.get("show_adds", "1"))
            show_removals = json.loads(options.get("show_removals", "1"))
            ignore_pre = json.loads(options.get("ignore_pre", "0"))
            ignore_pre_if_stable = json.loads(
                options.get("ignore_pre_if_stable", "0")
            )
        except ValueError:
            return []

        if user and not options:
            profile = get_profile(user)
            upstream_info = profile.feed_upstream_info
            portage_info = profile.feed_portage_info
            show_adds = profile.feed_show_adds
            show_removals = profile.feed_show_removals
            ignore_pre = profile.feed_ignore_pre
            ignore_pre_if_stable = profile.feed_ignore_pre_if_stable

        ret, max_items = self._items(data)

        if not upstream_info:
            ret = ret.exclude(overlay="")
        if not portage_info:
            ret = ret.exclude(~Q(overlay=""))
        if not show_adds:
            ret = ret.exclude(action=VersionLog.VERSION_ADDED)
        if not show_removals:
            ret = ret.exclude(action=VersionLog.VERSION_REMOVED)
        if ignore_pre:
            ret = ret.exclude(vtype__in=gentoo_unstable)
        if ignore_pre_if_stable:
            ret = ret.exclude(
                ~Q(package__last_version_gentoo__vtype__in=gentoo_unstable),
                vtype__in=gentoo_unstable
            )

        return ret.order_by("-datetime")[:max_items]
Ejemplo n.º 16
0
def package(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)

    packaged = sorted(packaged, key=version_key)
    upstream = sorted(upstream, key=version_key)

    log = EuscanResult.objects.filter(package=package).\
                               order_by('-datetime')[:1]
    log = log[0] if log else None
    vlog = VersionLog.objects.for_package(package, order=True)

    try:
        last_scan = EuscanResult.objects.for_package(package).latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        if package in get_profile(request.user).packages.all():
            favourited = True

    try:
        refresh_query = RefreshPackageQuery.objects.get(package=package)
    except RefreshPackageQuery.DoesNotExist:
        refresh_requested = False
        refresh_pos = None
    else:
        refresh_requested = request.user in refresh_query.users.all()
        refresh_pos = refresh_query.position

    return {
        'package': package,
        'packaged': packaged,
        'upstream': upstream,
        'vlog': vlog,
        'log': log,
        'msg': log.messages if log else "",
        'last_scan': last_scan,
        'favourited': favourited,
        'refresh_requested': refresh_requested,
        'refresh_pos': refresh_pos,
    }
Ejemplo n.º 17
0
def package(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)

    packaged = sorted(packaged, key=version_key)
    upstream = sorted(upstream, key=version_key)

    log = EuscanResult.objects.filter(package=package).\
                               order_by('-datetime')[:1]
    log = log[0] if log else None
    vlog = VersionLog.objects.for_package(package, order=True)

    try:
        last_scan = EuscanResult.objects.for_package(package).latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        if package in get_profile(request.user).packages.all():
            favourited = True

    try:
        refresh_query = RefreshPackageQuery.objects.get(package=package)
    except RefreshPackageQuery.DoesNotExist:
        refresh_requested = False
        refresh_pos = None
    else:
        refresh_requested = request.user in refresh_query.users.all()
        refresh_pos = refresh_query.position

    return {
        'package': package,
        'packaged': packaged,
        'upstream': upstream,
        'vlog': vlog,
        'log': log,
        'msg': log.messages if log else "",
        'last_scan': last_scan,
        'favourited': favourited,
        'refresh_requested': refresh_requested,
        'refresh_pos': refresh_pos,
    }
Ejemplo n.º 18
0
    def items(self, data=None):
        user = data.get("user", None) if data else None
        options = data.get("options", {}) if data else {}

        # first of all consider options, then user preferences
        try:
            upstream_info = json.loads(options.get("upstream_info", "1"))
            portage_info = json.loads(options.get("portage_info", "1"))
            show_adds = json.loads(options.get("show_adds", "1"))
            show_removals = json.loads(options.get("show_removals", "1"))
            ignore_pre = json.loads(options.get("ignore_pre", "0"))
            ignore_pre_if_stable = json.loads(
                options.get("ignore_pre_if_stable", "0"))
        except ValueError:
            return []

        if user and not options:
            profile = get_profile(user)
            upstream_info = profile.feed_upstream_info
            portage_info = profile.feed_portage_info
            show_adds = profile.feed_show_adds
            show_removals = profile.feed_show_removals
            ignore_pre = profile.feed_ignore_pre
            ignore_pre_if_stable = profile.feed_ignore_pre_if_stable

        ret, max_items = self._items(data)

        if not upstream_info:
            ret = ret.exclude(overlay="")
        if not portage_info:
            ret = ret.exclude(~Q(overlay=""))
        if not show_adds:
            ret = ret.exclude(action=VersionLog.VERSION_ADDED)
        if not show_removals:
            ret = ret.exclude(action=VersionLog.VERSION_REMOVED)
        if ignore_pre:
            ret = ret.exclude(vtype__in=gentoo_unstable)
        if ignore_pre_if_stable:
            ret = ret.exclude(
                ~Q(package__last_version_gentoo__vtype__in=gentoo_unstable),
                vtype__in=gentoo_unstable)

        return ret.order_by("-datetime")[:max_items]
Ejemplo n.º 19
0
def herd(request, herd):
    herd = get_object_or_404(Herd, herd=herd)
    packages = Package.objects.for_herd(herd, last_versions=True)

    try:
        last_scan = EuscanResult.objects.for_herd(herd).latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        if herd in get_profile(request.user).herds.all():
            favourited = True

    return {
        'herd': herd,
        'packages': packages,
        "last_scan": last_scan,
        'favourited': favourited
    }
Ejemplo n.º 20
0
def overlay(request, overlay):
    packages = Package.objects.for_overlay(overlay)
    if not packages:
        return HttpResponseNotFound()

    try:
        last_scan = EuscanResult.objects.latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        try:
            overlay = Overlay.objects.get(name=overlay)
            favourited = overlay in get_profile(request.user).overlays.all()
        except Overlay.DoesNotExist:
            pass

    return {'overlay': overlay, 'packages': packages, 'last_scan': last_scan,
            'favourited': favourited}
Ejemplo n.º 21
0
def maintainer(request, maintainer_id=None, maintainer_email=None):
    maintainer = get_maintainer_or_404(maintainer_id, maintainer_email)
    packages = Package.objects.for_maintainer(maintainer, last_versions=True)

    try:
        last_scan = \
            EuscanResult.objects.for_maintainer(maintainer).latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        if maintainer in get_profile(request.user).maintainers.all():
            favourited = True

    return {
        'maintainer': maintainer,
        'packages': packages,
        'last_scan': last_scan,
        'favourited': favourited
    }
Ejemplo n.º 22
0
def world_scan(request):
    if 'world' in request.FILES:
        data = request.FILES['world'].read()
    elif 'packages' in request.POST:
        data = request.POST['packages']
    else:
        data = ""

    packages = packages_from_names(data)
    packages_ids = [p.pk for p in packages]

    favourited = False
    if len(packages) > 0 and 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
    }
Ejemplo n.º 23
0
def world_scan(request):
    if 'world' in request.FILES:
        data = request.FILES['world'].read()
    elif 'packages' in request.POST:
        data = request.POST['packages']
    else:
        data = ""

    packages = packages_from_names(data)
    packages_ids = [p.pk for p in packages]

    favourited = False
    if len(packages) > 0 and 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
    }
Ejemplo n.º 24
0
def category(request, category):
    packages = Package.objects.for_category(category, last_versions=True)

    if not packages:
        return HttpResponseNotFound()

    try:
        last_scan = \
            EuscanResult.objects.for_category(category).latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        try:
            category = Category.objects.get(name=category)
            favourited = category in get_profile(request.user).categories.all()
        except Category.DoesNotExist:
            pass

    return {'category': category, 'packages': packages, 'last_scan': last_scan,
            'favourited': favourited}
Ejemplo n.º 25
0
def overlay(request, overlay):
    packages = Package.objects.for_overlay(overlay)
    if not packages:
        return HttpResponseNotFound()

    try:
        last_scan = EuscanResult.objects.latest().datetime
    except EuscanResult.DoesNotExist:
        last_scan = None

    favourited = False
    if request.user.is_authenticated():
        try:
            overlay = Overlay.objects.get(name=overlay)
            favourited = overlay in get_profile(request.user).overlays.all()
        except Overlay.DoesNotExist:
            pass

    return {
        'overlay': overlay,
        'packages': packages,
        'last_scan': last_scan,
        'favourited': favourited
    }
Ejemplo n.º 26
0
def accounts_packages(request):
    return {"packages": get_profile(request.user).packages.all()}
Ejemplo n.º 27
0
def unfavourite_category(request, category):
    obj = Category.objects.get(name=category)
    get_profile(request.user).categories.remove(obj)
    if "nojs" in request.POST:
        return redirect(reverse("category", args=(category, )))
    return {"success": True}
Ejemplo n.º 28
0
def accounts_overlays(request):
    overlays = [obj.name for obj in get_profile(request.user).overlays.all()]
    return {"overlays": overlays}
Ejemplo n.º 29
0
def unfavourite_maintainer(request, maintainer_id=None, maintainer_email=None):
    obj = get_maintainer_or_404(maintainer_id, maintainer_email)
    get_profile(request.user).maintainers.remove(obj)
    if "nojs" in request.POST:
        return redirect(reverse("maintainer", args=(obj.email, )))
    return {"success": True}
Ejemplo n.º 30
0
def unfavourite_package(request, category, package):
    obj = get_object_or_404(Package, category=category, name=package)
    get_profile(request.user).packages.remove(obj)
    if "nojs" in request.POST:
        return redirect(reverse("package", args=(category, package)))
    return {"success": True}
Ejemplo n.º 31
0
def unfavourite_herd(request, herd):
    obj = get_object_or_404(Herd, herd=herd)
    get_profile(request.user).herds.remove(obj)
    if "nojs" in request.POST:
        return redirect(reverse("herd", args=(herd, )))
    return {"success": True}
Ejemplo n.º 32
0
def unfavourite_overlay(request, overlay):
    obj = Overlay.objects.get(name=overlay)
    get_profile(request.user).overlays.remove(obj)
    if "nojs" in request.POST:
        return redirect(reverse("overlay", args=(overlay, )))
    return {"success": True}