Commit 34e12bdb417bd774f197f822cba9cf78741a76a4

Authored by Bartłomiej Nitoń
1 parent 2dd43901

Initial coding for making possible to add positions list as phrase type realization.

dictionary/ajax_argument_realizations.py
... ... @@ -32,8 +32,9 @@ from common.decorators import render, ajax, AjaxError
32 32 from dictionary.ajax_argument_form import argument_to_form_values, get_argument_model, \
33 33 create_argument_form, all_fields_filled, \
34 34 get_argument_from_form, validate_argument_form
35   -from dictionary.forms import ArgRealOpinionForm
36   -from dictionary.models import Argument, ArgRealization, ArgRealOpinion, AttributeParameterModel
  35 +from dictionary.forms import ArgRealOpinionForm, ArgRealTypeForm
  36 +from dictionary.models import Argument, ArgRealization, ArgRealOpinion, AttributeParameterModel, \
  37 + RealizationType
37 38 from settings import PROJECT_PATH
38 39  
39 40 DEFAULT_SAVE_PATH = os.path.join(PROJECT_PATH, 'tmp')
... ... @@ -74,6 +75,8 @@ def realization_arg_form(request, form_data, main_argument, real_id):
74 75 form_dict = {'arg_id': realization_argument.id}
75 76 arg_model = get_argument_model(form_dict)
76 77 opinion_form = create_opinion_form(real_id)
  78 + realization_type = get_realization_type(real_id, form_dict)
  79 + realization_type_form = create_realization_type_form(realization_type)
77 80 if main_argument:
78 81 form_type = 'realization_main_arg'
79 82 else:
... ... @@ -91,8 +94,19 @@ def realization_arg_form(request, form_data, main_argument, real_id):
91 94 return {'type_form': type_form,
92 95 'attr_sheets': attr_sheets,
93 96 'opinion_form': opinion_form,
  97 + 'real_type_form': realization_type_form,
94 98 'main_argument': main_argument}
95 99  
  100 +def get_realization_type(realization_id, form_dict):
  101 + if realization_id:
  102 + realization = ArgRealization.objects.get(id=realization_id)
  103 + real_type = realization.type
  104 + elif form_dict and form_dict['real_type']:
  105 + real_type = RealizationType.objects.get(id=form_dict['real_type'])
  106 + else:
  107 + real_type = RealizationType.objects.order_by('priority')[0]
  108 + return real_type
  109 +
96 110 def get_arg_from_realization(realization_id):
97 111 argument = None
98 112 if realization_id:
... ... @@ -108,6 +122,9 @@ def create_opinion_form(realization_id):
108 122 opinion_form = ArgRealOpinionForm(sel_opinion=opinion)
109 123 return opinion_form
110 124  
  125 +def create_realization_type_form(real_type):
  126 + return ArgRealTypeForm(sel_type=real_type)
  127 +
111 128 @ajax(method='post')
112 129 def remove_realization(request, realization_id, main_arg_data):
113 130 result = {}
... ...
dictionary/forms.py
... ... @@ -330,6 +330,15 @@ class ArgPropositionsForm(Form):
330 330 if sel_argument:
331 331 self.fields['freq_coordinated'].initial = sel_argument
332 332  
  333 +class ArgRealTypeForm(Form):
  334 + real_type = ModelChoiceField(queryset=RealizationType.objects.order_by('priority'),
  335 + label=u'Typ realizacji', required=True,
  336 + empty_label=None)
  337 +
  338 + def __init__(self, sel_type=None, *args, **kwargs):
  339 + super(ArgRealTypeForm, self).__init__(*args, **kwargs)
  340 + self.fields['real_type'].initial = sel_type
  341 +
333 342 class ArgRealOpinionForm(Form):
334 343 opinion = ModelChoiceField(queryset=ArgRealOpinion.objects.order_by('priority'),
335 344 label=u'Opinia', required=True)
... ...
dictionary/models.py
... ... @@ -766,8 +766,8 @@ def sort_arguments(arguments):
766 766 return sortArguments(arguments)
767 767  
768 768 class ArgRealization(Model):
769   -# # !NOWE! nie dodalem tego jeszcze na produkcyjnym
770   -# type = ForeignKey('RealizationType', related_name='realizations')
  769 +# # !NOWE!
  770 + type = ForeignKey('RealizationType', related_name='realizations')
771 771 argument = ForeignKey('Argument', blank=True, null=True)
772 772 positions = ManyToManyField('Position', blank=True, null=True,
773 773 related_name='realizations')
... ... @@ -779,6 +779,7 @@ class ArgRealization(Model):
779 779 class RealizationType(Model):
780 780 name = CharField(max_length=24)
781 781 sym_name = CharField(max_length=24)
  782 + priority = PositiveIntegerField(db_column='priorytet')
782 783  
783 784 def __unicode__(self):
784 785 return self.name
... ...
dictionary/static/js/arg_realizations.js
1 1 /*
2   -Copyright (c) 2012, Bartłomiej Nitoń
  2 +Copyright (c) 2015, Bartłomiej Nitoń
3 3 All rights reserved.
4 4  
5 5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
... ... @@ -31,6 +31,11 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31 31 realization_arguments_form_change(-1, '', true, $(event.target).closest('.argument-add-form'));
32 32 });
33 33  
  34 + $('#create-realization .argument-add-form #id_real_type').live('change', function (event) {
  35 + // zmiana typu realizacji
  36 + realization_arguments_form_change(-1, '', false, $(event.target).closest('.argument-add-form'));
  37 + });
  38 +
34 39 $('#create-realization .argument-add-form #id_arg_type').live('change', function (event) {
35 40 realization_arguments_form_change(0, '', false, $(event.target).closest('.argument-add-form'));
36 41 });
... ... @@ -58,7 +63,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
58 63 $("$[id$='-add_realization_button']").live('click', function(event){openAddArgumentDialog(event, null, 'Tworzenie rozwinięcia typu frazy:')});
59 64 $("$[id$='-select_argument_button']").live('click', function(event){openSelectArgumentDialog(event, null)});
60 65  
61   -
62 66 $("[id$='-argument-form-dialog'] .argument-add-form #id_arg_type'").live('change', function(event) {
63 67 arguments_form_change(0, null, $(event.target).closest(".argument-add-form"), null)});
64 68 $("[id$='-argument-form-dialog'] .argument-add-form #id_value_positions_0, [id$='-argument-form-dialog'] .argument-add-form #id_value_arguments_0, [id$='-argument-form-dialog'] .argument-add-form #id_value_parameter_0").live('change', function(event) {
... ...
dictionary/templates/arg_realization_form.html
1 1 <form class="argument-add-form" method="post"> {% csrf_token %}
  2 + {% if main_argument %}
  3 + {% else %}
  4 + <div class="realization-type">
  5 + {{real_type_form.as_p}}
  6 + </div>
  7 + {% endif %}
2 8 <div class="argument-type">
3 9 {{type_form.as_p}}
4 10 {% for sheet in attr_sheets %}
... ...