Coder Social home page Coder Social logo

jorgebastida / django-dajax Goto Github PK

View Code? Open in Web Editor NEW
347.0 347.0 99.0 522 KB

Easy to use library to create asynchronous presentation logic with django and dajaxice

Home Page: http://dajaxproject.com/

License: BSD 3-Clause "New" or "Revised" License

Python 49.72% JavaScript 27.17% Shell 23.11%

django-dajax's People

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

django-dajax's Issues

Setting Dajax with JQuery

I'm using jqueryui on my site. When i install Dajax, it works, but it broken all my jqueryui layout.

How can i make for this works ?

I didn't find any documentation about to use Dajax with JQuery.

Can you help me ?

Encoding problem

Not sure if this is a dajax or JavaScript problem.

I am sending serialized form data data to my ajax function like this:

    form_data = $('#email-form').serialize(false);
    Dajaxice.escola.build_emails('Dajax.process',{'form_data':form_data});

and receiving the data like this:

def build_emails(request, form_data=None):
dajax = Dajax()

but in this case form_data is None and I get the following error:

ERROR:root:DAJAXICE argv exception Unterminated string starting at: line 1 column 13 (char 13)

the correct value of form_data should be something like "to_func=on&additional=&subject=&message=" I found that adding this line to my JavaScript fixed the problem:

    form_data = encodeURIComponent(form_data);

Interestingly, I didn't have to add a corresponding urldecode function to my ajax function as the passed form_data is already decoded automatically somehow

@csrf_exempt not being honoured

I have set @csrf_exempt on my view and I am still getting a csrf error when POSTing to it.

code:

@csrf_exempt
@require_person_viewed_is_verified
@dajaxice_register
def profile(request, id):
profile = Profile.objects.select_subclasses().get(id = id)
return model_to_dajax(profile, False, 'profile', 'feeds/single_proper.html').json()

request:

POST /dajaxice/feeds.profile/ HTTP/1.1
Host:
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Referer:
Content-Length: 26
Content-Type: text/plain; charset=UTF-8
Pragma: no-cache
Cache-Control: no-cache

argv=%7B%22id%22%3A5041%7D

Response:

HTTP/1.1 403 FORBIDDEN

Server nginx/0.7.67
Date Mon, 12 Mar 2012 13:26:16 GMT
Content-Type text/html
Transfer-Encoding chunked
Connection keep-alive
Keep-Alive timeout=20
Vary Cookie
ETag "ecdfed475610726df6c4cae28a35b4e4"
X-Varnish 1818915281
Age 0
Via 1.1 varnish
Content-Encoding gzip

Forbidden (403)

CSRF verification failed. Request aborted.

Help

<p>Reason given for failure:</p>
<pre>
No CSRF or session cookie.
</pre>

Jquery Addcc/remcc Chromium bug

Just a quick bug report: Chromium was interpeting these lines from
jquery.dajax.core.js incorrectly:

$(elem.id).addClass(this);
$(elem.id).removeClass(this);

It was not resolving "this" as a string, and instead passed "this"
into the function as a reference. I added a manual ".toString()" that
resolved the problem:

$(elem.id).addClass(this.toString());
$(elem.id).removeClass(this.toString());

Thanks Chase [1]

[1] http://groups.google.com/group/dajaxproject/browse_thread/thread/f32fc197d534dd39

get_media_prefix exception in example

Hi. I am new to django and very new to dajax, I want to ask you for some help.

I installed to run the examples of django-dajax (download the archive dajax-examples.tar.gz), and tried to run it using command python manager.py runserver

In every example I get the same error:

Caught an exception while rendering: 'module' object has no attribute 'get_media_prefix'

Can anybody help me?
I think I've installed something wrongly or something is missing.
Thank you very much

Dajax - Support events Jquery

I wanted to put a loading.gif while the ajax with Jquery is being processed, but he does not call the events of jquery. I as follows:

$("select#id_estado.select_black_style").change(function() {
$(document).ajaxStart(function(){
$("#teste").show();
});
$(document).ajaxStop(function(){
$("#teste").hide();
});
Dajaxice.apps.localizacao.updatecombo_estadocidade(Dajax.process,{"option":this.value});
return false;
});

This does not work.

Dajax global not set properly (jquery.dajax.core.js breaks with django-pipeline)

Django-pipeline (which is a css/js compressor) collects together all js files into a single js file, and then wraps it into an anonymous function like this:

(function(){ ... })();

This results in onclick scripts on all pages breaking because they cannot find Dajax. (Dajax is currently defined in jquery.dajax.core.js as a "var Dajax", so obviously it is not visible outside the anonymous function. Link.

Suggested fix: At the end of the file, expose the Dajax variable:

window.Dajax = Dajax

(as is done by jQuery).

Temporary workaround for others facing the same problem:

Set PIPELINE_DISABLE_WRAPPER = True

to disable wrapping all the code in an anonymous function. This works but is not an ideal solution.

'Dajax' object has no attribute 'json'

HELLO,

I met following issue when i try to use dajax:

Traceback (most recent call last):

File ... in process
response = '%s(%s)' % ( callback, thefunction(self.request, **argv) )

File ,,, line 37, in join
return dajax.json()

AttributeError: 'Dajax' object has no attribute 'json'

Coud you give me any hint on it?

Thanks

jquery.html() like function

Hi all,
would it make sense, is it possible to add a html() like function.
This would enable us to replace/add certain parts of the documents out of Django Templates.
Thanks
Juergen

Does dajax support django 1.4

ImproperlyConfigured at /maps/
Error importing template source loader django.template.loaders.filesystem.load_template_source: "'module' object has no attribute 'load_template_source'

I guess this has something to do with the following...

Function-based template loaders
Django 1.2 changes the template loading mechanism to use a class-based approach. Old style function-based template loaders will still work, but should be updated to use the new class-based template loaders.

Is this something that can easily be updated ?

unicode(data) error

Where: /dajax/core/dajax.py line 85
What: This should be changed to unicode(data, 'utf8')
Why: Causes encoding problems (UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position _: ordinal not in range(128) ) when given certain characters. The function is trying to decode to ascii before encoding to unicode, because that is the default. Thus, my change would have it use utf8 instead of ascii as the decoder before the unicode encodes.

:D

Pagination does not work on IE8

Hi,
I have a little Wiki running on Django 1.3.1 with Dajaxice 0.2 and Dajax 0.8.4.
Everything is running fine on Firefox, Chrome and Opera. By accident I discovered this little problem with IE8:

I have implemented the Pagination example from http://dajaxproject.com/pagination/. In order to avoid CSRF token issues I got rid of the tokens in views that have Paginations.

IE8 gives the following error message:
Unbekannter Laufzeitfehler (approx. "Unknown runtime error")
prototype.dajax.core.js
line: 23
code: 0
char: 50
URI: http://www-elektronenmikroskopie.uni-regensburg.de/media/js/dajax/prototype.dajax.core.js

I'm not sure whether this is an issue solely caused by Dajax because the Pagination example on http://dajaxproject.com/pagination/ is working fine.

I would appreciate any ideas...

Better debugging information

Two issues:

  1. When an error occurs in an ajax function, only the Exception is printed and there is no stack trace or line number. This makes it very difficult to figure out where the error occurred.
  2. The error message is outputted to sys.stdout which is not allowed when running in mod_wsgi and generates the error below. Error messages should be printed to sys.stderr to appear in the server error log.

Finally, instead of logging errors in the server log by printing to sys.stderr is there anyway to log errors with the normal Django error handler that generates an email? The default Django error emails contain lots of useful information and we are notified immediately by email instead of having to search through a server log.

File "/home/escolaterrafirme/apps_wsgi/django/core/handlers/base.py", line 86, in get_response
response = callback(request, _callback_args, *_callback_kwargs)

File "/home/escolaterrafirme/apps_wsgi/.site-packages/django_dajaxice-0.1.2-py2.4.egg/dajaxice/views.py", line 46, in dajax_request

File "/home/escolaterrafirme/apps_wsgi/.site-packages/django_dajaxice-0.1.2-py2.4.egg/dajaxice/core/DajaxiceRequest.py", line 220, in process

File "/home/escolaterrafirme/apps_wsgi/.site-packages/django_dajaxice-0.1.2-py2.4.egg/dajaxice/core/DajaxiceRequest.py", line 181, in _print_exception

IOError: sys.stdout access restricted by mod_wsgi

Call function

hello
is it possible to call the function like this into the future version ?

Dajaxice{
application: $(this).attr('data-application'),
view : $(this).attr('data-view'),
('Dajax.process', {...})
}

Thanks!

PEP8 compliance

Would be good to have PEP8 [1] compliance regarding naming style.

Code like:
dajax.removeCSSClass(...)

Breaks the common naming style of both Python [1] and Django [2]. According to PEP8, the recommendation would be:

dajax.remove_css_class(...)

I know it's down to personal preference, but surely makes Dajax alien in the middle of a PEP8 compliant, Django project. If it ever made into Django contrib, this would have to be fixed too, so I think it's a great idea to get this right from the beginning.

[1] http://www.python.org/dev/peps/pep-0008/

[2] http://docs.djangoproject.com/en/dev/internals/contributing/#coding-style

unicode throws exception

Setup:

  • Django 1.4.1
  • PostgreSQL with UTF-8

When querying a table with all countries for selection this error is thrown:


return unicode(data).replace('\n','').replace('\r','')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 2115: ordinal not in range(128)
response: DAJAXICE_EXCEPTION


The problem is the unicode command in django.py (http://docs.python.org/howto/unicode.html)


def _clean(self, data):
    if hasattr(data,'__iter__'):
        return map(self._clean,data)
    else:
        try:
            return unicode(data).replace('\n','').replace('\r','')
        except Exception: # Used to avoid the exception 
            return data; # Used to avoid the exception 

This is a quick and dirty fix, I have no idea if it is a good idea to do this.

jquery not working properly...takes exactly 2 arguments (1 given)

Hey,

So when I use mootools, dojo or prototype I get no errors while using dajax( I currently use 0.5.2v dajaxice,0.9.2v dajax, 1.4.1 django ).
I have followed the documentation for Dajaxice and Dajax to set the project. And like I mentioned before it works with the other JS frameworks just not jquery. I have also tested it with different versions of jquery and I get the same error.
I get the following error:

ERROR:django.request:Internal Server Error: /dajaxice/projects.employeeSearch/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, _callback_args, *_callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py", line 48, in view
return self.dispatch(request, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/dajaxice/views.py", line 52, in dispatch
response = function.call(request, *_data)
File "/usr/local/lib/python2.7/dist-packages/dajaxice/core/Dajaxice.py", line 18, in call
return self.function(_args, **kwargs)
TypeError: employeeSearch() takes exactly 2 arguments (1 given)

This is what I am doing in my template:

       {% load dajaxice_templatetags %}

        .
        .
        <script src="http://www.google.com/jsapi"></script>
        <script>    
         // Load Prototype
         //google.load("prototype", "1.6.0.3");
         google.load("jquery", "1.6.2");
        //google.load("mootools", "1.2.1");
        //google.load("dojo", "1.3.1");    

        function my_callback(data){
              alert(data+' received from server');
        }    
        </script>

        {% dajaxice_js_import %}

         <script type="text/javascript" charset="utf-8">
          var Dajax = {
               process: function(data)
                   {
                      $.each(data, function(i,elem){
             .
             .
         </script>

         {% block content  %}
          <form id="target" action="/resultsLC/" method="get">

         <input type="text" name="employeeid" id="employeeid" value="" placeholder=Employee   
     required onblur="Dajaxice.projects.employeeSearch(Dajax.process,{'employeeid':$('employeeid').value});">
        .
            .

ajax.py

from dajax.core import Dajax
from dajaxice.decorators import dajaxice_register
from projects import SearchForm
@dajaxice_register
def employeeSearch (request, employeeid):
dajax = Dajax()
result = SearchForm.search(emp)
dajax.assign('#employeeid', 'value', str(result))
return dajax.json()

In my chrome browser console this is the error message I get.
Dajaxice: Something went wrong. dajaxice.core.js:114

EXCEPTION: 'DAJAXICE_EXCEPTION',
default_settings: {'default_exception_callback': function(){ console.log('Dajaxice: Something went wrong.')}}

If you could illuminate what I am doing wrong I would really appreciate it.

Thanks

collectstatic breaks if django_dajax installed as a zipped egg

In my setup, I found that if django_dajax was installed as a zipped egg (e.g. easy_install -z django_dajax), then collectstatic failed to find dajax/jquery.dajax.core.js and other dajax static files. The problem went away when I forced easy_install to do an unzipped install (easy_install -Z django_dajax).

I have not really determined whether this is a problem with DajaxiceFinder, or Django staticfiles in general, or whether it was with django-pipeline (which I am also using) - so I cannot give a suggested fix for sure.

However, putting up the issue here, along with the suggested workaround (easy_install -Z) for the benefit of anyone else who runs into this problem.

assign does not work with events

dajax.assign("#myID", 'onchange', "myJSFunction();") is not working right now because onchange is not an attribute.
It should be useful either to add a new function to handle events or to change the actual "as" command to handle events correctly.

Thank you.

Problems with add_css_class and remove_css_class

Today I tried dajax and found it very usefull. I use jquery 1.4 and therefore jquery.dajax.core.js. The add_css_class and remove_css_class function did not work, all other functions did work.
After a bit of testing I found that changing the function from:
jQuery.each(elem.val,function(){
$(elem.id).addClass(this);
});
to:
jQuery.each(elem.val,function(){
$(elem.id).addClass(""+this+"");
});
did solve the problem. The same change did work for the remove_css_class function.

Registred methods created twice in javascript after page reload

Hello

We load a form with a ajax post command. When the form is loaded and the page is reloaded with f5 the ajax.py methods are registred twice in the generic java script:


var Dajaxice = {
portal: {
ajax_load_home: function(callback_function, argv, custom_settings){
Dajaxice.call('portal.ajax_load_home', callback_function, argv, custom_settings);
}
contact: {
Uncaught SyntaxError: Unexpected identifier // Added by google chrome dev view
ajax_load_contact_form: function(callback_function, argv, custom_settings){
Dajaxice.call('portal.contact.ajax_load_contact_form', callback_function, argv, custom_settings);
},
ajax_save_contact_form: function(callback_function, argv, custom_settings){
Dajaxice.call('portal.contact.ajax_save_contact_form', callback_function, argv, custom_settings);
},
send_form: function(callback_function, argv, custom_settings){
Dajaxice.call('portal.contact.send_form', callback_function, argv, custom_settings);
}
}
},
contact: {
ajax_load_contact_form: function(callback_function, argv, custom_settings){
Dajaxice.call('contact.ajax_load_contact_form', callback_function, argv, custom_settings);
},
ajax_save_contact_form: function(callback_function, argv, custom_settings){
Dajaxice.call('contact.ajax_save_contact_form', callback_function, argv, custom_settings);
},
send_form: function(callback_function, argv, custom_settings){
Dajaxice.call('contact.send_form', callback_function, argv, custom_settings);
}

}

ajax.py of the form:


from dajax.core import Dajax
from dajaxice.core import dajaxice_functions
from portal.contact import views
from django.views.decorators.csrf import csrf_exempt
from forms import ContactForm
from django.middleware.csrf import get_token

def ajax_load_contact_form(request):
get_token(request)
dajax = Dajax()
dajax.assign('#contentText','innerHTML',views.post_contact(request))
return dajax.json()

def ajax_save_contact_form(request):
get_token(request)
dajax = Dajax()
dajax.assign('#contentText','innerHTML',views.save_contact(request))
return dajax.json()

@csrf_exempt
def send_form(request, form):
dajax = Dajax()
form = ContactForm(form)
dajax.assign('#contentText','innerHTML',views.save_contact(form))
return dajax.json()

dajaxice_functions.register(ajax_load_contact_form)
dajaxice_functions.register(ajax_save_contact_form)
dajaxice_functions.register(send_form)


Is there something wrong in the code or a bug? I can't see it.

Thanks

Problems with simple example

I have problems with the sentence Dajax.process, does not work... It does nothing. The examples of dajaxice don´t have any problem...

Assign Error in jquery.dajax.core.js

Hi,

I have an error assigning a value using dajax with jquery:

example command:
dajax = Dajax()
dajax.assign('#example','value', random.randint(1, 10))
return dajax.json()

I traced it down to jquery.dajax.core.js. The clear_quotes funtion doesn't exist:

            case 'as':
                elem.val = clear_quotes(elem.val);
                jQuery.each($(elem.id),function(){ this[elem.prop] = elem.val; });

Error in Django Forms example?

Hello, and thanks for your hard work on these libraries

Not a core issue, but in the full forms example at http://www.dajaxproject.com/fullform/
I believe there's an error in the send_form() function provided:

function send_form(){
      data = $('my_form').serialize(true);
      Dajaxice.examples.send_form(Dajax.process,{'form':data});
}
  • 'my_form' should be '#my_form' ? Working through the example was less than fruitfull till I added the #.

Cheers

Unknown action in jquery.dajax.core.js

When an error occurs it is generally unrecoverable, however an error message is repeated over and over on the client. I sugest adding the return statement below:

            default:
                alert('Unknown action!');
                return false; // error reported, exit each loop

No support for non-blank SERVER_ROOT_URL

Submitted this in error to the dajaxice repo several months ago-- I'm not sure if it has been fixed since then.

I have a non-blank SERVER_ROOT_URL for a particular project, which means URLs for all the views in my project are of the form:
www.mysite.com/project_name/some_view

Instead of:
www.mysite.com/some_view

My configuration is only this way in the production server, not the dev server. Consequently, dajax works great on my dev server but not the production server. It seems the reason for this is because dajaxice uses only DAJAX_MEDIA_PREFIX to generate the paths to the ajax views and doesn't take SERVER_ROOT_URL into account. The result on my production server is that the ajax view urls look like this:
www.mysite.com/dajaxice/myapp.some_view

When they should really look like this:
www.mysite.com/project_name/dajaxice/myapp.some_view

Can you offer some insight here? I've spent hours trying to figure out if I just had it configured incorrectly... I tried changing the DAJAX_MEDIA_PREFIX to something else but it didn't seem to fix the problem since you have multiple dependencies on that prefix in your code...

Django full form example; jQuery 1.4 support?

The example on http://dajaxproject.com/fullform/ is broken.

One problem is that the example code that's displayed under "html" doesn't include the <script> needed to serialize the form data and ship it off to the server.

Another is that Dajax/Dajaxice isn't working for me, for jQuery 1.4.2. I get a "process_form() takes exactly 2 arguments (1 given)" traceback on the server. The call I'm using is

<script type="text/javascript" charset="utf-8"> function send_form(){ data = $('#addsection_form').serialize(); Dajaxice.hosted.process_form('Dajax.process', {'form': data}); } </script>

Can you give me a hint as to where I should look to find the problem? Or is the problem that jQuery 1.4.2 isn't supported by Dajax?

Thanks!

Support for UTF8

Could not be used with Spanish or other language with accents.

Error Validating Form with Many-to-Many Field

I am having an issue where when I try to validate a form from a model with a Many-to-Many field. The Form will not validate unless I select more than one item from the select-box.

Model validates fine when submitting form with standard POST method

Using jQuery serializeObject script as suggested in the tutorial

Error in the javascript dajax.

The firebug is pointing in the following javascript errors:
jquery.dajax.core.js - $ is undefined $.each(data, function(i,elem){
prototype.dajax.core.js - Class is not defined var Dajax = Class.create();
mootools.dajax.core.js - data.each is not a function data.each(function(elem){
dojo.dajax.core.js - dojo is not defined dojo.forEach(data, function(elem,i){

'dajax_templatetags' is not a valid tag library

Hi all. I have the message "'dajax_templatetags' is not a valid tag library" executing the dajax-examples refering to the first line in the template. I installed dajax and dajaxice following instructions. I would grateful for any tip.

Typo in script(code) documentation

The example in the documentation has code() instead of script():

def code_example(request):
    dajax = Dajax()
    dajax.code('my_function();')
    return dajax.json()

Dajax's _clean() breaks <textarea> tags

line 85 of Dajax.py is the problem:

return unicode(data).replace('\n','').replace('\r','')

example ajax.py:

def edit_contact(request, object):
    dajax = Dajax()
    …
    html = render_to_string('contact_form.html', {'formset': formset})
    dajax.assign('#contactform', 'innerHTML', html)
    return dajax.json()

a textarea from the string html looks like:

<textarea id='street_address'>
    line1\nline2\nline3
</textarea>

but dajax returns this textarea:

<textarea id='street_address'>
    line1line2line3
</textarea>

form example does not work with IE

Running Internet Explorer 7 on WinXP. Most of my client base will be running this version and upgrading is not possible. The form at http://dajaxproject.com/forms/ allows the user to select a country but the second dropdown showing cities does not update. Form does work with other browsers.

dajaxice_callback should be a function since dajaxice 0.2

I m running your examples on my local machine and receive the pop up error. when I select some country in Ajax Form Machine!
The error is

dajaxice_callback should be a function since dajaxice 0.2

I installed django-dajax and django-dajaxice using pip.
The only thing I changed in the examples code is in settings.py, where I added 'dajax' to INSTALLED_APPS
Please help.

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.