コード例 #1
0
ファイル: test_lex.py プロジェクト: ntoll/checklistDSL
 def test_break(self):
     """
     Ensures that break token is correctly identified.
     """
     # Breaks need to be 3 or more minus signs otherwise they match TEXT
     data = "--"
     tokens = get_tokens(data)
     self.assertEqual("TEXT", tokens[0].token)
     # A legitimate break
     data = "---"
     tokens = get_tokens(data)
     self.assertEqual("BREAK", tokens[0].token)
コード例 #2
0
ファイル: views.py プロジェクト: checklisthq/checklisthq.com
def edit_checklist(request, id):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/')
    checklist = Checklist.objects.get(id=id)
    if not checklist.owner == request.user:
        return HttpResponseRedirect('/')
    context = {}
    if request.method == 'POST':

		form = ChecklistForm(request.POST, instance=checklist)
		if 'Save' in request.POST:
			if form.is_valid():
				form.save()
                messages.add_message(request, messages.INFO, "Your changes have been saved...")
		if 'Preview' in request.POST:
			if form.is_valid():
				content = form.cleaned_data['content']
				tokens = lex.get_tokens(content)
				result = parse.get_form(tokens)
				context = {
					'checklist': checklist,
					'result': result
				}
				return render(request, 'view_checklist.html', context)
    else:
        form = ChecklistForm(instance=checklist)
    context['action'] = '/checklist/%s/edit' % id
    context['form'] = form
    return render(request, 'user/edit_checklist.html', context)
コード例 #3
0
def edit_checklist(request, id):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/')
    checklist = Checklist.objects.get(id=id)
    if not checklist.owner == request.user:
        return HttpResponseRedirect('/')
    context = {}
    if request.method == 'POST':

        form = ChecklistForm(request.POST, instance=checklist)
        if 'Save' in request.POST:
            if form.is_valid():
                form.save()
        messages.add_message(request, messages.INFO,
                             "Your changes have been saved...")
        if 'Preview' in request.POST:
            if form.is_valid():
                content = form.cleaned_data['content']
                tokens = lex.get_tokens(content)
                result = parse.get_form(tokens)
                context = {'checklist': checklist, 'result': result}
                return render(request, 'view_checklist.html', context)
    else:
        form = ChecklistForm(instance=checklist)
    context['action'] = '/checklist/%s/edit' % id
    context['form'] = form
    return render(request, 'user/edit_checklist.html', context)
コード例 #4
0
ファイル: test_lex.py プロジェクト: ntoll/checklistDSL
 def test_comments_ignored(self):
     """
     Ensures comments (//) are ignored.
     """
     data = "// This is a comment\n// So is this\n\n// One final comment."
     tokens = get_tokens(data)
     self.assertEqual(0, len(tokens),
         "Got tokens when none were expected: %s" % tokens)
コード例 #5
0
ファイル: views.py プロジェクト: checklisthq/checklisthq.com
def view_checklist(request, id):
    checklist = Checklist.objects.get(id=id)
    tokens = lex.get_tokens(checklist.content)
    result = parse.get_form(tokens)
    context = {
        'checklist': checklist,
        'result': result
    }
    return render(request, 'view_checklist.html', context)
コード例 #6
0
ファイル: test_lex.py プロジェクト: ntoll/checklistDSL
 def test_or_item(self):
     """
     Ensures items that can be ORed together are correctly identified.
     """
     data = "() An item\n() An item\n\n() An item"
     tokens = get_tokens(data)
     self.assertEqual(3, len(tokens),
         "Got the wrong number of tokens: %s" % tokens)
     for t in tokens:
         self.assertEqual("OR_ITEM", t.token)
         self.assertEqual("An item", t.value)
コード例 #7
0
ファイル: views.py プロジェクト: checklisthq/checklisthq.com
def preview_checklist(request):
    """
    Takes a request from the markitup editor and returns a preview.
    """
    result = ''
    if request.method == 'POST':
        if 'data' in request.POST:
            raw_data = request.POST['data']
            tokens = lex.get_tokens(raw_data)
            result = parse.get_form(tokens)
    return render(request, 'preview.html', {'content': result})
コード例 #8
0
def preview_checklist(request):
    """
    Takes a request from the markitup editor and returns a preview.
    """
    result = ''
    if request.method == 'POST':
        if 'data' in request.POST:
            raw_data = request.POST['data']
            tokens = lex.get_tokens(raw_data)
            result = parse.get_form(tokens)
    return render(request, 'preview.html', {'content': result})
コード例 #9
0
ファイル: views.py プロジェクト: checklisthq/checklisthq.com
def print_checklist(request, id):
    checklist = Checklist.objects.get(id=id)
    modified = checklist.modified
    tokens = lex.get_tokens(checklist.content)
    result = parse.get_form(tokens)
    context = {
        'checklist': checklist,
        'result': result,
        'modified': modified,
        'username': checklist.owner.username
    }
    return render(request, 'print_checklist.html', context)
コード例 #10
0
def print_checklist(request, id):
    checklist = Checklist.objects.get(id=id)
    modified = checklist.modified
    tokens = lex.get_tokens(checklist.content)
    result = parse.get_form(tokens)
    context = {
        'checklist': checklist,
        'result': result,
        'modified': modified,
        'username': checklist.owner.username
    }
    return render(request, 'print_checklist.html', context)
コード例 #11
0
ファイル: test_lex.py プロジェクト: ntoll/checklistDSL
    def test_text(self):
        """
        Ensures paragraphs of text are correctly identified in various contexts.

        Since this is a rather greedy regex I'm testing that it doesn't gobble
        up the others too.
        """
        # Do not misidentify headers
        data ="= Not text ="
        tokens = get_tokens(data)
        self.assertNotEqual("TEXT", tokens[0].token)
        # Do not misidentify comments
        data ="// Not text"
        tokens = get_tokens(data)
        self.assertEqual(0, len(tokens))
        # Do not misidentify AND items
        data ="[] Not text"
        tokens = get_tokens(data)
        self.assertNotEqual("TEXT", tokens[0].token)
        # Do not misidentify OR items
        data ="() Not text"
        tokens = get_tokens(data)
        self.assertNotEqual("TEXT", tokens[0].token)
        # Do not misidentify breaks
        data ="----"
        tokens = get_tokens(data)
        self.assertNotEqual("TEXT", tokens[0].token)
        # Some real text
        data = "This is some text"
        tokens = get_tokens(data)
        self.assertEqual("TEXT", tokens[0].token)
        self.assertEqual("This is some text", tokens[0].value)
コード例 #12
0
ファイル: test_lex.py プロジェクト: ntoll/checklistDSL
    def test_good_case(self):
        """
        Process a checklist with all the various tokenisable elements in it.
        """

        data = """= A Heading =

        // A comment that isn't rendered.

        Some explanatory text at the start of the list.

        This can be several paragraphs.

        [] A single item in a checklist

        Each item immediately below belongs to a single choice list.
        [] Item 1
        [] Item 2
        [] Item 3

        The following items are OR'd (rather than AND'd) together.
        () {doctor, nurse} Item 1
        () {doctor} Item 2
        () Item 3

        Roles authorised to fulfil items are listed in curly brackets.

        ---

        You can crete a break with three or more minus signs.
        """

        tokens = get_tokens(data)
        # Simply check we get the right number of tokens of the right type.
        self.assertEqual(15, len(tokens), tokens)
        self.assertEqual('HEADING', tokens[0].token)
        self.assertEqual('TEXT', tokens[1].token)
        self.assertEqual('TEXT', tokens[2].token)
        self.assertEqual('AND_ITEM', tokens[3].token)
        self.assertEqual('TEXT', tokens[4].token)
        self.assertEqual('AND_ITEM', tokens[5].token)
        self.assertEqual('AND_ITEM', tokens[6].token)
        self.assertEqual('AND_ITEM', tokens[7].token)
        self.assertEqual('TEXT', tokens[8].token)
        self.assertEqual('OR_ITEM', tokens[9].token)
        self.assertEqual('OR_ITEM', tokens[10].token)
        self.assertEqual('OR_ITEM', tokens[11].token)
        self.assertEqual('TEXT', tokens[12].token)
        self.assertEqual('BREAK', tokens[13].token)
        self.assertEqual('TEXT', tokens[14].token)
コード例 #13
0
ファイル: test_lex.py プロジェクト: ntoll/checklistDSL
 def test_heading(self):
     """
     Ensures headings are correctly identified in various contexts.
     """
     # A heading that will eventually become <h1>
     data = "= A heading ="
     tokens = get_tokens(data)
     self.assertEqual("HEADING", tokens[0].token)
     self.assertEqual("A heading", tokens[0].value)
     self.assertEqual(1, tokens[0].size)
     # A heading that will eventually become <h6>
     data = "====== A small heading ======"
     tokens = get_tokens(data)
     self.assertEqual("HEADING", tokens[0].token)
     self.assertEqual("A small heading", tokens[0].value)
     self.assertEqual(6, tokens[0].size)
     # A heading can include punctuation characters too
     data = "== This is a heading! (Or so it would seem) =="
     tokens = get_tokens(data)
     self.assertEqual("HEADING", tokens[0].token)
     self.assertEqual("This is a heading! (Or so it would seem)",
         tokens[0].value)
     self.assertEqual(2, tokens[0].size)
コード例 #14
0
ファイル: test_lex.py プロジェクト: ntoll/checklistDSL
 def test_or_item_with_roles(self):
     """
     Ensures items may have roles assigned to them via a list in curly
     brackets.
     """
     data = "() {doctor, nurse} An item\n() An item"
     tokens = get_tokens(data)
     self.assertEqual(2, len(tokens),
         "Got the wrong number of tokens: %s" % tokens)
     self.assertEqual("OR_ITEM", tokens[0].token)
     self.assertEqual("An item", tokens[0].value)
     self.assertEqual(['doctor', 'nurse'], tokens[0].roles)
     self.assertEqual("OR_ITEM", tokens[1].token)
     self.assertEqual("An item", tokens[1].value)
     self.assertEqual(None, tokens[1].roles)
コード例 #15
0
def view_checklist(request, id):
    checklist = Checklist.objects.get(id=id)
    tokens = lex.get_tokens(checklist.content)
    result = parse.get_form(tokens)
    context = {'checklist': checklist, 'result': result}
    return render(request, 'view_checklist.html', context)