Example #1
0
File: ajax.py Project: albanm/djity
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _ 
from django.contrib import messages
from django.conf import settings

from dajax.core import Dajax
from djity.utils.decorators import djity_view
from djity.utils.security import sanitize
from dajaxice.core import dajaxice_functions
from .models import Project, Member

register = lambda name:dajaxice_functions.register_function('djity.project.ajax',name)
@djity_view(perm='edit')
def save_tab_order(request,js_target,array,context=None):
    project = context['project']
    for module in  project.modules.all():
        module.tab_position = array.index(module.name)
        module.save()
register('save_tab_order')

@djity_view(perm='manage')
def edit_tab(request,js_target,label,status,context=None):
    module = context['module']
    module.label = label
    module.status = int(status)
    module.save()
register('edit_tab')

@djity_view(perm='edit')
def save_project_title(request,js_target,html,context=None):
Example #2
0
File: ajax.py Project: youen/cowst
"""
Ajax views for cowst.
"""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import activate, get_language
from djity.utils.decorators import djity_view
from djity.utils.security import sanitize
from djity.transmeta import get_value,set_value

from django.conf import settings

from dajaxice.core import dajaxice_functions
register = lambda name:dajaxice_functions.register_function('djity_cowst.ajax',name)

# permission needed to access a view can be 'view', 'edit', 'manage'
@djity_view(perm='manage')
def load_data(request,js_target,context=None):
    js_target.message(_('Data loaded!'))
    js_target.reload()

#register your view in dajaxice
register('load_data')

Example #3
0
File: ajax.py Project: albanm/djity
import json
from django.conf import settings
from django.template.loader import render_to_string
from dajax.core import Dajax
from djity.utils.decorators import djity_view
from django.utils.translation import ugettext_lazy as _ 
from django.contrib import messages


from dajaxice.core import dajaxice_functions
register = lambda name:dajaxice_functions.register_function('djity.style.ajax',name)

@djity_view(perm='manage')
def save_project_style(request,style_values,js_target,context=None):
    if style_values.__class__.__name__ in ['unicode','str']:
        # style can be given as string in json
        try:
            style_values = json.loads(style_values)
        except:
            style_values = {}
        
    if style_values.__class__.__name__ == 'list':
        # style can be given as a list of tuples
        style_values = dict(style_values)

    context['project'].css.set_all_values(style_values)
    message = _("The style of the project has been saved.")
    js_target.message(message,post=True)
    js_target.reload()

register('save_project_style')
Example #4
0
File: ajax.py Project: albanm/djity
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _ 
from django.contrib import messages
from django.contrib.contenttypes.models import ContentType

from django.utils.translation import get_language
from dajax.core import Dajax
from djity.utils.decorators import djity_view
from djity.utils.security import sanitize
from djity.transmeta import get_value, set_value
from dajaxice.core import dajaxice_functions
register = lambda name:dajaxice_functions.register_function('djity.simplepage.ajax',name)


@djity_view(perm='edit')
def save_simple_page(request,js_target,html,lang,context=None):
    simple_page = context['module']
    html = sanitize(html)
    if simple_page.content != html :
        set_value(simple_page,'content',lang,html)
        simple_page.save()
        js_target.message(_('Change in page saved.'))
    else:
        js_target.message(_('No change in the page.'))

register('save_simple_page')

@djity_view(perm='edit')
def get_simple_page(request,js_target,lang,context=None):
    simple_page = context['module']
    js_target.set_html(get_value(simple_page,'content',lang))
Example #5
0
File: ajax.py Project: albanm/djity
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
from dajax.core import Dajax
from django.contrib.auth import logout as django_logout
from django.contrib.auth import login as django_login
from django.contrib.auth import authenticate
from django.utils.translation import ugettext_lazy as _ 
from django.template.loader import render_to_string
from django.contrib import messages

from djity.portal.forms import RegistrationForm, ProfileForm
from djity.utils.decorators import djity_view

from dajaxice.core import dajaxice_functions
dajax_register = lambda name:dajaxice_functions.register_function('djity.portal.ajax',name)

@djity_view()
def logout(request,context=None):
    django_logout(request)
    dajax = Dajax()
    msg = _('You are now disconnected.')
    messages.add_message(request, messages.INFO, unicode(msg) )
    dajax.script('location.reload()')
    return dajax.json()
dajax_register('logout')

@djity_view()
def register(request,js_target,username,email,password1,password2,context=None):
    form = RegistrationForm({
                    'username':username,
                    'email':email,
                    'password1':password1,