Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
Merge 0651ccb into fa91827
Browse files Browse the repository at this point in the history
  • Loading branch information
romifz committed Aug 31, 2020
2 parents fa91827 + 0651ccb commit d0a8d5a
Show file tree
Hide file tree
Showing 39 changed files with 5,429 additions and 266 deletions.
11 changes: 11 additions & 0 deletions default/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ def wrap(request, *args, **kwargs):
request.session.pop(key, None)
return val
return wrap


def require_get_param(param_name):
def decorator(function):
@wraps(function)
def wrap(request, *args, **kwargs):
if param_name not in request.GET:
return JsonResponse({'error': _('The {} parameter is required'.format(param_name))}, status=400)
return function(request, *args, **kwargs)
return wrap
return decorator
115 changes: 113 additions & 2 deletions default/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.utils.translation import gettext_lazy as _

from default.util import ocds_tags
from default.util import get_schema_field_lists, ocds_tags


def _get_extension_keys(data):
Expand All @@ -10,14 +10,50 @@ def _get_extension_keys(data):
yield key


class OptionClassCheckboxSelectMultiple(forms.CheckboxSelectMultiple):
template_name = 'default/widget/checkbox-multiple.html'
option_template_name = 'default/widget/checkbox.html'


class MappingSheetOptionsForm(forms.Form):
type = forms.ChoiceField(choices=(('select', _('Select a schema and version')),
('url', _('Provide a URL')),
('file', _('Upload a file')),
('extension', _('For an OCDS Extension'))),
initial='select',
error_messages={'required': _('Please choose an operation type')})
select_url = forms.URLField(required=False, label=_('Select a schema and version'))
select_url = forms.ChoiceField(required=False, label=_('Select a schema and version'),
widget=forms.Select(attrs={'class': 'form-control'}),
choices=(
('1.1', (
('https://standard.open-contracting.org/1.1/en/release-schema.json',
'(1.1) Release'),
('https://standard.open-contracting.org/1.1/en/release-package-schema.json',
'(1.1) Release Package'),
('https://standard.open-contracting.org/1.1/en/record-package-schema.json',
'(1.1) Record Package')
)
),
('1.1 (Español)', (
('http://standard.open-contracting.org/1.1/es/release-schema.json',
'(1.1) (Español) Release'),
('http://standard.open-contracting.org/1.1/es/release-schema.json',
'(1.1) (Español) Paquete de Release'),
('http://standard.open-contracting.org/1.1/es/record-package-schema.json',
'(1.1) (Español) Paquete de Record')
)
),
('1.0', (
('https://standard.open-contracting.org/schema/1__0__3/release-schema.json',
'(1.0) Release'),
('https://standard.open-contracting.org/schema/'
+ '1__0__3/release-package-schema.json',
'(1.0) Release Package'),
('https://standard.open-contracting.org/schema/'
+ '1__0__3/record-package-schema.json',
'(1.0) Record Package'))
)
))
custom_url = forms.URLField(required=False, label=_('Provide the URL to a custom schema below'))
custom_file = forms.FileField(required=False, label=_('Upload a file'))
version = forms.ChoiceField(required=False, label=_('Please select an OCDS version'),
Expand Down Expand Up @@ -55,3 +91,78 @@ def clean(self):
def get_extension_fields(self):
# this method returns a list of BoundField and it is used in the template
return list(filter(lambda field: field.name.startswith('extension_url_'), [field for field in self]))


class UnflattenOptionsForm(forms.Form):
schema = forms.ChoiceField(label=_('Schema version'),
choices=(
('https://standard.open-contracting.org/1.1/en/release-schema.json',
'1.1'),
('https://standard.open-contracting.org/1.1/es/release-schema.json',
'1.1 (Español)'),
('https://standard.open-contracting.org/schema/1__0__3/release-schema.json',
'1.0')),
widget=forms.Select(attrs={'class': 'form-control'}))
output_format = forms.MultipleChoiceField(required=True,
label=_('Output formats'),
initial=('csv', 'xlsx'),
choices=(('csv', 'CSV'),
('xlsx', 'Excel')),
widget=OptionClassCheckboxSelectMultiple(
attrs={'option_class': 'checkbox-inline'})
)
use_titles = forms.ChoiceField(required=True,
label=_('Use titles instead of field names'),
choices=((True, _('Yes')), (False, _('No'))),
widget=forms.Select(attrs={'class': 'form-control'}),
initial=False)
filter_field = forms.ChoiceField(required=False,
help_text=_('Select the field (top level fields only)'),
widget=forms.Select(attrs={'class': 'form-control'}),
error_messages={'invalid_choice': _('%(value)s is not a valid choice. Choose a '
'valid field from the schema selected.')})
filter_value = forms.CharField(required=False,
help_text=_('Enter a value'),
widget=forms.TextInput(attrs={'class': 'form-control'}))

preserve_fields = forms.MultipleChoiceField(required=False,
label=_('Include the following fields only'),
help_text=_('Use the tree to select the fields. Top-level required '
'fields are disabled'))

remove_empty_schema_columns = forms.ChoiceField(required=True,
label=_('Remove empty schema columns'),
choices=((True, _('Yes')), (False, _('No'))),
initial=False,
widget=forms.Select(attrs={'class': 'form-control'}))

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
try:
schema_valid = bool(self.fields['schema'].clean(self.data.get('schema')))
except forms.ValidationError:
schema_valid = False
if self.is_bound and schema_valid:
preserve_fields_choices, top_level_fields_choices = get_schema_field_lists(self.data.get('schema'))
self.fields['preserve_fields'].choices = preserve_fields_choices
self.fields['filter_field'].choices = top_level_fields_choices

def clean_output_format(self):
return 'all' if len(self.cleaned_data['output_format']) > 1 else self.cleaned_data['output_format'][0]

def clean_use_titles(self):
return bool(not self.cleaned_data['use_titles'] == 'False')

def clean_remove_empty_schema_columns(self):
return bool(not self.cleaned_data['remove_empty_schema_columns'] == 'False')

def clean(self):
cleaned_data = super().clean()

# filter_field is not validated if schema is invalid
if 'schema' in cleaned_data.keys():
if bool(cleaned_data['filter_field']) ^ bool(cleaned_data['filter_value']):
self.add_error('filter_field', _('Define both the field and value to filter data'))

def non_empty_values(self):
return {key: value for key, value in self.cleaned_data.items() if value}
7 changes: 6 additions & 1 deletion default/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
float: left;
margin-right: 10px;
margin-top: -8px;
color: #9BAF00;
color: #9BAF00;
}
.schema-nav {
margin-bottom: 10px;
Expand Down Expand Up @@ -94,3 +94,8 @@
.panel-title a .control .glyphicon{
top: 5px;
}

#tree-container{
height: 400px;
overflow-y: auto;
}
21 changes: 20 additions & 1 deletion default/static/css/uploader.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,38 @@
position: absolute;
z-index: -1;
}
.drop-area.empty label

.drop-area label
{
cursor: pointer;
border-bottom: dashed 2px;
}

.drop-area.empty label
{
border-bottom: dashed 2px #fff;
}

.fileinput-button label
{
margin: 0;
}

.drop-area label:hover
{
border-bottom: dotted 2px;
}

.drop-area.empty label:hover
{
border-bottom: dotted 2px #fff;
}
#publishedDate {
width: 220px;
}
.options-link {
padding: 0 5px;
}
.options-link:hover, .options-link:active {
text-decoration: None;
}
102 changes: 102 additions & 0 deletions default/static/js/jquery.typewatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* TypeWatch 3
*
* Examples/Docs: github.com/dennyferra/TypeWatch
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/

!function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof exports === 'object') {
factory(require('jquery'));
} else {
factory(root.jQuery);
}
}(this, function($) {
'use strict';
$.fn.typeWatch = function(o) {
// The default input types that are supported
var _supportedInputTypes =
['TEXT', 'TEXTAREA', 'PASSWORD', 'TEL', 'SEARCH', 'URL', 'EMAIL', 'DATETIME', 'DATE', 'MONTH', 'WEEK', 'TIME', 'DATETIME-LOCAL', 'NUMBER', 'RANGE', 'DIV'];

// Options
var options = $.extend({
wait: 750,
callback: function() { },
highlight: true,
captureLength: 2,
allowSubmit: false,
inputTypes: _supportedInputTypes
}, o);

function checkElement(timer, override) {
var value = timer.type === 'DIV'
? jQuery(timer.el).html()
: jQuery(timer.el).val();

// If has capture length and has changed value
// Or override and has capture length or allowSubmit option is true
// Or capture length is zero and changed value
if ((value.length >= options.captureLength && value != timer.text)
|| (override && (value.length >= options.captureLength || options.allowSubmit))
|| (value.length == 0 && timer.text))
{
timer.text = value;
timer.cb.call(timer.el, value);
}
};

function watchElement(elem) {
var elementType = (elem.type || elem.nodeName).toUpperCase();
if (jQuery.inArray(elementType, options.inputTypes) >= 0) {

// Allocate timer element
var timer = {
timer: null,
text: (elementType === 'DIV') ? jQuery(elem).html() : jQuery(elem).val(),
cb: options.callback,
el: elem,
type: elementType,
wait: options.wait
};

// Set focus action (highlight)
if (options.highlight && elementType !== 'DIV')
jQuery(elem).focus(function() { this.select(); });

// Key watcher / clear and reset the timer
var startWatch = function(evt) {
var timerWait = timer.wait;
var overrideBool = false;
var evtElementType = elementType;

// If enter key is pressed and not a TEXTAREA or DIV
if (typeof evt.keyCode != 'undefined' && evt.keyCode == 13
&& evtElementType !== 'TEXTAREA' && elementType !== 'DIV') {
timerWait = 1;
overrideBool = true;
}

var timerCallbackFx = function() {
checkElement(timer, overrideBool)
}

// Clear timer
clearTimeout(timer.timer);
timer.timer = setTimeout(timerCallbackFx, timerWait);
};

jQuery(elem).on('keydown paste cut input', startWatch);
}
};

// Watch each element
return this.each(function() {
watchElement(this);
});
};
});

0 comments on commit d0a8d5a

Please sign in to comment.