Exemplo n.º 1
0
def test_classes():
    ops = [{
        "insert": "Quill",
        "attributes": {
            "font": "monospace",
            "size": "huge"
        }
    }]
    source = '<p><span class="ql-font-monospace ql-size-huge">Quill</span></p>'
    assert html.render(ops) == source

    ops = [{
        "insert": "Quill",
        "attributes": {
            "font": "serif",
            "size": "large"
        }
    }]
    source = '<p><span class="ql-font-serif ql-size-large">Quill</span></p>'
    assert html.render(ops) == source

    ops = [{
        "insert": "Quill",
        "attributes": {
            "font": "sans-serif",
            "size": "small"
        }
    }]
    source = '<p><span class="ql-size-small">Quill</span></p>'
    assert html.render(ops) == source
Exemplo n.º 2
0
def test_script():
    ops = [{"insert": "Quill", "attributes": {"script": "sub"}}]
    source = '<p><sub>Quill</sub></p>'
    assert html.render(ops) == source

    ops = [{"insert": "Quill", "attributes": {"script": "super"}}]
    source = '<p><sup>Quill</sup></p>'
    assert html.render(ops) == source
Exemplo n.º 3
0
def test_strong():
    ops = [{"insert": "Quill", "attributes": {"bold": True}}]
    source = '<p><strong>Quill</strong></p>'
    assert html.render(ops) == source

    ops = [{"insert": "Quill", "attributes": {"strong": True}}]
    source = '<p><strong>Quill</strong></p>'
    assert html.render(ops) == source
Exemplo n.º 4
0
def test_em():
    ops = [{"insert": "Quill", "attributes": {"italic": True}}]
    source = '<p><em>Quill</em></p>'
    assert html.render(ops) == source

    ops = [{"insert": "Quill", "attributes": {"em": True}}]
    source = '<p><em>Quill</em></p>'
    assert html.render(ops) == source
Exemplo n.º 5
0
def test_header():
    ops = [{"insert": "Quill", "attributes": {"header": 1}}]
    source = '<h1>Quill</h1>'
    assert html.render(ops) == source

    ops = [{"insert": "Quill", "attributes": {"header": 5}}]
    source = '<h5>Quill</h5>'
    assert html.render(ops) == source

    ops = [{"insert": "Quill"}, {"insert": "\n", "attributes": {"header": 2}}]
    source = '<h2>Quill</h2>'
    assert html.render(ops) == source
Exemplo n.º 6
0
def test_lists():
    ops = [{
        "insert": "item 1"
    }, {
        "insert": "\n",
        "attributes": {
            "list": "ordered",
            "indent": 1
        }
    }, {
        "insert": "item 2"
    }, {
        "insert": "\n",
        "attributes": {
            "list": "ordered"
        }
    }, {
        "insert": "item 3"
    }, {
        "insert": "\n",
        "attributes": {
            "list": "ordered"
        }
    }]
    source = "<ol><li class=\"ql-indent-1\">item 1</li><li>item 2</li><li>item 3</li></ol>"
    assert html.render(ops) == source

    ops = [{
        "insert": "item 1"
    }, {
        "insert": "\n",
        "attributes": {
            "list": "bullet",
            "indent": 2
        }
    }, {
        "insert": "item 2"
    }, {
        "insert": "\n",
        "attributes": {
            "list": "bullet"
        }
    }, {
        "insert": "item 3"
    }, {
        "insert": "\n",
        "attributes": {
            "list": "bullet"
        }
    }]
    source = "<ul><li class=\"ql-indent-2\">item 1</li><li>item 2</li><li>item 3</li></ul>"
    assert html.render(ops) == source
Exemplo n.º 7
0
def test_colors():
    ops = [
        {"insert": "quill", "attributes": {"background": "#000000"}}
    ]

    source = '<p><span style="background-color: #000">quill</span></p>'
    assert html.render(ops) == source

    ops = [
        {"insert": "quill", "attributes": {"background": "#000000", "color": "#FFFFFF"}}
    ]

    source = '<p><span style="background-color: #000; color: #FFF">quill</span></p>'
    assert html.render(ops) == source
Exemplo n.º 8
0
def test_direction():
    ops = [
        {"insert": "quill"},
        {"insert": "\n", "attributes": {"direction": "rtl"}}
    ]
    source = '<p class="ql-direction-rtl">quill</p>'
    assert html.render(ops) == source
Exemplo n.º 9
0
def test_codeblock():
    from delta.html import CODE_BLOCK_CLASS
    ops = [
        {"insert":"Quill", "attributes": {"code-block": True}}
    ]
    source = '<pre class="%s" spellcheck="false">Quill</pre>' % CODE_BLOCK_CLASS
    assert html.render(ops) == source
Exemplo n.º 10
0
def test_align():
    ops = [
        {"insert": "quill"},
        {"insert": "\n", "attributes": {"align": "center"}}
    ]
    source = '<p class="ql-align-center">quill</p>'
    assert html.render(ops) == source
Exemplo n.º 11
0
def test_blockquote():
    ops = [
        {'insert': 'One\nTwo\nQuote'}, 
        {'insert': '\n', 'attributes': {'blockquote': True}}
    ]
    source = '<p>One</p><p>Two</p><blockquote>Quote</blockquote>'
    assert html.render(ops) == source
Exemplo n.º 12
0
def test_basics():
    ops = [
        {
            "insert": "Quill\nEditor\n\n"
        },
        {
            "insert": "bold",
            "attributes": {
                "bold": True
            }
        },
        {
            "insert": " and the "
        },
        {
            "insert": "italic",
            "attributes": {
                "italic": True
            }
        },
        {
            "insert": "\n\nNormal\n"
        },
    ]

    source = '<p>Quill</p><p>Editor</p><p><br></p><p><strong>bold</strong> and the <em>italic</em></p><p><br></p><p>Normal</p>'

    assert html.render(ops) == source
Exemplo n.º 13
0
def test_video():
    ops = [
        {"insert":{"video":"https://www.youtube.com/embed/NAb9V08zcBE"}},
        {"insert": "\n"}
    ]
    source = '<iframe class="ql-video" frameborder="0" allowfullscreen="true" src="https://www.youtube.com/embed/NAb9V08zcBE"></iframe><p><br></p>'
    assert html.render(ops) == source
Exemplo n.º 14
0
def test_indent():
    for i in range(1, 9):
        ops = [
            {"insert": "quill", "attributes": {"indent": i}}
        ]
        source = '<p class="ql-indent-%d">quill</p>' % i
        assert html.render(ops) == source
Exemplo n.º 15
0
def test_link():
    ops = [{
        'insert': "example.com",
        "attributes": {
            "link": "http://example.com"
        }
    }]
    source = '<p><a href="http://example.com">example.com</a></p>'
    assert html.render(ops) == source
Exemplo n.º 16
0
    def get_article_as_html(self):
        article_html = ""
        if self.titlePicture:
            article_html = "<img class='img-fluid' src='/pictures/" + Newspicture.query.get(self.titlePicture).path + "'>"
        article_html += "<h1>" + self.title + "</h1>\n"
        article_html += "<p class='ingress'>" + self.ingress + "</p>\n"
        article_html += quill_parser.render(self.text["ops"])

        return article_html
Exemplo n.º 17
0
def test_image_width():
    ops = [{
        'insert': {
            'image': 'https://i.imgur.com/ZMSUFEU.gif'
        },
        'attributes': {
            'width': '196',
            'height': '200'
        }
    }]
    source = '<p><img src="https://i.imgur.com/ZMSUFEU.gif" width="196" height="200"></p>'
    assert html.render(ops) == source
    def render(self, fichier):
        """ Genere le contenu HTML """
        delta = self._message_publication['quilldelta']
        delta_html = html.render(delta['ops'], pretty=True)

        # fichier.write('<html><head>'.encode('utf-8'))
        # fichier.write('<meta charset="UTF-8">\n'.encode('utf-8'))
        # fichier.write((
        #         '<title>%s</title>' % self._message_publication['titre']
        #     ).encode('utf-8'))
        # fichier.write('</head><body>'.encode('utf-8'))
        fichier.write(delta_html.encode('utf-8'))
Exemplo n.º 19
0
def test_unsupported_style_attribute():
    ops = [{
        "insert": "quill",
        "attributes": {
            "color": "var(--some-color)",
            "background": "#000000"
        }
    }]

    source = '<p><span style="background-color: #000">quill</span></p>'
    assert html.render(ops) == source

    ops = [{
        "insert": "quill",
        "attributes": {
            "background": "#000000",
            "color": "#FFFFFF"
        }
    }]

    source = '<p><span style="background-color: #000; color: #FFF">quill</span></p>'
    assert html.render(ops) == source
Exemplo n.º 20
0
def AddCampaignProcess(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        form = AddCampaignForm(request.POST, request.FILES)
        #print(request.FILES['coverImage'])
        # print(request.POST)
        # print(request.FILES)
        # print(form)
        # check whether it's valid:
        if form.is_valid():
            print("is valid")
            # process the data in form.cleaned_data as required
            name = form.cleaned_data['name']
            shortDescription = form.cleaned_data['shortDescription']
            goal = form.cleaned_data['goal']
            a = json.loads(form.cleaned_data['fullDescription'])
            fullDescription = html.render(a["ops"])
            expiredDate = form.cleaned_data['expiredDate']
            coverImage = form.cleaned_data['coverImage']
            ownerID = UserDetail.objects.get(id=request.user.id)
            newCampaign = Campaign(name=name,
                                   shortDescription=shortDescription,
                                   goal=goal,
                                   expiredDate=expiredDate,
                                   coverImage=coverImage,
                                   fullDescription=fullDescription,
                                   ownerID=ownerID)

            newCampaign.save()
            #csrf_token = django.middleware.csrf.get_token(request)
            # redirect to a new URL:
            return render(None, 'vdf/thankyou.html', {"user": request.user.id})

    # if a GET (or any other method) we'll create a blank form
    # else:
    #     form = AddCampaignForm()
    #csrf_token = django.middleware.csrf.get_token(request)
    #return render(None, 'vdf/taochiendich.html', {"user": request.user.id})
    return redirect('/taochiendich')
Exemplo n.º 21
0
def processFeedback(feedback_delta, fvecs, models):
    feedback_html = html.render(json.loads(feedback_delta)['ops'])

    # QUALITY
    try:
        qCase = "Q_high_quality"
        feedback_features = Q_high_quality_text_feature_extractor(
            feedback_html)
        quality_pred = apply_model(feedback_features, fvecs[qCase],
                                   models[qCase])
        output_eng['ops'][1]['insert'] = toFraction(quality_pred)
        output_de['ops'][1]['insert'] = toFraction(quality_pred)
        print("\n Q_high_quality: ", quality_pred, toFraction(quality_pred))
    except:
        print("\nError in calculating Quality\n")
        e = sys.exc_info()
        print(e)

    # HELPFULNESS
    try:
        qCase = "Q_was_helpful"
        feedback_features = Q_was_helpful_text_feature_extractor(feedback_html)
        helpfulness_pred = apply_model(feedback_features, fvecs[qCase],
                                       models[qCase])
        output_eng['ops'][3]['insert'] = toFraction(helpfulness_pred)
        output_de['ops'][3]['insert'] = toFraction(helpfulness_pred)
        print("\n Q_was_helpful: ", helpfulness_pred,
              toFraction(helpfulness_pred))
    except:
        print("\nError in calculating helpfulness\n")
        e = sys.exc_info()
        print(e)

    # CRITICAL ASPECTS
    try:
        qCase = "Q_critical_aspects"
        feedback_features = Q_critical_aspects_text_feature_extractor(
            feedback_html)
        critical_aspects_pred = apply_model(feedback_features, fvecs[qCase],
                                            models[qCase])
        output_eng['ops'][5]['insert'] = toFraction(critical_aspects_pred)
        output_de['ops'][5]['insert'] = toFraction(critical_aspects_pred)
        print("\n Q_critical_aspects: ", critical_aspects_pred,
              toFraction(critical_aspects_pred))
    except:
        print("\nError in calculating critical aspects\n")
        e = sys.exc_info()
        print(e)

    # SUGGESTIONS
    try:
        qCase = "Q_constructive_suggestions"
        feedback_features = Q_constructive_suggestions_text_feature_extractor(
            feedback_html)
        suggestions_pred = apply_model(feedback_features, fvecs[qCase],
                                       models[qCase])
        output_eng['ops'][7]['insert'] = toFraction(suggestions_pred)
        output_de['ops'][7]['insert'] = toFraction(suggestions_pred)
        print("\n Q_constructive_suggestions: ", suggestions_pred,
              toFraction(suggestions_pred))
    except:
        print("\nError in calculating suggestions\n")
        e = sys.exc_info()
        print(e)

    # TASK_RELATED
    # try:
    #    qCase = "Q_task_related"
    #    feedback_features = Q_task_related_text_feature_extractor(feedback_html)
    #    task_related_pred = apply_model(feedback_features, fvecs[qCase], models[qCase])
    #    output_eng['ops'][9]['insert'] = toFraction(task_related_pred)
    #    output_de['ops'][9]['insert'] = toFraction(task_related_pred)
    # except:
    #    print("\nError in calculating related\n")
    #    e = sys.exc_info()
    #    print(e)

    # WEAKNESSES AND STRENGTHS
    try:
        qCase = "Q_highlights_weaknesses_strengths"
        feedback_features = Q_highlights_weaknesses_strengths_text_feature_extractor(
            feedback_html)
        weaknesses_strengths_pred = apply_model(feedback_features,
                                                fvecs[qCase], models[qCase])
        output_eng['ops'][9]['insert'] = toFraction(weaknesses_strengths_pred)
        output_de['ops'][9]['insert'] = toFraction(weaknesses_strengths_pred)
        print("\nWeaknesses: ", weaknesses_strengths_pred,
              toFraction(weaknesses_strengths_pred))
    except:
        print("\nError in calculation strength and weaknesses\n")
        e = sys.exc_info()
        print(e)

    # ARGUMENTATION
    try:
        r = requests.post("http://localhost:5130/",
                          json={"text": feedback_delta['reviewText']})
        output_eng['argmine'] = r.json()
        output_de['argmine'] = r.json()
    except:
        print("\nError in argumentation feedback\n")
        e = sys.exc_info()
        print(e)

    # EASY TO UNDERSTAND
    # try:
    #    qCase = "Q_easy_understand"
    #    feedback_features = Q_easy_understand_text_feature_extractor(feedback_html)
    #    easy_to_understand_pred = apply_model(feedback_features, fvecs[qCase], models[qCase])
    #    output_eng['ops'][13]['insert'] = toFraction(easy_to_understand_pred)
    #    output_de['ops'][13]['insert'] = toFraction(easy_to_understand_pred)
    #    print(easy_to_understand_pred, toFraction(easy_to_understand_pred))
    # except:
    #    print("\nError in calculation easy to understand\n")
    #    e = sys.exc_info()
    #    print(e)

    return {
        'output_eng': json.dumps(output_eng),
        'output_de': json.dumps(output_de)
    }
Exemplo n.º 22
0
 def get_article_as_html_user(self):
     article_html = ""
     article_html += quill_parser.render(self.text["ops"])
     return article_html
Exemplo n.º 23
0
def test_underline():
    ops = [
        {"insert":"Quill", "attributes": {"underline": True}}
    ]
    source = '<p><u>Quill</u></p>'
    assert html.render(ops) == source
 def render(self, delta):
     resultat = html.render(delta['ops'], pretty=True)
     print(resultat)
Exemplo n.º 25
0
def test_error():
    ops = [
        { 'insert': {'image': True} }
    ]
    source = '<p><img></p>'
    assert html.render(ops) == source
Exemplo n.º 26
0
def test_image():
    ops = [
        { 'insert': {'image': 'https://i.imgur.com/ZMSUFEU.gif'} }
    ]
    source = '<p><img src="https://i.imgur.com/ZMSUFEU.gif"></p>'
    assert html.render(ops) == source
Exemplo n.º 27
0
def test_strike():
    ops = [
        {"insert":"Quill", "attributes": {"strike": True}}
    ]
    source = '<p><s>Quill</s></p>'
    assert html.render(ops) == source
Exemplo n.º 28
0
def test_empty():
    ops = [ {"insert": "\n"} ]
    source = "<p><br></p>"
    assert html.render(ops) == source