summaryrefslogtreecommitdiffstats
path: root/equations/views.py
blob: 9ef1081e54ff1366e79e50183b52b22d4623018e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from django.core import serializers
from models import Equation, Variable, Symbol
from django.http import HttpResponse

def all_vars(request):
    data = serializers.serialize("json", Variable.objects.all())
    return HttpResponse(data, mimetype="text/javascript")

def all_symbs(request):
    data = serializers.serialize("json", Symbol.objects.all())
    return HttpResponse(data, mimetype="text/javascript")

def equs_by_vars(request, whichvars):
    vars = whichvars.split(',')
    if len(vars) < 1 or whichvars == '':
        return HttpResponse('[]', mimetype="text/javascript")
    if vars[-1] == '/' or vars[-1] == '':
        vars = vars[:-1]
    returnables = Equation.objects.filter(variables=vars[0])
    if len(vars) > 1:
        for r in returnables:
            for i in vars[1:]:
                if len(r.variables.filter(id=i)) == 0:
                    returnables = returnables.exclude(id=r.id)
                    if len(returnables) < 1:
                        break
    
    data = serializers.serialize("json", returnables)
    return HttpResponse(data, mimetype="text/javascript")