Add more tests + Event.max_items_pre_order should be a settings

This commit is contained in:
Raphael Michel
2015-02-21 15:33:53 +01:00
parent e13d11be78
commit 497cbe17af
8 changed files with 190 additions and 18 deletions

View File

@@ -111,10 +111,10 @@ class CartAdd(EventViewMixin, CartActionMixin, View):
if not items:
return redirect(self.get_failure_url())
existing = CartPosition.objects.current.filter(user=self.request.user, event=self.request.event).count()
if sum(i[2] for i in items) + existing > self.request.event.max_items_per_order:
if sum(i[2] for i in items) + existing > int(self.request.event.settings.max_items_per_order):
# TODO: i18n plurals
messages.error(self.request,
_("You cannot select more than %d items per order") % self.event.max_items_per_order)
_("You cannot select more than %s items per order") % self.request.event.settings.max_items_per_order)
return redirect(self.get_failure_url())
# Extend this user's cart session to 30 minutes from now to ensure all items in the

View File

@@ -40,13 +40,13 @@ class EventIndex(EventViewMixin, CartDisplayMixin, TemplateView):
if not item.has_variations:
item.cached_availability = list(item.check_quotas())
item.cached_availability[1] = min(item.cached_availability[1],
self.request.event.max_items_per_order)
int(self.request.event.settings.max_items_per_order))
item.price = item.available_variations[0]['price']
else:
for var in item.available_variations:
var.cached_availability = list(var['variation'].check_quotas())
var.cached_availability[1] = min(var.cached_availability[1],
self.request.event.max_items_per_order)
int(self.request.event.settings.max_items_per_order))
items = [item for item in items if len(item.available_variations) > 0]
@@ -65,7 +65,11 @@ class EventIndex(EventViewMixin, CartDisplayMixin, TemplateView):
class LoginForm(BaseAuthenticationForm):
username = forms.CharField(
label=_('Username'),
help_text=_('If you registered for multiple events, your username is your email address.')
help_text=(
_('If you registered for multiple events, your username is your email address.')
if settings.PRETIX_GLOBAL_REGISTRATION
else None
)
)
password = forms.CharField(
label=_('Password'),
@@ -245,7 +249,7 @@ class EventLogin(EventViewMixin, TemplateView):
user = authenticate(identifier=user.identifier, password=form.cleaned_data['password'])
login(request, user)
return self.redirect_to_next()
elif request.POST.get('form') == 'global_registration':
elif request.POST.get('form') == 'global_registration' and settings.PRETIX_GLOBAL_REGISTRATION:
form = self.global_registration_form
if form.is_valid():
user = User.objects.create_global_user(