def extra_change(request, subscription_id): ''' change an extra subscription ''' subscription = get_object_or_404(Subscription, id=subscription_id) extra_order_allowed = subscription.waiting or subscription.active if request.method == 'POST': if not extra_order_allowed: raise ValidationError( _('Für gekündigte {} können keine Zusatzabos bestellt werden' ).format(Config.vocabulary('subscription_pl')), code='invalid') for type in ExtraSubscriptionTypeDao.all_visible_extra_types(): value = int(request.POST.get('extra' + str(type.id))) if value > 0: for x in range(value): ExtraSubscription.objects.create( main_subscription=subscription, type=type) return redirect('extra-change', subscription_id=subscription.id) renderdict = get_menu_dict(request) renderdict.update({ 'types': ExtraSubscriptionTypeDao.all_visible_extra_types(), 'extras': subscription.extra_subscription_set.all(), 'sub_id': subscription_id, 'extra_order_allowed': extra_order_allowed, }) return render(request, 'extra_change.html', renderdict)
def extra_change(request, subscription_id): ''' change an extra subscription ''' subscription = get_object_or_404(Subscription, id=subscription_id) if request.method == 'POST': for type in ExtraSubscriptionTypeDao.all_extra_types(): value = int(request.POST.get('extra'+str(type.id))) if value>0: for x in range(value): ExtraSubscription.objects.create(main_subscription=subscription, type=type) return redirect('/my/subscription/change/extra/'+str(subscription.id)+'/') renderdict = get_menu_dict(request) renderdict.update({ 'types': ExtraSubscriptionTypeDao.all_extra_types(), 'extras': subscription.extra_subscription_set.all() }) return render(request, 'extra_change.html', renderdict)
def fill_overview_cache(self): self.fill_active_subscription_cache() self.overview_cache = [] for subscription_size in SubscriptionSizeDao.sizes_for_depot_list(): self.overview_cache.append(self.subscription_amounts(self.subscription_cache, subscription_size.name)) for category in ExtraSubscriptionCategoryDao.all_categories_ordered(): for extra_subscription in ExtraSubscriptionTypeDao.extra_types_by_category_ordered(category): code = extra_subscription.name self.overview_cache.append(self.extra_subscription(self.subscription_cache, code))
def fill_overview_cache(self): self.fill_active_subscription_cache() self.overview_cache = [] for subscription_size in SubscriptionSizeDao.sizes_for_depot_list(): cache = self.subscription_cache size_name = subscription_size.name amounts = self.subscription_amounts(cache, size_name) self.overview_cache.append(amounts) for category in ExtraSubscriptionCategoryDao.all_categories_ordered(): types = ExtraSubscriptionTypeDao.extra_types_by_category_ordered( category) for extra_subscription in types: code = extra_subscription.name cache = self.subscription_cache esub = self.extra_subscription(cache, code) self.overview_cache.append(esub)
def future(request): renderdict = get_menu_dict(request) subscriptionsizes = [] subscription_lines = dict({}) extra_lines = dict({}) for subscription_size in SubscriptionSizeDao.all_sizes_ordered(): subscriptionsizes.append(subscription_size.id) subscription_lines[subscription_size.id] = { 'name': subscription_size.product.name + '-' + subscription_size.name, 'future': 0, 'now': 0 } for extra_subscription in ExtraSubscriptionTypeDao.all_extra_types(): extra_lines[extra_subscription.name] = { 'name': extra_subscription.name, 'future': 0, 'now': 0 } for subscription in SubscriptionDao.all_active_subscritions(): for subscription_size in subscriptionsizes: subscription_lines[subscription_size][ 'now'] += subscription.subscription_amount(subscription_size) for users_subscription in ExtraSubscriptionDao.all_active_extrasubscritions( ): extra_lines[users_subscription.type.name]['now'] += 1 for subscription in SubscriptionDao.future_subscriptions(): for subscription_size in subscriptionsizes: subscription_lines[subscription_size][ 'future'] += subscription.subscription_amount_future( subscription_size) for users_subscription in ExtraSubscriptionDao.future_extrasubscriptions(): extra_lines[users_subscription.type.name]['future'] += 1 renderdict.update({ 'changed': request.GET.get('changed'), 'subscription_lines': iter(subscription_lines.values()), 'extra_lines': iter(extra_lines.values()), }) return render(request, 'future.html', renderdict)
def future(request): renderdict = get_menu_dict(request) subscriptionsizes = [] subscription_lines = dict({}) extra_lines = dict({}) for subscription_size in SubscriptionSizeDao.all_sizes_ordered(): subscriptionsizes.append(subscription_size.name) subscription_lines[subscription_size.name] = { 'name': subscription_size.name, 'future': 0, 'now': 0 } for extra_subscription in ExtraSubscriptionTypeDao.all_extra_types(): extra_lines[extra_subscription.name] = { 'name': extra_subscription.name, 'future': 0, 'now': 0 } for subscription in SubscriptionDao.all_subscritions(): for subscription_size in subscriptionsizes: subscription_lines[subscription_size]['now'] += subscription.subscription_amount(subscription_size) subscription_lines[subscription_size]['future'] += subscription.subscription_amount_future( subscription_size) for users_subscription in subscription.future_extra_subscriptions.all(): extra_lines[users_subscription.type.name]['future'] += 1 for users_subscription in subscription.extra_subscriptions.all(): extra_lines[users_subscription.type.name]['now'] += 1 month = int(time.strftime("%m")) day = int(time.strftime("%d")) renderdict.update({ 'changed': request.GET.get("changed"), 'subscription_lines': iter(subscription_lines.values()), 'extra_lines': iter(extra_lines.values()), 'subscription_change_enabled': month is 12 or (month is 1 and day <= 6) }) return render(request, 'future.html', renderdict)
def handle(self, *args, **options): if not options['force'] and timezone.now().weekday( ) not in Config.depot_list_generation_days(): print( 'not the specified day for depot list generation, use --force to override' ) return if options['future'] or timezone.now().weekday( ) in Config.depot_list_generation_days(): for subscription in SubscriptionDao.subscritions_with_future_depots( ): subscription.depot = subscription.future_depot subscription.future_depot = None subscription.save() emails = [] for member in subscription.recipients(): emails.append(member.email) send_depot_changed(emails, subscription.depot) if options['force'] and not options['future']: print('future depots ignored, use --future to override') depots = DepotDao.all_depots_order_by_code() subscription_names = [] for subscription_size in SubscriptionSizeDao.sizes_for_depot_list(): subscription_names.append(subscription_size.name) categories = [] types = [] for category in ExtraSubscriptionCategoryDao.all_categories_ordered(): cat = {'name': category.name, 'description': category.description} count = 0 for extra_subscription in ExtraSubscriptionTypeDao.extra_types_by_category_ordered( category): count += 1 type = { 'name': extra_subscription.name, 'size': extra_subscription.size, 'last': False } types.append(type) type['last'] = True cat['count'] = count categories.append(cat) used_weekdays = [] for item in DepotDao.distinct_weekdays(): used_weekdays.append(weekdays[item['weekday']]) overview = {'all': None} for weekday in used_weekdays: overview[weekday] = None count = len(types) + len(subscription_names) for weekday in used_weekdays: overview[weekday] = [0] * count overview['all'] = [0] * count all = overview.get('all') for depot in depots: depot.fill_overview_cache() depot.fill_active_subscription_cache() row = overview.get(depot.get_weekday_display()) count = 0 # noinspection PyTypeChecker while count < len(row): row[count] += depot.overview_cache[count] all[count] += depot.overview_cache[count] count += 1 insert_point = len(subscription_names) for weekday in used_weekdays: overview[weekday].insert(insert_point, 0) overview['all'].insert(insert_point, 0) index = 0 for subscription_size in SubscriptionSizeDao.sizes_for_depot_list(): for weekday in used_weekdays: overview[weekday][insert_point] = overview[weekday][insert_point] + subscription_size.size * \ overview[weekday][index] overview['all'][insert_point] = overview['all'][ insert_point] + subscription_size.size * overview['all'][index] index += 1 renderdict = { 'overview': overview, 'depots': depots, 'subscription_names': subscription_names, 'subscriptioncount': len(subscription_names) + 1, 'categories': categories, 'types': types, 'datum': timezone.now(), 'weekdays': used_weekdays } render_to_pdf_storage('exports/legacy.html', renderdict, 'dpl.pdf') render_to_pdf_storage('exports/depotlist.html', renderdict, 'depotlist.pdf') render_to_pdf_storage('exports/depot_overview.html', renderdict, 'depot_overview.pdf') render_to_pdf_storage('exports/amount_overview.html', renderdict, 'amount_overview.pdf')
def extra_change(request): """ change an extra subscription """ saved = False if request.method == "POST": for extra_subscription in ExtraSubscriptionType.objects.all(): existing = request.user.member.subscription.extra_subscription_set.filter( type__id=extra_subscription.id) if request.POST.get("subscription" + str(extra_subscription.id)) == str( extra_subscription.id): if existing.count() == 0: future_extra_subscription = Extrasubscription.objects.create( main_subscription=request.user.member.subscription, type=extra_subscription) future_extra_subscription.active = False future_extra_subscription.save() else: has_active = False index = 0 while not has_active or index < existing.count(): existing_extra_subscription = exisitng[index] if existing_extra_subscription.active == True: has_active = True elif existing_extra_subscription.canceled == True and existing_extra_subscription.active == True: existing_extra_subscription.canceled = False existing_extra_subscription.save() has_active = True index += 1 if not has_active: future_extra_subscription = Extrasubscription.create( main_subscription=request.user.member.subscription, type=extra_subscription) future_extra_subscription.active = False future_extra_subscription.save() else: if existing.count() > 0: for existing_extra_subscription in existing: if existing_extra_subscription.canceled == False and existing_extra_subscription.active == True: existing_extra_subscription.canceled = True existing_extra_subscription.save() elif existing_extra_subscription.deactivation_date is None and existing_extra_subscription.active == False: existing_extra_subscription.delete() request.user.member.subscription.save() saved = True subscriptions = [] for subscription in ExtraSubscriptionTypeDao.all_extra_types(): if request.user.member.subscription.future_extra_subscriptions.filter( type__id=subscription.id).count() > 0: subscriptions.append({ 'id': subscription.id, 'name': subscription.name, 'selected': True }) else: subscriptions.append({ 'id': subscription.id, 'name': subscription.name }) renderdict = get_menu_dict(request) renderdict.update({ 'saved': saved, 'member': request.user.member, "extras": subscriptions }) return render(request, "extra_change.html", renderdict)