当前位置: 首页>>代码示例>>Python>>正文


Python utils.unicode_sorter函数代码示例

本文整理汇总了Python中smart_selects.utils.unicode_sorter函数的典型用法代码示例。如果您正苦于以下问题:Python unicode_sorter函数的具体用法?Python unicode_sorter怎么用?Python unicode_sorter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了unicode_sorter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: filterchain_all

def filterchain_all(request, app, model):
    model_class = get_model(app, model)
    keywords = {}
    for field, value in request.GET.items():
        if value == '0':
            keywords[str("%s__isnull" % field)] = True
        elif value:
            keywords[str(field)] = str(value) or None

    queryset = model_class._default_manager.filter(**keywords)
    if not len(keywords):
        queryset = queryset.none()

    results = list(queryset)
    results.sort(cmp=locale.strcoll, key=lambda x: unicode_sorter(unicode(x)))
    final = []
    for item in results:
        final.append({'value': item.pk, 'display': unicode(item)})
    results = list(model_class._default_manager.exclude(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x: unicode_sorter(unicode(x)))
    final.append({'value': "", 'display': "---------"})

    for item in results:
        final.append({'value': item.pk, 'display': unicode(item)})
    json = simplejson.dumps(final)
    return HttpResponse(json, content_type='application/json')
开发者ID:AndreLobato,项目名称:raizcidadanista,代码行数:26,代码来源:views.py

示例2: filterchain

def filterchain(request, app, model, manager=None):
    model_class = get_model(app, model)
    keywords = {}
    for field, value in request.GET.items():
        if value == '0':
            keywords[str("%s__isnull" % field)] = True
        elif value:
            keywords[str(field)] = str(value) or None

    if manager is not None and hasattr(model_class, manager):
        queryset = getattr(model_class, manager)
    else:
        queryset = model_class._default_manager

    results = queryset.filter(**keywords)
    if not len(keywords):
        results = results.none()

    if not getattr(model_class._meta, 'ordering', False):
        results = list(results)
        results.sort(cmp=locale.strcoll, key=lambda x: unicode_sorter(unicode(x)))

    result = []
    for item in results:
        result.append({'value': item.pk, 'display': unicode(item)})
    json = simplejson.dumps(result)
    return HttpResponse(json, content_type='application/json')
开发者ID:AndreLobato,项目名称:raizcidadanista,代码行数:27,代码来源:views.py

示例3: filterchain_all

def filterchain_all(request, app, model, field, value):
    Model = get_model(app, model)
    keywords = {str(field): str(value)}
    results = list(Model.objects.filter(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x:unicode_sorter(unicode(x)))
    final = []
    for item in results:
        final.append({'value':item.pk, 'display':unicode(item)})
    results = list(Model.objects.exclude(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x:unicode_sorter(unicode(x)))
    final.append({'value':"", 'display':"---------"})
    
    for item in results:
        final.append({'value':item.pk, 'display':unicode(item)})
    json = simplejson.dumps(final)
    return HttpResponse(json, mimetype='application/json')
开发者ID:Anber,项目名称:django-smart-selects,代码行数:16,代码来源:views.py

示例4: filterchain

def filterchain(request, app, model, field, manager=None):
    model_class = get_model(app, model)
    queryset = model_class._default_manager
    results = list(queryset.all().values_list('option_name'))
    results.sort(cmp=locale.strcoll, key=lambda x: unicode_sorter(unicode(x)))
    json = simplejson.dumps(results)
    return HttpResponse(json, mimetype='application/json')
开发者ID:pygaur,项目名称:taxiforpool,代码行数:7,代码来源:views.py

示例5: filterchain_all

def filterchain_all(request, app, model, field, value):
    model_class = get_model(app, model)
    if value == "0":
        keywords = {str("%s__isnull" % field): True}
    else:
        keywords = {str(field): str(value)}
    results = list(model_class._default_manager.filter(**keywords))
    results.sort(cmp=strcoll, key=lambda x: unicode_sorter(unicode(x)))
    final = []
    for item in results:
        final.append({"value": item.pk, "display": unicode(item)})
    results = list(model_class._default_manager.exclude(**keywords))
    results.sort(cmp=strcoll, key=lambda x: unicode_sorter(unicode(x)))
    final.append({"value": "", "display": "---------"})
    for item in results:
        final.append({"value": item.pk, "display": unicode(item)})
    return HttpResponse(dumps(final), mimetype="application/json")
开发者ID:emergence,项目名称:django-smart-selects,代码行数:17,代码来源:views.py

示例6: filterchain_all

def filterchain_all(request, app, model, field, value):
    model_class = get_model(app, model)
    if value == '0':
        keywords = {str("%s__isnull" % field): True}
    else:
        keywords = {str(field): str(value)}
    results = list(model_class._default_manager.filter(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x: unicode_sorter(unicode(x)))
    final = []
    for item in results:
        final.append({'value': item.pk, 'display': unicode(item)})
    results = list(model_class._default_manager.exclude(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x: unicode_sorter(unicode(x)))
    final.append({'value': "", 'display': "---------"})

    for item in results:
        final.append({'value': item.pk, 'display': unicode(item)})
    json = simplejson.dumps(final)
    return HttpResponse(json, mimetype='application/json')
开发者ID:Japje,项目名称:django-smart-selects,代码行数:19,代码来源:views.py

示例7: filterchain

def filterchain(request, app, model, field, value):
    Model = get_model(app, model)
    if value == '0':
        keywords = {str("%s__isnull" % field):True}
    else:
        keywords = {str(field): str(value)}
    results = list(Model.objects.filter(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x:unicode_sorter(unicode(x)))
    result = []
    for item in results:
        result.append({'value':item.pk, 'display':unicode(item)})
    json = simplejson.dumps(result)
    return HttpResponse(json, mimetype='application/json')
开发者ID:AndresDileva,项目名称:ProyectoFinal,代码行数:13,代码来源:views.py

示例8: filterchain

def filterchain(request, app, model, field, value, manager=None):
    Model = get_model(app, model)
    keywords = {str(field): str(value)}
    if manager is not None and hasattr(Model, manager):
        queryset = getattr(Model, manager).all()
    else:
        queryset = Model.objects
    results = list(queryset.filter(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x:unicode_sorter(unicode(x)))
    result = []
    for item in results:
        result.append({'value':item.pk, 'display':unicode(item)})
    json = simplejson.dumps(result)
    return HttpResponse(json, mimetype='application/json')
开发者ID:bitzeppelin,项目名称:django-smart-selects,代码行数:14,代码来源:views.py

示例9: filterchain

def filterchain(request, app, model, field, value, manager=None):
    model_class = get_model(app, model)
    if value == "0":
        keywords = {str("%s__isnull" % field): True}
    else:
        keywords = {str(field): str(value)}
    if manager is not None and hasattr(model_class, manager):
        queryset = getattr(model_class, manager)
    else:
        queryset = model_class._default_manager
    results = list(queryset.filter(**keywords))
    results.sort(cmp=strcoll, key=lambda x: unicode_sorter(unicode(x)))
    result = []
    for item in results:
        result.append({"value": item.pk, "display": unicode(item)})
    return HttpResponse(dumps(result), mimetype="application/json")
开发者ID:emergence,项目名称:django-smart-selects,代码行数:16,代码来源:views.py

示例10: filterchain

def filterchain(request, app, model, field, value, manager=None):
    model_class = get_model(app, model)
    if value == '0':
        keywords = {str("%s__isnull" % field): True}
    else:
        keywords = {str(field): str(value)}
    if manager is not None and hasattr(model_class, manager):
        queryset = getattr(model_class, manager)
    else:
        queryset = model_class._default_manager
    results = list(queryset.filter(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x: unicode_sorter(unicode(x)))
    result = []
    for item in results:
        result.append({'value': item.pk, 'display': unicode(item)})
    json_response = json.dumps(result)
    return HttpResponse(json_response, content_type='application/json')
开发者ID:kabucey,项目名称:django-smart-selects,代码行数:17,代码来源:views.py

示例11: filterchain

def filterchain(request, app, model, field, value, manager=None):
    model_class = get_model(app, model)
    try:
        political_divisions = model_class.country.field.related.parent_model.objects.get(id=value).political_divisions
    except:
        political_divisions = "State"
    if value == '0':
        keywords = {str("%s__isnull" % field): True}
    else:
        keywords = {str(field): str(value)}
    if manager is not None and hasattr(model_class, manager):
        queryset = getattr(model_class, manager)
    else:
        queryset = model_class._default_manager
    results = list(queryset.filter(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x: unicode_sorter(unicode(x)))
    result = {'out': [],}    
    for item in results:
        result['out'].append({'value': item.pk, 'display': unicode(item)})
    result['political_divisions'] = political_divisions 
    json = simplejson.dumps(result)
    return HttpResponse(json, mimetype='application/json')
开发者ID:drawingboardmedia,项目名称:django-smart-selects,代码行数:22,代码来源:views.py

示例12: filterchain_m2m

def filterchain_m2m(request, app, model, mapp, middle, field, value, manager=None):
    #middle = 'Standings'
    Model = get_model(app, model)
    Middle = get_model(mapp, middle)
    if manager is not None:
        raise HttpResponseServerError
    if value == '0':
        keywords = {str("%s__isnull" % field): True}
    else:
        keywords = {str(field): str(value)}
    if manager is not None and hasattr(Model, manager):
        queryset = getattr(Model, manager).all()
    else:
        queryset = Middle.objects
    results = list(queryset.filter(**keywords))
    results.sort(cmp=locale.strcoll, key=lambda x: unicode_sorter(unicode(x)))
    result = []
    for item in results:
        itemid = item.__dict__[model.lower() + '_id']
        result.append({'value': itemid, 'display': unicode(Model.objects.get(pk=itemid))})
    json = simplejson.dumps(result)
    return HttpResponse(json, mimetype='application/json')
开发者ID:skotsjedal,项目名称:caglol,代码行数:22,代码来源:views.py

示例13: render

    def render(self, name, value, attrs=None, choices=()):
        if len(name.split('-')) > 1:  # formset
            chained_field = '-'.join(name.split('-')[:-1] + [self.chained_field])
        else:
            chained_field = self.chained_field

        if not self.view_name:
            if self.show_all:
                view_name = "chained_filter_all"
            else:
                view_name = "chained_filter"
        else:
            view_name = self.view_name
        kwargs = {
            'app': self.to_app_name,
            'model': self.to_model_name,
            'field': self.chained_model_field,
            'foreign_key_app_name': self.foreign_key_app_name,
            'foreign_key_model_name': self.foreign_key_model_name,
            'foreign_key_field_name': self.foreign_key_field_name,
            'value': '1'
            }
        if self.manager is not None:
            kwargs.update({'manager': self.manager})
        url = URL_PREFIX + ("/".join(reverse(view_name, kwargs=kwargs).split("/")[:-2]))
        if self.auto_choose:
            auto_choose = 'true'
        else:
            auto_choose = 'false'
        iterator = iter(self.choices)
        if hasattr(iterator, '__next__'):
            empty_label = iterator.__next__()[1]
        else:
            # Hacky way to getting the correct empty_label from the field instead of a hardcoded '--------'
            empty_label = iterator.next()[1]

        js = """
        <script type="text/javascript">
        (function($) {
            var chainfield = "#id_%(chainfield)s";
            var url = "%(url)s";
            var id = "#%(id)s";
            var value = %(value)s;
            var auto_choose = %(auto_choose)s;
            var empty_label = "%(empty_label)s";

            $(document).ready(function() {
                chainedfk.init(chainfield, url, id, value, empty_label, auto_choose);
            });
        })(jQuery || django.jQuery);
        </script>

        """
        js = js % {"chainfield": chained_field,
                   "url": url,
                   "id": attrs['id'],
                   'value': 'undefined' if value is None or value == '' else value,
                   'auto_choose': auto_choose,
                   'empty_label': escape(empty_label)}
        final_choices = []
        if value:
            available_choices = self._get_available_choices(self.queryset, value)
            for choice in available_choices:
                final_choices.append((choice.pk, force_text(choice)))
        if len(final_choices) > 1:
            final_choices = [("", (empty_label))] + final_choices
        if self.show_all:
            final_choices.append(("", (empty_label)))
            self.choices = list(self.choices)
            self.choices.sort(key=lambda x: unicode_sorter(x[1]))
            for ch in self.choices:
                if ch not in final_choices:
                    final_choices.append(ch)
        self.choices = ()
        final_attrs = self.build_attrs(attrs, name=name)
        if 'class' in final_attrs:
            final_attrs['class'] += ' chained'
        else:
            final_attrs['class'] = 'chained'

        output = super(ChainedSelect, self).render(name, value, final_attrs, choices=final_choices)
        output += js
        return mark_safe(output)
开发者ID:anlaplante,项目名称:mahana,代码行数:83,代码来源:widgets.py

示例14: render


#.........这里部分代码省略.........
                    if (init_value == "None") init_value = undefined;
                    var url = "%(url)s/";
                    if (!val && pk)
                        url += "0/pk/"+pk;
                    else
                        url += val;
                    $.getJSON(url+"/", function(j){
                        var options = '<option value="">%(empty_label)s<'+'/option>';
                        var prev_value = el.children("option[selected='selected']").val();
                        for (var i = 0; i < j.length; i++) {
                            options += '<option value="' + j[i].value + '">' + j[i].display + '<'+'/option>';
                        }
                        var width = el.outerWidth();
                        el.html(options);
                        if (navigator.appVersion.indexOf("MSIE") != -1)
                            el.width(width + 'px');
                        $('#%(id)s option:first').attr('selected', 'selected');
                        var auto_choose = %(auto_choose)s;
                        if(init_value){
                            $('#%(id)s option[value="'+ init_value +'"]').attr('selected', 'selected');
                        }
                        if(auto_choose && j.length == 1){
                            $('#%(id)s option[value="'+ j[0].value +'"]').attr('selected', 'selected');
                        }
                        if (init_value != prev_value)
                            el.trigger('change');
                    })
                }

                var chainfield = $("#id_%(chainfield)s");

                if(!chainfield.hasClass("chained") || !el.children().length){
                    var pk;
                    var val = chainfield.val();
                    if (!chainfield.length) {
                        var a;
                        a = el.parents("tr").first().children("td.action-checkbox").children("input.action-select");
                        if (a.length)
                            pk = a.val();
                        else {
                            a = el.parents("div.inline-group");
                            if (a.length)
                                val = document.location.pathname.match(/\d+[/]?$/)[0].replace("/","");
                        }
                    }
                    fill_field(val, "%(value)s", pk);
                }

                chainfield.change(function(){
                    var start_value = el.val();
                    var val = $(this).val();
                    fill_field(val, start_value);
                })
            })
            if (typeof(dismissAddAnotherPopup) !== 'undefined') {
                var oldDismissAddAnotherPopup = dismissAddAnotherPopup;
                dismissAddAnotherPopup = function(win, newId, newRepr) {
                    oldDismissAddAnotherPopup(win, newId, newRepr);
                    if (windowname_to_id(win.name) == "id_%(chainfield)s") {
                        $("#id_%(chainfield)s").change();
                    }
                }
            }
        })(jQuery || django.jQuery);
        //]]>
        </script>

        """
        js = js % {
            "chainfield": chain_field.split("__")[0],
            "url": url,
            "id": attrs["id"],
            "value": value,
            "auto_choose": auto_choose,
            "empty_label": empty_label,
        }
        final_choices = []
        if value:
            available_choices = self._get_available_choices(self.queryset, value)
            for choice in available_choices:
                final_choices.append((choice.pk, force_text(choice)))
        if len(final_choices) > 1:
            final_choices = [("", (empty_label))] + final_choices
        if self.show_all:
            final_choices.append(("", (empty_label)))
            self.choices = list(self.choices)
            self.choices.sort(key=lambda x: unicode_sorter(x[1]))
            for ch in self.choices:
                if not ch in final_choices:
                    final_choices.append(ch)
        self.choices = ()
        final_attrs = self.build_attrs(attrs, name=name)
        if "class" in final_attrs:
            final_attrs["class"] += " chained"
        else:
            final_attrs["class"] = "chained"

        output = super(ChainedSelect, self).render(name, value, final_attrs, choices=final_choices)
        output += js
        return mark_safe(output)
开发者ID:mkaluza,项目名称:django-smart-selects,代码行数:101,代码来源:widgets.py

示例15: render

 def render(self, name, value, attrs=None, choices=()):
     if len(name.split('-')) > 1: # formset
         chain_field = '-'.join(name.split('-')[:-1] + [self.chain_field])
     else:
         chain_field = self.chain_field 
     
     if self.show_all:
         url = "/".join(reverse("chained_filter_all", kwargs={'app':self.app_name,'model':self.model_name,'field':self.model_field,'value':"1"}).split("/")[:-2])
     else:
         url = "/".join(reverse("chained_filter", kwargs={'app':self.app_name,'model':self.model_name,'field':self.model_field,'value':"1"}).split("/")[:-2])
     if self.auto_choose:
         auto_choose = 'true'
     else:
         auto_choose = 'false'
     empty_label = iter(self.choices).next()[1] # Hacky way to getting the correct empty_label from the field instead of a hardcoded '--------'
     js = """
     <script type="text/javascript">
     //<![CDATA[
     $(document).ready(function(){
         function fill_field(val, init_value){
             if (!val || val==''){
                 options = '<option value="">%(empty_label)s<'+'/option>';
                 $("#%(id)s").html(options);
                 $('#%(id)s option:first').attr('selected', 'selected');
                 $("#%(id)s").trigger('change');
                 return;
             }
             $.getJSON("%(url)s/"+val+"/", function(j){
                 var options = '<option value="">%(empty_label)s<'+'/option>';
                 for (var i = 0; i < j.length; i++) {
                     options += '<option value="' + j[i].value + '">' + j[i].display + '<'+'/option>';
                 }
                 $("#%(id)s").html(options);
                 $('#%(id)s option:first').attr('selected', 'selected');
                 var auto_choose = %(auto_choose)s;
                 if(init_value){
                     $('#%(id)s option[value="'+ init_value +'"]').attr('selected', 'selected');
                 }
                 if(auto_choose && j.length == 1){
                     $('#%(id)s option[value="'+ j[0].value +'"]').attr('selected', 'selected');
                 }
                 $("#%(id)s").trigger('change');
             })
         }
         
         if(!$("select#id_%(chainfield)s").hasClass("chained")){
             var val = $("select#id_%(chainfield)s").val();
             fill_field(val, "%(value)s");
         }
         
         $("select#id_%(chainfield)s").change(function(){
             var start_value = $("select#%(id)s").val();
             var val = $(this).val();
             fill_field(val, start_value);
             
         })
     })
     //]]>
     </script>
     
     """ % {"chainfield":chain_field, "url":url, "id":attrs['id'], 'value':value, 'auto_choose':auto_choose, 'empty_label': empty_label}
     final_choices=[]
     
     if value:
         item = self.queryset.filter(pk=value)[0]
         try:
             pk = getattr(item, self.model_field+"_id")
             filter={self.model_field:pk}
         except AttributeError:
             try: # maybe m2m?
                 pks = getattr(item, self.model_field).all().values_list('pk', flat=True)
                 filter={self.model_field+"__in":pks}
             except AttributeError:
                 try: # maybe a set?
                     pks = getattr(item, self.model_field+"_set").all().values_list('pk', flat=True)
                     filter={self.model_field+"__in":pks}
                 except: # give up
                     filter = {}
         filtered = list(get_model( self.app_name, self.model_name).objects.filter(**filter).distinct())
         filtered.sort(cmp=locale.strcoll, key=lambda x:unicode_sorter(unicode(x)))
         for choice in filtered:
             final_choices.append((choice.pk, unicode(choice)))
     if len(final_choices)>1:
         final_choices = [("", (empty_label))] + final_choices
     if self.show_all:
         final_choices.append(("", (empty_label)))
         self.choices = list(self.choices)
         self.choices.sort(cmp=locale.strcoll, key=lambda x:unicode_sorter(x[1]))
         for ch in self.choices:
             if not ch in final_choices:
                 final_choices.append(ch)
     self.choices = ()
     final_attrs = self.build_attrs(attrs, name=name)
     if 'class' in final_attrs:
         final_attrs['class'] += ' chained'
     else:
         final_attrs['class'] = 'chained'
     output = super(ChainedSelect, self).render(name, value, final_attrs, choices=final_choices)
     output += js
     return mark_safe(output)
开发者ID:dmoisset,项目名称:django-smart-selects,代码行数:100,代码来源:widgets.py


注:本文中的smart_selects.utils.unicode_sorter函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。