def size_change(request, subscription_id): ''' change the size of an subscription ''' subscription = get_object_or_404(Subscription, id=subscription_id) saved = False shareerror = False if request.method == 'POST' and int(time.strftime( '%m')) <= Config.business_year_cancelation_month() and int( request.POST.get('subscription')) > 0: type = SubscriptionTypeDao.get_by_id( int(request.POST.get('subscription')))[0] shares = subscription.all_shares if shares < type.shares: shareerror = True else: if subscription.state == 'waiting': for t in TSST.objects.filter(subscription=subscription): t.delete() TSST.objects.create(subscription=subscription, type=type) for t in TFSST.objects.filter(subscription=subscription): t.delete() TFSST.objects.create(subscription=subscription, type=type) saved = True renderdict = get_menu_dict(request) renderdict.update({ 'saved': saved, 'subscription': subscription, 'shareerror': shareerror, 'hours_used': Config.assignment_unit() == 'HOURS', 'next_cancel_date': temporal.next_cancelation_date(), 'selected_subscription': subscription.future_types.all()[0].id, 'subscription_sizes': SubscriptionSizeDao.all_visible_sizes_ordered() }) return render(request, 'size_change.html', renderdict)
def cs_select_subscription(request): if request.user.is_authenticated: member = request.user.member else: member = request.session.get('main_member') if member is None: return redirect('http://' + Config.server_url()) if request.method == 'POST': selectedsubscription = request.POST.get('subscription') size = next( iter( SubscriptionTypeDao.get_by_id( selectedsubscription).values_list('size__units', flat=True) or []), 0) if size > 0: request.session['selectedsubscription'] = selectedsubscription return redirect('/my/create/subscription/selectdepot') return redirect('/my/create/subscription/shares') renderdict = { 'hours_used': Config.assignment_unit() == 'HOURS', 'subscriptionsizes': SubscriptionSizeDao.all_visible_sizes_ordered(), } return render(request, 'createsubscription/select_subscription.html', renderdict)