Changeset 1491

Show
Ignore:
Timestamp:
19/05/2010 14:25:43 (21 months ago)
Author:
tiago
Message:

Fixed Ticket #247

Location:
trunk/gestorpsi
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/gestorpsi/demographic/forms.py

    r1404 r1491  
    2222 
    2323class ProfessionForm(forms.ModelForm): 
    24     profession = forms.ModelChoiceField(queryset=Occupation.objects.all(), widget=forms.Select(attrs={'class':'giant asm'}), label=_('Profession Ocupation')) 
     24    #profession = forms.ModelChoiceField(queryset=Occupation.objects.all(), widget=forms.Select(attrs={'class':'giant asm'}), label=_('Profession Ocupation')) 
    2525    labor_market_status = forms.ChoiceField(choices=LABOR_MARKET_STATUS, widget=forms.Select(attrs={'class':'giant asm'}), label=_('Labor Market Status')) 
    2626    workplace = forms.CharField(required=False, widget=forms.Textarea(attrs={'class':'giant asm'}), label=_('Profession Workplace')) 
     
    3030    class Meta: 
    3131        model = Profession 
    32         fields = ('profession','labor_market_status', 'workplace', 'working_hours', 'comments', 'status') 
     32        fields = ('labor_market_status', 'workplace', 'working_hours', 'comments', 'status') 
    3333 
    3434class EducationalLevelForm(forms.ModelForm): 
  • trunk/gestorpsi/demographic/views.py

    r1472 r1491  
    2424from gestorpsi.demographic.forms import EducationalLevelForm, ProfessionForm 
    2525from gestorpsi.demographic.models import EducationalLevel, Profession 
     26 
     27from gestorpsi.cbo.models import Occupation 
    2628 
    2729from gestorpsi.client.views import _access_check 
     
    8183def occupation(request, object_id, occupation_id=0): 
    8284    object = get_object_or_404(Client, pk=object_id, person__organization=request.user.get_profile().org_active) 
     85 
    8386    # check access by requested user 
    8487    if not _access_check(request, object): 
     
    8689 
    8790    occupation_object = get_object_or_None(Profession, id=occupation_id) or Profession() 
     91 
    8892    profession_form = ProfessionForm(instance=occupation_object) 
     93 
    8994    professions = [p for p in object.profession_set.all()] 
    9095    return render_to_response('demographic/demographic_occupation.html', { 
     
    9398                                    'professions': professions, 
    9499                                    'profession_form': profession_form, 
     100                                    'occupation': occupation_object, 
    95101                                    }, context_instance=RequestContext(request)) 
    96102 
     
    104110    occupation_object = get_object_or_None(Profession, id=occupation_id) or Profession() 
    105111    profession_form = ProfessionForm(request.POST, instance=occupation_object) 
     112 
     113    print profession_form.errors 
     114    print request.POST.get('ocup_class') 
     115    print Occupation.objects.get(pk=request.POST.get('ocup_class')) 
     116 
    106117    profession = profession_form.save(commit=False) 
     118    profession.profession = Occupation.objects.get(pk=request.POST.get('ocup_class')) 
    107119    profession.client = object 
    108120    profession.save() 
  • trunk/gestorpsi/media/js/gestorpsi.forms.js

    r1464 r1491  
    854854                 
    855855    }); 
    856      
     856 
     857    /******** 
     858    *  OCUPATION SEARCH  
     859    *********/ 
     860 
     861        $('a.show_ocup_search').click(function() { 
     862            $('.ocup_search').toggle(); 
     863            $('table#ocup_results tbody').html(''); 
     864        }); 
     865         
     866        $('input[name=ocup_search_key]').keyup(function() { 
     867            var typed = $(this).val(); 
     868            if(typed.length >= 2) { 
     869                $.getJSON('/util/ocupation/?query=' + typed, function(json) { 
     870                    line = ''; 
     871                    jQuery.each(json, function() { 
     872                       line += '<tr><td class="ocup_id">' + this.id + '</td><td class="ocup_label"><a style="cursor:pointer;">' + this.name + '</a></td></tr>'; 
     873                    }); 
     874                    $('table#ocup_results tbody').html(line); 
     875                    $('table#ocup_results tr td a').click(function() { 
     876                        $('input[name=ocup_class]').val($(this).parents('tr').children('td.ocup_id').text()); 
     877                        $('span.ocup_name').text($(this).parents('tr').children('td.ocup_label').children('a').text()); 
     878                        $('.ocup_search').hide(); 
     879                        $('table#ocup_results tbody tr').show(); 
     880                        $('input[name=ocup_search_key]').val(''); 
     881                    }); 
     882                    
     883                }); 
     884            } else { 
     885                $('table#ocup_results tbody').html(''); 
     886            } 
     887        });     
     888 
     889 
     890/* MAIN FUNCTION */  
    857891}); 
  • trunk/gestorpsi/templates/demographic/demographic_occupation.html

    r1365 r1491  
    5151 
    5252<fieldset> 
    53     <legend>{% trans "Occupation Detail" %}</legend> 
    54         <div class="form_as_ul"> 
    55             {{ profession_form.as_ul }} 
    56         </div>         
     53 <legend>{% trans "Occupation Detail " %}</legend> 
     54 
     55 
     56    <label>Occupation Code <a style="cursor: pointer;" class="show_ocup_search">Search Code?</a><br> 
     57        <input type="text" id="id_ocup_class" name="ocup_class" value="{{ occupation.profession.id }}"> 
     58    </label> 
     59 
     60    <br /> 
     61    <br /> 
     62 
     63    <label> 
     64     <span class="ocup_name">{{ occupation }}</span> 
     65    </label> 
     66 
     67    <br /> 
     68    <br /> 
     69    <br /> 
     70 
     71    <label class="ocup_search hidden" style="display: none;">Occupation Search<br> 
     72        <input type="text" class="big" name="ocup_search_key"> 
     73    </label> 
     74 
     75    <div class="overflow ocup_search hidden" style="display: none;"> 
     76     <table class="zebra" id="ocup_results"> 
     77      <thead>   
     78       <tr> 
     79        <th></th> 
     80        <th></th> 
     81       </tr>  
     82      </thead> 
     83      <tbody></tbody> 
     84     </table> 
     85    </div> 
     86 
     87    <div class="form_as_ul"> 
     88      {{ profession_form.as_ul }} 
     89    </div>         
     90                                
    5791</fieldset> 
     92 <br /> 
    5893 
    5994</p> 
  • trunk/gestorpsi/util/urls.py

    r1245 r1491  
    1717from django.conf.urls.defaults import * 
    1818from django.contrib.auth.decorators import login_required 
    19 from gestorpsi.util.views import cnae 
     19from gestorpsi.util.views import cnae, ocupation 
    2020 
    2121urlpatterns = patterns('', 
    2222    (r'^cnae/$', login_required(cnae)),  
     23    (r'^ocupation/$', login_required(ocupation)),  
    2324) 
  • trunk/gestorpsi/util/views.py

    r1310 r1491  
    2424from django.template import Context 
    2525from gestorpsi.util.models import Cnae 
     26from gestorpsi.cbo.models import Occupation 
    2627 
    2728def get_object_or_new(klass, *args, **kwargs): 
     
    5758    return HttpResponse(simplejson.dumps(results)) 
    5859 
     60def ocupation(request): 
     61    print "ocupation" 
     62    ''' 
     63    filter Cnae's return a dict with cnae codes and sub classes names  
     64    ''' 
     65    results = [] 
     66    for i in Occupation.objects.filter(title__icontains=request.GET.get('query')): 
     67        results.append({'id': i.id, 'name': i.title }) 
     68     
     69    return HttpResponse(simplejson.dumps(results)) 
     70 
    5971def write_pdf(template_src, context_dict, filename='output.pdf'): 
    6072    template = get_template(template_src)