Ejemplo n.º 1
0
    def post(self, *args, **kwargs):
        object = self.get_object()

        o_count = 0
        if 'confirm' in self.request.POST and self.request.user.is_superuser:
            orphans = utils.get_orphans(object)
            o_count = len(orphans)
            for o in orphans:
                o.delete()
            object.delete()

        old = Trait.objects.count()
        Prover._add_proofs()
        new = Trait.objects.count()
        messages.warning(self.request,
            '%s proof(s) deleted. %s automatically recovered.' %
            (o_count + 1, new - old))
        return redirect('brubeck:home')
Ejemplo n.º 2
0
    def search(self):
        q, res = self.cleaned_data.get('q', '').strip(), {}

        # TODO: unicode support is problematic because of a bug in
        #   urllib. For now, we'll remove accents and hope for the best
        #   Moving forward, we need to completely audit unicode
        #   handling throughout the application.
        import unicodedata
        q = ''.join((c for c in unicodedata.normalize('NFD', q)
            if unicodedata.category(c) != 'Mn'))

        if not q:
            return res

        # Try to parse as a formula
        try:
            f = human_to_formula(q)
            if f.is_empty():
                res['f'], res['f_spaces'] = '', []
            else:
                res['f'] = f.__unicode__(lookup=True, link=True)
                res['f_spaces'] = Space.objects.filter(
                    id__in=Prover.spaces_matching_formula(f))
        except ValidationError as e:
            res['f_errors'] = e.messages

        # Trim trailing separators
        if q and q[-1] in ['+', '|']:
            q = q[:-1].rstrip()
        # Slight optimization: if q contained a '+' or '|' and validated as a
        # formula, it will almost certainly not match any text
        if 'f' in res and ('+' in q or '|' in q):
            return res

        # Otherwise, include the text to search by
        res['text'] = q
        return res
Ejemplo n.º 3
0
def proof_ajax(request, s, p):
    # if not request.is_ajax(): raise Http404
    trait = get_object_or_404(Trait, space__slug=s, property__slug=p)
    proof = Prover.get_full_proof(trait)
    return HttpResponse(json.dumps(proof),
        content_type='application/json')