# -*- coding: utf-8 -*-
"""
    apps.stores.views
    ~~~~~~~~~~~~~~

    stores views
    
    :copyright: (c) 2012 by arruda.
"""

from django.shortcuts import redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from annoying.decorators import render_to

from utils.decorators import ajax_login_required, JsonResponse

from stores.forms import NewStoreForm
    
@login_required
@render_to("stores/new.html")
def new(request):
    "create a new store for the logged user"
    
    if request.method == 'POST':
        form = NewStoreForm(request.POST)
        if form.is_valid():             
            store = form.save(commit=False)
            store.user = request.user
            store.save()
            form.save_m2m()
            return redirect('filter_books')
    else:
        form = NewStoreForm()
    
    return locals()


@ajax_login_required
def new_ajax(request):
    "create a new store for the logged user, using ajax"
    
    if request.method == 'POST':
        post_dict = request.POST.copy()        
        post_dict['user'] = request.user.id
        form = NewStoreForm(post_dict)
        if form.is_valid():             
            object = form.save()
            return JsonResponse({'model':"store",'id':object.id, 'name':object.name})
        else:
            return JsonResponse({'errors': form.errors})
    
    return JsonResponse({})
be2bbb181aaea7cc77eb950582386304dafc7820
<mask token>

<mask token>


@login_required
@render_to('stores/new.html')
def new(request):
    """create a new store for the logged user"""
    if request.method == 'POST':
        form = NewStoreForm(request.POST)
        if form.is_valid():
            store = form.save(commit=False)
            store.user = request.user
            store.save()
            form.save_m2m()
            return redirect('filter_books')
    else:
        form = NewStoreForm()
    return locals()


<mask token>

<mask token>


@login_required
@render_to('stores/new.html')
def new(request):
    """create a new store for the logged user"""
    if request.method == 'POST':
        form = NewStoreForm(request.POST)
        if form.is_valid():
            store = form.save(commit=False)
            store.user = request.user
            store.save()
            form.save_m2m()
            return redirect('filter_books')
    else:
        form = NewStoreForm()
    return locals()


@ajax_login_required
def new_ajax(request):
    """create a new store for the logged user, using ajax"""
    if request.method == 'POST':
        post_dict = request.POST.copy()
        post_dict['user'] = request.user.id
        form = NewStoreForm(post_dict)
        if form.is_valid():
            object = form.save()
            return JsonResponse({'model': 'store', 'id': object.id, 'name':
                object.name})
        else:
            return JsonResponse({'errors': form.errors})
    return JsonResponse({})

<mask token>
from django.shortcuts import redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from annoying.decorators import render_to
from utils.decorators import ajax_login_required, JsonResponse
from stores.forms import NewStoreForm


@login_required
@render_to('stores/new.html')
def new(request):
    """create a new store for the logged user"""
    if request.method == 'POST':
        form = NewStoreForm(request.POST)
        if form.is_valid():
            store = form.save(commit=False)
            store.user = request.user
            store.save()
            form.save_m2m()
            return redirect('filter_books')
    else:
        form = NewStoreForm()
    return locals()


@ajax_login_required
def new_ajax(request):
    """create a new store for the logged user, using ajax"""
    if request.method == 'POST':
        post_dict = request.POST.copy()
        post_dict['user'] = request.user.id
        form = NewStoreForm(post_dict)
        if form.is_valid():
            object = form.save()
            return JsonResponse({'model': 'store', 'id': object.id, 'name':
                object.name})
        else:
            return JsonResponse({'errors': form.errors})
    return JsonResponse({})

# -*- coding: utf-8 -*-
"""
    apps.stores.views
    ~~~~~~~~~~~~~~

    stores views
    
    :copyright: (c) 2012 by arruda.
"""

from django.shortcuts import redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from annoying.decorators import render_to

from utils.decorators import ajax_login_required, JsonResponse

from stores.forms import NewStoreForm
    
@login_required
@render_to("stores/new.html")
def new(request):
    "create a new store for the logged user"
    
    if request.method == 'POST':
        form = NewStoreForm(request.POST)
        if form.is_valid():             
            store = form.save(commit=False)
            store.user = request.user
            store.save()
            form.save_m2m()
            return redirect('filter_books')
    else:
        form = NewStoreForm()
    
    return locals()


@ajax_login_required
def new_ajax(request):
    "create a new store for the logged user, using ajax"
    
    if request.method == 'POST':
        post_dict = request.POST.copy()        
        post_dict['user'] = request.user.id
        form = NewStoreForm(post_dict)
        if form.is_valid():             
            object = form.save()
            return JsonResponse({'model':"store",'id':object.id, 'name':object.name})
        else:
            return JsonResponse({'errors': form.errors})
    
    return JsonResponse({})