Esempio n. 1
0
 def perfect_result(self):
     dict_format = {}
     if hasattr(self, 'initial_data'):
         if len(self.initial_data) > 0:
             dict_format = self.initial_data[0]
     else:
         if len(self.instance) > 0:
             dict_format = model_to_dict(self.instance[0])
     ordered_dict = self.data
     for item in ordered_dict:
         for key in list(item.keys()):
             if key not in dict_format or not item[key]:
                 continue
             if isinstance(dict_format[key], datetime.datetime):
                 item[key] = timezoneStringTostring(item[key])
             if isinstance(dict_format[key],
                           (models.fields.files.ImageFieldFile,
                            models.fields.files.FieldFile)):
                 image_str = urllib.parse.unquote(item[key])
                 if image_str.startswith('http://') or image_str.startswith(
                         'https://'):
                     item['%s_url' % key] = image_str
                 else:
                     item['%s_url' % key] = os.path.join(
                         settings.WEB_URL_FIX, 'static', image_str)
                 item.pop(key)
     return ordered_dict
Esempio n. 2
0
def perfect_result(self, _data):
    _fields = self.get_fields()
    for key in _data:
        if isinstance(_fields[key], Fields.DateTimeField):
            _data[key] = timezoneStringTostring(_data[key])
        if isinstance(_fields[key], Fields.ImageField):
            _data['%s_url' % key] = os.path.join(settings.WEB_URL_FIX,
                                                 _data[key])
    return _data
Esempio n. 3
0
def perfect_result(self, _data):
    _fields = self.get_fields()
    for key in _data.keys():
        if isinstance(_fields[key], Fields.DateTimeField):
            _data[key] = timezoneStringTostring(_data[key])
        if isinstance(_fields[key], (Fields.ImageField, Fields.FileField)):
            image_str = urllib.unquote(_data[key])
            if image_str.startswith('http://') or image_str.startswith(
                    'https://'):
                _data['%s_url' % key] = image_str
            else:
                _data['%s_url' % key] = os.path.join(
                    settings.WEB_URL_FIX, 'static',
                    image_str.split('static/', 1)[1])
            _data.pop(key)
    return _data
Esempio n. 4
0
 def perfect_result(self):
     dict_format = {}
     if hasattr(self, 'initial_data'):
         if len(self.initial_data) > 0:
             dict_format = self.initial_data[0]
     else:
         if len(self.instance) > 0:
             dict_format = model_to_dict(self.instance[0])
     ordered_dict = self.data
     for item in ordered_dict:
         for key in item.keys():
             if isinstance(dict_format[key], datetime.datetime):
                 item[key] = timezoneStringTostring(item[key])
             if isinstance(dict_format[key],
                           models.fields.files.ImageFieldFile):
                 item['%s_url' % key] = os.path.join(
                     settings.WEB_URL_FIX, item[key])
     return ordered_dict
Esempio n. 5
0
def get_perfect_detail_by_instance(instance):
    opts = instance._meta
    fields = []
    for f in opts.concrete_fields:
        fields.append(f)

    detail_dict = model_to_dict(instance)
    for f in fields:
        key = f.name
        if isinstance(f, models.DateTimeField):
            detail_dict[key] = timezoneStringTostring(detail_dict[key])
        elif isinstance(f, models.ImageField):
            image_str = urllib.unquote(str(detail_dict[key]))
            if image_str.startswith('http://') or image_str.startswith('https://'):
                detail_dict['%s_url' % key] = image_str
            else:
                detail_dict['%s_url' % key] = os.path.join(settings.WEB_URL_FIX,
                                                           'static',
                                                           image_str.split('static/', 1)[1])
            detail_dict.pop(key)
    return detail_dict