コード例 #1
0
ファイル: widgets.py プロジェクト: GISYYT0812/oq-platform
    def render(self, name, value, attrs=None):
        if isinstance(value, list):
            chbx = value[0]
            taxo = value[1]
        else:
            (chbx, taxo) = self.decompress(value)

        taxo_attrs = self.build_attrs(attrs, name=name + '_1', type='text')
        taxo_attrs['id'] = 'id_' + name + '_1'

        chbx_attrs = {
            'id': 'id_' + name + '_0',
            'name': name + '_0',
            'style': 'vertical-align: text-bottom;',
            'type': 'checkbox'
        }
        if chbx:
            chbx_attrs['checked'] = ''

        # Only add the 'value' attribute if a value is non-empty.
        taxo_attrs['value'] = force_text(self._format_value(taxo))

        return format_html(
            r'''
            <span id="id_{3}_cbox"><span style="vertical-align: text-bottom;">Any:</span>
            <input {0} type="checkbox"
                 onClick="
                     if (this.checked) {{
                         var nam = '{3}' + '_1';
                         $('[name = ' + nam + ']').val('');
                     }}
                     taxonomy_update();
                          "/></span>

            <input {1}
                 onfocus="
                     if ($('#id_taxonomy_type').val() == 1) {{
                         $('#id_{3}_cbox').css('visibility', 'visible');
                         $('#id_{3}_taxtweb').css('visibility', 'visible');
                         }}
                     else {{
                         $('#id_{3}_cbox').css('visibility', 'hidden');
                         $('#id_{3}_taxtweb').css('visibility', 'hidden');
                         }}"

                 onblur="
                     $('[name={3}_0]').prop('checked', this.value == '');
                     taxonomy_update();"

                 onchange="
                     $('[name={3}_0]').prop('checked', this.value == '');
                     taxonomy_update();"
                 />&nbsp;&nbsp;
             <a id="id_{3}_taxtweb" style="font-size: 16px;
             font-weight: bold;" href="#" onclick="var pu_win = window.open('''
            ''''/taxtweb/{2}?is_popup=yes', '_blank', 'scrollbars=no,resizable=yes, width=800,'''
            '''  height=800, status=no, location=no, toolbar=no');">TaxTweb</a>''',
            flatatt(chbx_attrs), flatatt(taxo_attrs),
            force_text(self._format_value(taxo)), name)
コード例 #2
0
ファイル: widgets.py プロジェクト: gem/oq-platform
    def render(self, name, value, attrs=None):
        if isinstance(value, list):
            chbx = value[0]
            taxo = value[1]
        else:
            (chbx, taxo) = self.decompress(value)

        taxo_attrs = self.build_attrs(attrs, name=name + '_1', type='text')
        taxo_attrs['id'] = 'id_' + name + '_1'

        chbx_attrs = {'id': 'id_' + name + '_0', 'name': name + '_0',
                      'style': 'vertical-align: text-bottom;',
                      'type': 'checkbox'}
        if chbx:
            chbx_attrs['checked'] = ''

        # Only add the 'value' attribute if a value is non-empty.
        taxo_attrs['value'] = force_text(self._format_value(taxo))

        return format_html(r'''
            <span id="id_{3}_cbox"><span style="vertical-align: text-bottom;">Any:</span>
            <input {0} type="checkbox"
                 onClick="
                     if (this.checked) {{
                         var nam = '{3}' + '_1';
                         $('[name = ' + nam + ']').val('');
                     }}
                     taxonomy_update();
                          "/></span>

            <input {1}
                 onfocus="
                     if ($('#id_taxonomy_type').val() == 1) {{
                         $('#id_{3}_cbox').css('visibility', 'visible');
                         $('#id_{3}_taxtweb').css('visibility', 'visible');
                         }}
                     else {{
                         $('#id_{3}_cbox').css('visibility', 'hidden');
                         $('#id_{3}_taxtweb').css('visibility', 'hidden');
                         }}"

                 onblur="
                     $('[name={3}_0]').prop('checked', this.value == '');
                     taxonomy_update();"

                 onchange="
                     $('[name={3}_0]').prop('checked', this.value == '');
                     taxonomy_update();"
                 />&nbsp;&nbsp;
             <a id="id_{3}_taxtweb" style="font-size: 16px;
             font-weight: bold;" href="#" onclick="var pu_win = window.open('''
             ''''/taxtweb/{2}?is_popup=yes', '_blank', 'scrollbars=no,resizable=yes, width=800,'''
             '''  height=800, status=no, location=no, toolbar=no');">TaxTweb</a>''',
                           flatatt(chbx_attrs), flatatt(taxo_attrs),
                           force_text(self._format_value(taxo)), name)
コード例 #3
0
ファイル: widgets.py プロジェクト: gem/oq-platform
    def render(self, name, value, attrs=None):
        taxo_attrs = self.build_attrs(None, name=name, id="id_" + name, type='hidden')
        # Only add the 'value' attribute if a value is non-empty.
        taxo_attrs['value'] = force_text(self._format_value(value))
        view_attrs = self.build_attrs(attrs, name=name + "_view", type='text')
        view_attrs['id'] = "id_" + name + "_view"
        # import pdb ; pdb.set_trace()
        #  /*  */
        return format_html(r'''
             <input {0}/>
             <input {1} value=""><br>
<label>Visualization:</label>
<select id="OutTypeCB" onChange="
                     taxonomy_update();
">
<option value="0">Full</option>
<option value="1">Omit Unknown</option>
<option value="2" selected>Short</option>
</select>
            ''', flatatt(taxo_attrs), flatatt(view_attrs))
コード例 #4
0
ファイル: widgets.py プロジェクト: GISYYT0812/oq-platform
    def render(self, name, value, attrs=None):
        taxo_attrs = self.build_attrs(None,
                                      name=name,
                                      id="id_" + name,
                                      type='hidden')
        # Only add the 'value' attribute if a value is non-empty.
        taxo_attrs['value'] = force_text(self._format_value(value))
        view_attrs = self.build_attrs(attrs, name=name + "_view", type='text')
        view_attrs['id'] = "id_" + name + "_view"
        # import pdb ; pdb.set_trace()
        #  /*  */
        return format_html(
            r'''
             <input {0}/>
             <input {1} value=""><br>
<label>Visualization:</label>
<select id="OutTypeCB" onChange="
                     taxonomy_update();
">
<option value="0">Full</option>
<option value="1">Omit Unknown</option>
<option value="2" selected>Short</option>
</select>
            ''', flatatt(taxo_attrs), flatatt(view_attrs))
コード例 #5
0
ファイル: photo.py プロジェクト: gem/oq-platform
    def dispatch (self, request, *args, **kwargs):

        if self.preProcessPage(request, **kwargs):

            ix = kwargs.get('ix')
            self.page_context['ix'] = ix

            # get photo record
            try:
                current_object = WebLibPhoto.objects.get(pk=ix)
            except ObjectDoesNotExist:
                return self.showErrorPage(request, 'Error: photo with that id does not exist')

            cachedphotofilename = current_object._get_SIZE_url('photopage_large')

            pimg=force_text(current_object.image.path)
            if pimg.startswith(settings.MEDIA_ROOT + '/'):
                pimg = pimg[len(settings.MEDIA_ROOT + '/'):]
            photofilename = unicode(pimg)

            page_title = current_object.caption

            locationid = current_object.parentid # get the location id
            location_record = Location.objects.get(pk=locationid) # get the location record
            locationForm = LocationForm(instance=location_record, prefix="locationform")  # create the ModelForm
            locationfieldstructure = self.createFormFieldStructure( locationForm, location_record ) # generate field structure to pass to generictablerenderer (createFormFieldStructure is in weblib baseclasses pagebase.py)

            page_subtitle = location_record.name
            studyid = location_record.parentid
            study_record = Study.objects.get(pk=studyid)

            copyrightmessage = ''
            if study_record.copyrightmessage is not None and study_record.copyrightmessage != '':
                copyrightmessage = study_record.copyrightmessage # use the study copyright mesage
            if current_object.copyright_c is not None and current_object.copyright_c != '':
                copyrightmessage = current_object.copyright_c # use the photo copyright mesage

            if page_title == '' or page_title is None:
                page_title = photofilename

            eventid = study_record.parentid_id
            event_record = Event.objects.get(pk=eventid)

            yearint = event_record.yearint
            if yearint < 1923:
                yearint += 100

            page_sub_subtitle = unicode(yearint) + ' ' + event_record.name + ' ' + event_record.country

            photoqueryset = []
            photoqueryset.append(current_object) # to make it iterable
            photoForm = PhotoForm (instance=current_object, prefix="photoform")
            photofields = self.createFormFieldStructure( photoForm, current_object )
            photofields['foreignkeylinkprefix'] = '/ecd'

            # using a class dictionary from Pagebase in weblib
            self.page_context['page_title'] = page_title
            self.page_context['page_subtitle'] = page_subtitle
            self.page_context['page_sub_subtitle'] = page_sub_subtitle
            self.page_context['pageclass'] = 'photopage'
            self.page_context['editlink'] = ('/' + modelname + '/' + str(ix)).lower()
            self.page_context['current_object'] = current_object
            self.page_context['this_page'] = request.path
            self.page_context['page_backlink'] = '<a href="/ecd/location/' + str(locationid) + '">&laquo; Back to location</a>'

            self.page_context['tablesetup1'] = photofields
            self.page_context['tablesetup3'] = locationfieldstructure

            self.page_context['photofilename'] = photofilename
            self.page_context['cachedphotofilename'] = cachedphotofilename
            self.page_context['copyrightmessage'] = copyrightmessage


            self.page_context['locationid'] = locationid
            self.page_context['photoid'] = current_object.id

            ###############
            # GET
            ###############

            if request.method == 'GET':
                self.page_context['locationform'] = locationForm
                self.page_context['photoform'] = photoForm
                return render(request, self.template_name, self.page_context)

            ###############
            # POST
            ###############

            if request.method == 'POST':
                #locationForm = LocationForm(request.POST, instance=location_record , prefix='locationform') # A form bound to the POST data, prefix allows multiple forms
                #surveyForm = SurveyForm ( request.POST, instance=survey_record , prefix='surveyform' )
                photoForm = PhotoForm ( request.POST, instance=current_object , prefix='photoform' )

                #locationFormvalid = locationForm.is_valid()
                #surveyFormValid = surveyForm.is_valid()
                photoFormValid = photoForm.is_valid()

                #if locationFormvalid and surveyFormValid : # All validation rules pass
                if photoFormValid:
                    #location_record.lastupdate = datetime.now()
                    #location_record.lastupdatebyid = request.user.id
                    #locationForm.save()

                    #survey_record.lastupdate = datetime.now()
                    #survey_record.lastupdatebyid = request.user.id
                    #surveyForm.save()

                    current_object.lastupdate = datetime.now()
                    current_object.lastupdatebyid = request.user.id
                    photoForm.save()

                    return HttpResponseRedirect('/ecd/photo/' + str(ix)) # Redirect after successful POST to the non editing version
                else:

                    self.page_context['locationform'] = locationForm
                    self.page_context['photoform'] = photoForm
                    return render(request, self.template_name, self.page_context)  # Error - return just the form when there is an error - the template must not try and render anything outside the form because the contact data is not present