-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Primeira versão de frontend do style checker
- removido código das annotations (agora usa só o html do include "validator/includes/xml_annotated.html") - adiciono template tag: field_attr para modificar atributos de um form.field, como estilos, classe css, etc. - adiciono settings: VALIDATOR_MAX_UPLOAD_SIZE com valor máximo do upload (512KB) - corrigido contador de erros nas annotations (Fixes: #899) - adiciono clean do campo field, para validar tamanho do arquivo e content_type - melhoras na interface do formulário, validação js, etc
- Loading branch information
Showing
16 changed files
with
544 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
@register.filter_function | ||
def attr(obj, arg1): | ||
""" | ||
Use in templates: | ||
{% load field_attrs %} | ||
then, in a form field: | ||
{{ form.phone|attr:"style=width:143px;background-color:yellow"|attr:"size=30" }} | ||
""" | ||
att, value = arg1.split("=") | ||
obj.field.widget.attrs[att] = value | ||
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# coding: utf-8 | ||
|
||
from django import forms | ||
from django.conf import settings | ||
from django.utils.translation import ugettext as _ | ||
|
||
|
||
STYLECHECKER_TYPE_CHOICES = ( | ||
('url', _('URL')), | ||
('file', _('File')), | ||
) | ||
|
||
|
||
class StyleCheckerForm(forms.Form): | ||
type = forms.ChoiceField(label=_("Type"), choices=STYLECHECKER_TYPE_CHOICES, ) # widget=forms.RadioSelect | ||
url = forms.URLField(label=_("URL"), required=False) | ||
file = forms.FileField(label=_("File"), required=False) | ||
|
||
def clean_file(self): | ||
_file = self.cleaned_data.get('file', None) | ||
if _file: | ||
if _file.content_type != 'text/xml': | ||
raise forms.ValidationError(_(u"This type of file is not allowed! Please select another file.")) | ||
|
||
if _file.size > settings.VALIDATOR_MAX_UPLOAD_SIZE: | ||
raise forms.ValidationError(_(u"The file's size is too large! Please select a smaller file.")) | ||
|
||
return _file | ||
|
||
def clean(self): | ||
type = self.cleaned_data['type'] | ||
url = self.cleaned_data.get('url', None) | ||
file = self.cleaned_data.get('file', None) | ||
|
||
if type == 'url' and not url: | ||
raise forms.ValidationError('if trying to validate via URL, please submit a valid URL') | ||
if type == 'file' and not file: | ||
raise forms.ValidationError('if trying to validate a File, please upload a valid XML file') | ||
|
||
return self.cleaned_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{% extends "base_lv0.html" %} | ||
|
||
{% load i18n %} | ||
{% load static %} | ||
|
||
{% block base_struture %} | ||
<style type="text/css"> | ||
body { margin: 8px !important;} | ||
.container-base {padding-top: 40px;} | ||
</style> | ||
|
||
<div class="navbar navbar-inverse navbar-fixed-top"> | ||
<div class="navbar-inner"> | ||
<div class="container"> | ||
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<a class="brand" href="/">SciELO Manager</a> | ||
<div class="nav-collapse collapse"> | ||
<ul class="nav"> | ||
<li class="active"><a href="{% url validator.packtools.stylechecker %}">Style Checker</a></li> | ||
</ul> | ||
</div><!--/.nav-collapse --> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="container container-base"> | ||
{% block main_content %} | ||
|
||
{% endblock main_content %} | ||
</div> <!-- /container --> | ||
|
||
{% endblock base_struture %} |
69 changes: 69 additions & 0 deletions
69
scielomanager/validator/templates/validator/includes/xml_annotated.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{% load i18n %} | ||
{% load trans_status %} | ||
{% load static %} | ||
|
||
<link href="{% static 'css/prism.css' %}" rel="stylesheet" /> | ||
<style type="text/css"> | ||
/* OVERRIDE STYLES OF PRIMSM | ||
.line-highlight { left: 15px;} | ||
FIXES STYLES OF PRIMSM */ | ||
code, pre { font-size: 12px; } | ||
code[class*="language-"], | ||
pre[class*="language-"]{ -moz-tab-size: 2; -o-tab-size: 2; tab-size: 2;} | ||
.line-highlight:before, .line-highlight[data-end]:after { | ||
border-radius: 0; | ||
left: 0; | ||
min-height: 20px; | ||
min-width: 30px; | ||
padding: 0; | ||
top: 0; | ||
} | ||
</style> | ||
|
||
{% if not xml_data.can_be_analyzed.0 %} | ||
{# could not be analyzed #} | ||
<div class="alert alert-warning"> | ||
<h4><i class="icon-minus-sign"></i> {% trans "The XML could not be analyzed" %}</h4> | ||
<p>{{ xml_data.can_be_analyzed.1 }}</p> | ||
</div> | ||
{% elif not xml_data.annotations %} | ||
{# xml without annotations #} | ||
<div class="alert alert-success"> | ||
<i class="icon-ok"></i> {% trans "The XML has no errors" %} | ||
</div> | ||
{% else %} | ||
{# xml analyzed and with annotations #} | ||
<div class="alert alert-block alert-error"> | ||
<h4 class="alert-heading"> {% trans "The XML have some errors" %}:</h4> | ||
</div> | ||
{% if xml_data.validation_errors %} | ||
<table class="table table-striped table-condensed"> | ||
<thead> | ||
<tr> | ||
<th>{% trans "Level" %}:</th> | ||
<th>{% trans "Line" %}:</th> | ||
<th>{% trans "Column" %}:</th> | ||
<th>{% trans "Message" %}:</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for error in xml_data.validation_errors.results %} | ||
<tr> | ||
<td><span class="label label-{% trans_status error.level to_label='True' %}">{{ error.level }}</span></td> | ||
<td>{{ error.line }}</td> | ||
<td>{{ error.column }}</td> | ||
<td>{{ error.message }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endif %} | ||
{# XML ANNOTATED #} | ||
<pre | ||
class="line-numbers language-markup pre-scrollable" | ||
{% if xml_data.validation_errors and xml_data.validation_errors.error_lines %} | ||
data-line='{{ xml_data.validation_errors.error_lines }}' | ||
{% endif %} | ||
><code class="language-markup">{{ xml_data.annotations }}</code></pre> | ||
{% endif %} | ||
<script type="text/javascript" src="{% static 'js/prism.js' %}"></script> |
Oops, something went wrong.