Example #1
0
 def test_get_repos(self):
     """test get_repos"""
     self.assertEqual([self.repo],
                      list(api.get_repos(self.user.id)))
     self.assertEqual([],
                      list(api.get_repos(self.user_norepo.id)))
     with self.assertRaises(api.PermissionDenied):
         api.get_repos(-1)
Example #2
0
File: views.py Project: olabi/lore
def welcome(request):
    """
    Greet the user, show available repositories.
    """
    return render(
        request, "welcome.html", {
            "repos": get_repos(request.user.id),
            "support_email": settings.EMAIL_SUPPORT,
        })
Example #3
0
def welcome(request):
    """
    Greet the user, show available repositories.
    """
    return render(
        request, "welcome.html", {
            "repos": get_repos(request.user.id),
            "support_email": settings.EMAIL_SUPPORT,
        })
Example #4
0
File: views.py Project: Ferdi/lore
def upload(request, repo_id):
    """
    Upload a OLX archive.
    """
    if int(repo_id) not in set([x.id for x in get_repos(request.user.id)]):
        return HttpResponseForbidden("unauthorized")
    form = UploadForm()
    if request.method == "POST":
        form = UploadForm(
            data=request.POST, files=request.FILES)
        if form.is_valid():
            try:
                form.save(request.user.id, repo_id)
                return redirect("/lore/listing/{0}/1".format(repo_id))
            except ValueError as ex:
                log.debug("ex args: %s", ex.args)
                if "Duplicate course" not in ex.args:
                    raise ex
                form.add_error("course_file", "Duplicate course")
    return render(
        request,
        "upload.html",
        {'form': form, "repo_id": repo_id},
    )
Example #5
0
    def get_queryset(self):
        """Filter to these repositories."""

        repo_ids = [repo.id for repo in get_repos(self.request.user.id)]
        return Repository.objects.filter(id__in=repo_ids).order_by('id')