Coder Social home page Coder Social logo

django-splitjsonwidget-form's Introduction

django-splitjsonwidget-form's People

Contributors

abbasovalex avatar bitdeli-chef avatar egasimus avatar fchevitarese avatar sylvainblot avatar they4kman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-splitjsonwidget-form's Issues

Using for Dictionary, but when saving data gets changed.

Thank you for this awesome library.

Solved many issues, but having this problem:

original data: {1: {'end_minute': 0, 'start_hour': 10, 'end_hour': 19, 'start_minute': 0}, 2: {'end_minute': 30, 'start_hour': 8, 'end_hour': 17, 'start_minute': 30}}

After saving it using django-admin it's getting saved as below in DB.

[{u'end_minute': u'0', u'start_hour': u'10', u'end_hour': u'19', u'start_minute': u'0'}, {u'end_hour': u'17', u'start_hour': u'8', u'end_minute': u'30', u'start_minute': u'30'}]

Object has no attribute 'get' -Django 1.8

I am using Django 1.8 version, don't know whether it's a version related problem. But after adding all code in respective forms.py, views.py, and test_template.py, It returns

testForm' object has no attribute 'get'

I think i might missed to add the appname in settings.py apps.
i tried the default name but it didn't worked , it's not pointed in you repo readme too.
Here is the output,

Request Method: GET
Request URL: http://framework.com/test_template/

Django Version: 1.8.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'framework')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response

  1.             response = middleware_method(request, response)
    
    File "/usr/local/lib/python2.7/dist-packages/django/middleware/clickjacking.py" in process_response
  2.     if response.get('X-Frame-Options', None) is not None:
    

Exception Type: AttributeError at /test_template/
Exception Value: 'testForm' object has no attribute 'get'

screenshot from 2015-05-29 21 59 07

I had reached here using this ,
http://stackoverflow.com/a/16650451/4190386
and found it as the best way to implement my json form.

Could you please look into it?

Simple change for python 3

I was trying to run this library on python 3, and this line threw a syntax error. It's a simple fix to add brackets to the print statement, and looking through the code, there don't seem to be any other issues that stop python 3 support.

Python3 and Django 3 Compatibility

This package is not currently compatible with the latest versions of Python or Django.

I've opened the following Pull Request with the required compatibility changes in #31

I've also replaced the legacy string formatting style with more modern F-Strings

Hope this is useful to someone else!

Does not accept floats

Hi There,

Jsonsplit does not accept floats. Shoud just suffice to add float in the test against unicode and int in _to_build. Will do a pull request in this.

Cheers

Helge

To fill readme file

Will add common cases:

  • example to integrate with django
  • example with a list
  • example with a dictionary
  • example with a list of a dict
  • example with a dict of a list
  • example with a complex list
  • example with a complex dict

The objects are disappear

Problem:
You cannot use the list which includes similar structure objects.

example:

json = {
            ...
            [
                 {'name': 'A', 'value': 'No'},
                 {'name': 'B', 'value': 'No'},
                 {'name': 'C', 'value': 'Yes'}
            ],
            ...
 } 

after save it will look approximately as:

json = {
            ...
            [
                 {'name': 'A', 'value': 'No'},
                 {'name': 'C', 'value': 'Yes},
            ],
            ...
 } 

it happened because a values' keys of the list were rewrote.

Will discover this code and make solution:

   74             if k.find(self.separator) is not -1:
~  75                 apx, _, nk = k.rpartition(self.separator)
   76                 try:
+  77                     # parse list
   78                     int(nk)
~  79                     l = []
+  80                     obj = {}        
+  81                     if apx != root_node:
+  82                         for key, val in copy_raw_data.items():
+  83                             _, _, t = key.rpartition(self.separator)
+  84                             if key is k:
+  85                                 del copy_raw_data[key]
+  86                             elif key.startswith(apx):
+  87                                 try:
+  88                                     int(t)
+  89                                     l.append(val)
+  90                                 except ValueError:
+  91                                     obj[t] = val <---------- may be here?
+  92                                 del copy_raw_data[key]
+  93                         if obj: 
+  94                             l.append(obj)
+  95                     l.append(v)
+  96                     return _to_parse_key(apx, l)
   97                 except ValueError:

Cannot use number key

For objects which have digital key after form saved they will be transformed to a list.

Compatibility issue with django 1.11

When upgrading to django 1.11 an error arises: build_attrs() unexpected keyword 'type'.

It happened in other django related software, as you can see:
django-ckeditor/django-ckeditor#375
jazzband/django-sortedm2m#107

It is easily solved by this recoding in widgets.py:

--- /usr/local/lib/python2.7/dist-packages/splitjson/widgets.py.orig    2018-03-07 13:16:58.544426000 +0100
+++ /usr/local/lib/python2.7/dist-packages/splitjson/widgets.py 2018-03-07 13:24:15.904531209 +0100
@@ -23,8 +23,9 @@
         Widget.__init__(self, attrs)

     def _as_text_field(self, name, key, value, is_sub=False):
-        attrs = self.build_attrs(self.attrs, type='text',
-                                 name="%s%s%s" % (name, self.separator, key))
+        attrs = self.build_attrs(self.attrs)
+        attrs['type'] = 'text'
+        attrs['name'] = "%s%s%s" % (name, self.separator, key)
         attrs['value'] = utils.encoding.force_unicode(value)
         attrs['id'] = attrs.get('name', None)
         return u""" <label for="%s">%s:</label>

It would be great if you can update your code to solve the problem. Thanks!

How to use it in a ModelForm?

How can I use it for this model for example?

forms.py

class PersonForm(forms.ModelForm):
    name = forms.CharField( max_length=100)  
    extra_field = forms.CharField(widget=SplitJSONWidget(attrs=attrs, debug=True))

    class Meta:
        model = Person

and in views.py

def record_person(request):

    if request.method == "POST":
        form = PersonForm(request.POST)
        if form.is_valid():
            person_instance = form.save()
            return redirect('homepage')
    else:
        thisperson = Person.objects.get(user=request.user)
        form = PersonForm(instance=thisperson)

    return render(request, "record_person.html", {'form': form})

the extra_field store json data, which are custom additional field inputs that the user can create.

the extra_field is displayed, but I've got, even if thisperson does exist:

Source data:
None

Crashes when there are unicode contents in json

Hi,
Thank you for sharing a useful widget.
I have some unicode contents in json (backslashreplaced).
Whenever I'm about to use the widget on those contents, it crashes.
Since I've already resolved this issue in my project, I could send a pull-request sooner or later.

How to use it with admin

Can we use it with admin? seems like, it will increase the readability compared to displaying the value in textfield.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.