I don't know why but I'm calling a method from another view but now It doesn't work since I modified a try/except on my view. The except is used in all my views and it works perfecty.
This view should modify elements of a menu via a pre-filled form. Actually I can't access to this form with the error :
Python/Django global name 'logoutUser' is not defined
Here is the view
from views import B2BpartnerUser
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from .forms import MenuForm, MenuDetailForm
from .models import Menu, MenuParagraph, MenuItem, MenuItemProd
from django.db.models import Count
from django.utils.translation import ugettext_lazy as _
@login_required
def B2BpartnerMenuDetailModify(request, partnerId, menuId, menuItemId):
message = ''
e = B2BpartnerUser(request, partnerId)
try:
menuDetail = Menu.objects.get(id=menuId)
menuItem = MenuItem.objects.get(id=menuItemId)
menuItemProd = MenuItemProd.objects.get(id=menuItemId)
except (Menu.DoesNotExist, MenuItem.DoesNotExist, MenuItemProd.DoesNotExist):
return logoutUser(request)
if request.method == 'POST':
form = MenuDetailForm(request.POST, mySelf=partnerId)
if form.is_valid():
descrShort = form.cleaned_data['descrShort']
paragraph = form.cleaned_data['paragraph']
producteur = form.cleaned_data['producteur']
position = MenuItem.objects.filter(menuId = menuDetail).filter(paragraph = paragraph).count() + 1
menuItem = MenuItem(menuId = menuDetail)
menuItem.descrShort = descrShort
menuItem.paragraph = paragraph
menuItem.position = position
menuItem.save()
if producteur > 0:
menuItemProd = MenuItemProd(menuItemId = menuItem)
menuItemProd.entrepriseId = producteur
menuItemProd.save()
message = _('Details modified successfuly')
else:
data = {'descrShort': menuItem.descrShort, 'paragraph': menuItem.paragraph, 'producteur': menuItemProd.entrepriseId}
form = MenuDetailForm(mySelf=partnerId)
menuItems = MenuItem.objects.filter(menuId = menuDetail).select_related()
menus = Menu.objects.filter(entrepriseId=e)
menuParagraph = MenuParagraph.objects.filter(actif=1)
modifierDetail = True
detail = True
return render (request, 'front/B2Bmenu.html', {'MenuDetailForm': form, 'menus': menus, 'message': message, 'partnerId': partnerId, 'modifierDetail': modifierDetail, 'detail': detail, 'menuDetail': menuDetail, 'menuParagraph': menuParagraph, 'menuId': menuId, 'menuItems': menuItems})
Here is the model
class Menu(models.Model):
validDate = models.DateTimeField()
title = models.CharField(max_length=250)
entrepriseId = models.ForeignKey('Entreprise', null=True)
midi = models.BooleanField()
soir = models.BooleanField()
prix = models.DecimalField(max_digits=18, decimal_places=2, default=0)
class MenuItem(models.Model):
menuId = models.ForeignKey('Menu', null=True)
position = models.IntegerField()
paragraph = models.ForeignKey('MenuParagraph', null=True)
descrShort = models.CharField(max_length=250)
descrLong = models.TextField()
class Meta:
ordering = ['position']
class MenuItemProd(models.Model):
menuItemId = models.ForeignKey('MenuItem', null=True)
entrepriseId = models.ForeignKey('Entreprise', null=True)
class MenuParagraph(models.Model):
actif = models.BooleanField()
text = models.TextField()
position = models.IntegerField(null=True)
class Meta:
ordering = ['position']
If you need anything, I can give you more details and thank you if you have a proposition. Thank you for taking time on my topic :)
Aucun commentaire:
Enregistrer un commentaire