Commit 39d12f86ea59334b78f417b4b97024d4f3768e67
1 parent
d641183a
Eksport atrybutu 'rok'; uzupełnienie parametrów eksportu możliwych do ustawienia…
… w interfejsie administratora (o 'homonym numbers' oraz 'form qualifiers'; poprawienie zachowania checkboxów przy odczytywaniu danych konfiguracji eksportu; wprowadzenie dodatkowych parametrów przy wywołaniu eksportu (--nocopyright oraz --exportyear)
Showing
6 changed files
with
79 additions
and
15 deletions
dictionary/models.py
... | ... | @@ -1129,8 +1129,8 @@ class SavedExportData(Model): |
1129 | 1129 | 'variant': temp_dict['variant'], |
1130 | 1130 | 'refl': bool(temp_dict.get('refl', False)), |
1131 | 1131 | 'commonness': bool(temp_dict.get('commonness', False)), |
1132 | - 'form_qualifiers': True, | |
1133 | - 'homonym_numbers': True, | |
1132 | + 'form_qualifiers': bool(temp_dict.get('form_qualifiers', False)), | |
1133 | + 'homonym_numbers': bool(temp_dict.get('homonym_numbers', False)), | |
1134 | 1134 | 'copyright': temp_dict['copyright'], |
1135 | 1135 | } |
1136 | 1136 | magic_ids = set() |
... | ... |
export/forms.py
... | ... | @@ -19,6 +19,8 @@ class ExportForm(Form): |
19 | 19 | label=_(u'variant')) |
20 | 20 | refl = BooleanField(label=_(u'tags with "refl"'), required=False) |
21 | 21 | commonness = BooleanField(label=_(u'commonness labels'), required=False) |
22 | + homonym_numbers = BooleanField(label=_(u'homonym numbers'), required=False) | |
23 | + form_qualifiers = BooleanField(label=_(u'form qualifiers'), required=False) | |
22 | 24 | copyright = CharField(widget=Textarea(attrs={'cols': 80, 'rows': 40})) |
23 | 25 | # excluding_qualifiers = QualifiersField( |
24 | 26 | # required=False, label=_(u'excluding qualifiers')) |
... | ... |
export/lexeme_export.py
... | ... | @@ -68,9 +68,10 @@ class LexemeExport(object): |
68 | 68 | 'appas': 'v', |
69 | 69 | } |
70 | 70 | |
71 | - def __init__(self, export_data_name=None, data=None, output_file=None): | |
71 | + def __init__(self, export_data_name=None, nocopy_flag = None, expyear_flag = None, data=None, output_file=None): | |
72 | 72 | self.homonym_entries = None |
73 | 73 | self.homonyms_with_numbers = None |
74 | + | |
74 | 75 | if export_data_name: |
75 | 76 | export_data = SavedExportData.objects.get(name=export_data_name) |
76 | 77 | self.data = export_data.get_data() |
... | ... | @@ -88,7 +89,15 @@ class LexemeExport(object): |
88 | 89 | 'copyright': u'', |
89 | 90 | } |
90 | 91 | self.output_file = output_file or sys.stdout |
91 | - self.copyright_file = open('copyright.txt', 'w') | |
92 | + if expyear_flag: | |
93 | + try: | |
94 | + self.YEAR_ATTR = LexemeAttribute.objects.get(name=u'rok') | |
95 | + except LexemeAttribute.DoesNotExist: | |
96 | + self.YEAR_ATTR = None | |
97 | + else: | |
98 | + self.YEAR_ATTR = None | |
99 | + self.nocopy = nocopy_flag | |
100 | +# self.copyright_file = open('copyright.txt', 'w') | |
92 | 101 | self.vocabs_placeholders = ', '.join('%s' for v in self.data['vocabs']) |
93 | 102 | |
94 | 103 | if self.data['antivocabs']: |
... | ... | @@ -149,6 +158,14 @@ class LexemeExport(object): |
149 | 158 | select qualifier_id from kwalifikatory_zakonczen |
150 | 159 | where ending_id = z.id))) |
151 | 160 | ''' |
161 | + | |
162 | + self.year_select = ''', | |
163 | + (select string_agg(lavalue.value, '|') | |
164 | + from dictionary_lexemeattributevalue lavalue inner join dictionary_lexemeattribute la on lavalue.attribute_id = la.id | |
165 | + inner join dictionary_lexemeav lav on lavalue.id = lav.attribute_value_id | |
166 | + where la.name = 'rok' and lav.lexeme_id = l.id) | |
167 | + ''' | |
168 | + | |
152 | 169 | self.commonness_select = ''', |
153 | 170 | (select string_agg(nazwa, '|') |
154 | 171 | from wartosci_klasyfikacji |
... | ... | @@ -246,6 +263,17 @@ class LexemeExport(object): |
246 | 263 | quals = row[i] |
247 | 264 | if UNDERSCORES and quals: |
248 | 265 | quals = quals.replace(' ', '_') |
266 | + try: | |
267 | + if row[i+1]: | |
268 | + year_attr = row[i+1].strip() | |
269 | + else: | |
270 | + year_attr = None | |
271 | + if quals and year_attr: | |
272 | + quals = quals + u'|' + year_attr | |
273 | + elif year_attr: | |
274 | + quals = year_attr | |
275 | + except IndexError: | |
276 | + pass | |
249 | 277 | if self.data['homonym_numbers'] and entry in self.homonym_entries: |
250 | 278 | if (entry, main_pos) in self.homonyms_with_numbers: |
251 | 279 | assert hn |
... | ... | @@ -297,7 +325,7 @@ class LexemeExport(object): |
297 | 325 | if not nested: |
298 | 326 | params = self.params_part + flatten(self.data['magic_qualifiers']) |
299 | 327 | query = """ |
300 | -select distinct l.id, haslo, %(select)s %(clas_field)s %(qual_field)s | |
328 | +select distinct l.id, haslo, %(select)s %(clas_field)s %(qual_field)s %(year_attr)s | |
301 | 329 | %(table_joins)s |
302 | 330 | left join dictionary_lexemeav refl |
303 | 331 | on (l.id = refl.lexeme_id and %(refl)s) |
... | ... | @@ -310,7 +338,7 @@ where ls.slownik in (%(vocabs)s) and %(antivocabs)s %(x_qual)s %(table_clause)s |
310 | 338 | else: |
311 | 339 | params = self.params_part |
312 | 340 | query = """ |
313 | -select distinct g.id, g.haslo as haslo, %(select)s %(clas_field)s %(qual_field)s | |
341 | +select distinct g.id, g.haslo as haslo, %(select)s %(clas_field)s %(qual_field)s %(year_attr)s | |
314 | 342 | %(table_joins)s |
315 | 343 | join odsylacze on l.id=l_id_od |
316 | 344 | join leksemy g on (l_id_do=g.id and g.usuniety = false) |
... | ... | @@ -332,6 +360,8 @@ where ls.slownik in (%(vocabs)s) and %(antivocabs)s %(x_qual)s %(table_clause)s |
332 | 360 | self.commonness_select if self.data['commonness'] else '', |
333 | 361 | 'qual_field': |
334 | 362 | self.qualifier_select if self.data['form_qualifiers'] else '', |
363 | + 'year_attr': | |
364 | + self.year_select if self.data['form_qualifiers'] and self.YEAR_ATTR else '', | |
335 | 365 | 'select': self.select, |
336 | 366 | 'table_joins': self.table_joins, |
337 | 367 | 'table_clause': self.table_clause, |
... | ... | @@ -363,6 +393,12 @@ where ls.slownik in (%(vocabs)s) and %(antivocabs)s %(x_qual)s %(table_clause)s |
363 | 393 | if self.data['form_qualifiers']: |
364 | 394 | quals = '|'.join(skr.qualifiers.values_list( |
365 | 395 | 'label', flat=True)) |
396 | + if self.YEAR_ATTR: | |
397 | + year_attr = skr.attribute_value(self.YEAR_ATTR) | |
398 | + if quals and year_attr: | |
399 | + quals = quals + u'|' + year_attr.value | |
400 | + elif year_attr: | |
401 | + quals = year_attr.value | |
366 | 402 | output_row += (quals,) |
367 | 403 | acc.append(output_row) |
368 | 404 | |
... | ... | @@ -414,7 +450,8 @@ where ls.slownik in (%(vocabs)s) and %(antivocabs)s %(x_qual)s %(table_clause)s |
414 | 450 | 'month': today.month, |
415 | 451 | 'day': today.day, |
416 | 452 | } |
417 | - if copyright: | |
453 | + if copyright and not self.nocopy: | |
454 | + self.copyright_file = open('copyright.txt', 'w') | |
418 | 455 | uniprint(copyright, file=self.copyright_file) |
419 | 456 | for r in export_data: |
420 | 457 | uniprint( |
... | ... |
export/locale/pl/LC_MESSAGES/django.po
... | ... | @@ -7,7 +7,7 @@ msgid "" |
7 | 7 | msgstr "" |
8 | 8 | "Project-Id-Version: PACKAGE VERSION\n" |
9 | 9 | "Report-Msgid-Bugs-To: \n" |
10 | -"POT-Creation-Date: 2016-03-25 17:56+0100\n" | |
10 | +"POT-Creation-Date: 2017-02-24 12:27+0100\n" | |
11 | 11 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
12 | 12 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
13 | 13 | "Language-Team: LANGUAGE <LL@li.org>\n" |
... | ... | @@ -38,11 +38,19 @@ msgstr "tagi z \"refl\"" |
38 | 38 | msgid "commonness labels" |
39 | 39 | msgstr "etykiety pospolitości" |
40 | 40 | |
41 | -#: forms.py:28 | |
41 | +#: forms.py:22 | |
42 | +msgid "homonym numbers" | |
43 | +msgstr "rozpodabniacze" | |
44 | + | |
45 | +#: forms.py:23 | |
46 | +msgid "form qualifiers" | |
47 | +msgstr "kwalifikatory" | |
48 | + | |
49 | +#: forms.py:30 | |
42 | 50 | msgid "lexeme qual." |
43 | 51 | msgstr "kwal. leksemu" |
44 | 52 | |
45 | -#: forms.py:29 | |
53 | +#: forms.py:31 | |
46 | 54 | msgid "tag pattern" |
47 | 55 | msgstr "wzorzec tagu" |
48 | 56 | |
... | ... |
export/management/commands/export_lexemes.py
... | ... | @@ -8,5 +8,19 @@ class Command(BaseCommand): |
8 | 8 | help = 'Temporary export script' |
9 | 9 | args = 'export_data' |
10 | 10 | |
11 | + def add_arguments(self, parser): | |
12 | + # Named (optional) arguments | |
13 | + parser.add_argument('--nocopyright', | |
14 | + action='store_true', | |
15 | + dest='nocopy', | |
16 | + default=False, | |
17 | + help='Do not create copyright.txt file.') | |
18 | + parser.add_argument('--exportyear', | |
19 | + action='store_true', | |
20 | + dest='expyear', | |
21 | + default=False, | |
22 | + help='Export "year" attribute with lexeme qualifiers.') | |
23 | + | |
24 | + | |
11 | 25 | def handle(self, export_data=None, **options): |
12 | - LexemeExport(export_data_name=export_data).export() | |
26 | + LexemeExport(export_data_name=export_data, nocopy_flag=options['nocopy'], expyear_flag=options['expyear']).export() | |
... | ... |
export/static/js/export.js
... | ... | @@ -82,8 +82,10 @@ function put_data(json) { |
82 | 82 | "use strict"; |
83 | 83 | var data = $.parseJSON(json), |
84 | 84 | qualifier_rows = {}, vocabs = [], antivocabs = [], parts; |
85 | - $('#id_refl').attr('checked', false); | |
86 | - $('#id_commonness').attr('checked', false); | |
85 | + $('#id_refl').prop('checked', false); | |
86 | + $('#id_commonness').prop('checked', false); | |
87 | + $('#id_homonym_numbers').prop('checked', false); | |
88 | + $('#id_form_qualifiers').prop('checked', false); | |
87 | 89 | $('#magic-qualifiers').find('li').remove(); |
88 | 90 | $.each(data, function (i, item) { |
89 | 91 | if (item.name === 'vocabs') { |
... | ... | @@ -95,8 +97,9 @@ function put_data(json) { |
95 | 97 | if (item.name === 'variant') { |
96 | 98 | $('#id_variant').val(item.value); |
97 | 99 | } |
98 | - if (item.name === 'refl' || item.name === 'commonness') { | |
99 | - $('#id_' + item.name).attr('checked', true); | |
100 | + if (item.name === 'refl' || item.name === 'commonness' || item.name === 'homonym_numbers' || item.name === 'form_qualifiers') { | |
101 | + $('#id_' + item.name).prop('checked', true); | |
102 | +// $('#id_' + item.name).attr('checked', true); | |
100 | 103 | } |
101 | 104 | if (item.name.indexOf('magic') === 0) { |
102 | 105 | parts = item.name.split('-'); |
... | ... |