Пример #1
0
 def test_sexp_mapping_types(self):
     good_sexps = [
     ( '( Addition ( Variable x ) ( Variable y ))',base_objects.Addition),
     ( '( Variable x )', base_objects.Variable) ,
     ]
     for sexp, cls in good_sexps:
         parsed = parse_sexp(sexp)
         self.assertEqual(parsed.classname, cls.__name__)
Пример #2
0
def ws_read(request, ws_id):
    ws = get_object_or_404(models.Workspace, pk=ws_id)

    if ( ws.owner.id != request.user.id ) and not ws.public:
        return HttpResponseForbidden()

    cells = models.Cell.objects.filter(workspace=ws_id)

    if not cells:
        cells = []

    # HTML elements to inject into the #workspace div
    html_cells = []

    uid = uidgen()
    # Populate the Cell
    for index,cell in enumerate(cells):
        # Load toplevel expressions
        eqs = models.Expression.objects.filter(cell=cell).order_by('index')
        top_exprs = []

        #asms = Assumption.objects.filter(cell=cell).order_by('index')
        #top_asms = []

        for eq in eqs:
            if 'Text:' in eq.sexp:
                top_exprs.append(TextAtom(eq.sexp))
            else:
                # Build up the object from the sexp in the database
                etree = parse_sexp(eq.sexp)
                etree.annotation = eq.annotation
                etree.uid_walk(uid)
                top_exprs.append(etree)

        # Initialize the new Cell instance
        ncell = basecell.Cell(top_exprs, [],
           index = index,
           cid = 'cell'+str(index),
           id = cell.id
        )

        html_cells.append(html(ncell))

    response = render_to_response('worksheet_read.html', {
        'title': ws.name,
        'author': ws.owner,
        'cells': html_cells,
        },
        context_instance = RequestContext(request),
    )

    return response
Пример #3
0
    def test_sexp_mapping(self):
        good_sexps = [
            '( Addition ( Variable x ) ( Variable y ) )',
            '( Variable x )',
            '( Equation 1 1 )',
            '( Placeholder )',
            '( Numeric 3.14159 )',
        ]

        bad_sexps = [
            '( Variable 1 )',
            '( Numeric x )',
            '( Numeric 1 1 )',
            '( Equation foo )',
            '( Addition )',
        ]

        for sexp in good_sexps:
            self.assertIsNotNone(parse_sexp(sexp))

        for sexp in bad_sexps:
            with self.assertRaises(Exception):
                parsed = parse_sexp(sexp)
Пример #4
0
def ws(request, ws_id):
    ws = get_object_or_404(models.Workspace, pk=ws_id)

    if ( ws.owner.id != request.user.id ):
        return HttpResponseForbidden()

    # Start a uid generator at cid0
    uid = uidgen()
    cells = models.Cell.objects.filter(workspace=ws_id)

    # If the worksheet is empty give it an empty cell
    if not cells:
        ncell = models.Cell(workspace=ws, index=0)
        ncell.save()

        cells = []
        cells.append(ncell)

    # HTML elements to inject into the #workspace div
    html_cells = []

    # inline javascript global variable `JSON_TREE`
    json_cells = []

    # Populate the Cell
    for index,cell in enumerate(cells):
        # Load toplevel expressions
        eqs = models.Expression.objects.filter(cell=cell).order_by('index')
        top_exprs = []

        #asms = Assumption.objects.filter(cell=cell).order_by('index')
        #top_asms = []

        for eq in eqs:
            if 'Text:' in eq.sexp:
                top_exprs.append(TextAtom(eq.sexp))
            else:
                # Build up the object from the sexp in the database
                etree = parse_sexp(eq.sexp)
                etree.uid_walk(uid)

                etree.sid = eq.id
                etree.annotation = eq.annotation
                top_exprs.append(etree)

        # Initialize the new Cell instance
        ncell = basecell.Cell(top_exprs, [],
           index = index,
           id = cell.id,
           sid = cell.id
        )

        html_cells.append(html(ncell))
        json_cells.append(json_flat(ncell))

    response = render_to_response('worksheet.html', {
        'title': ws.name,
        'ws_id': ws.id,
        'cells': html_cells,
        'namespace_index': uid.next()[3:],
        'cell_index': len(cells),
        'json_cells': json.dumps(json_cells),
        'xhtml': True,
        'debug': 'true' if settings.DEBUG else 'false',
        },
        context_instance = RequestContext(request),
    )

    # XHTMLMiddleware will look for this attribute and set
    # Content-Type to application/xhtml+xml which is needed by
    # some browsers (i.e. Firefox 3.5) to render MathML
    response.xhtml = True

    return response