コード例 #1
0
ファイル: subs.py プロジェクト: olmaga/juntagrico
 def price(self):
     result = 0
     for sub_size in SubscriptionSizeDao.all_sizes_ordered():
         amount = Subscription.calc_subscritpion_amount(
             self.size, sub_size.name)
         result += sub_size.price * amount
     return result
コード例 #2
0
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_sizes_ordered()
    })
    return render(request, 'size_change.html', renderdict)
コード例 #3
0
ファイル: subs.py プロジェクト: olmaga/juntagrico
 def required_assignments(self):
     result = 0
     for sub_size in SubscriptionSizeDao.all_sizes_ordered():
         amount = Subscription.calc_subscritpion_amount(
             self.size, sub_size.name)
         result += sub_size.required_assignments * amount
     return result
コード例 #4
0
ファイル: depot.py プロジェクト: olmaga/juntagrico
 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))
コード例 #5
0
ファイル: subs.py プロジェクト: olmaga/juntagrico
 def get_size_name(size=0):
     size_names = []
     for sub_size in SubscriptionSizeDao.all_sizes_ordered():
         amount = Subscription.calc_subscritpion_amount(size, sub_size.name)
         if amount > 0:
             size_names.append(sub_size.long_name + " : " + str(amount))
     if len(size_names) > 0:
         return ', '.join(size_names)
     return "kein Abo"
コード例 #6
0
ファイル: subs.py プロジェクト: olmaga/juntagrico
 def fill_sizes_cache():
     list = []
     map = {}
     index = 0
     for size in SubscriptionSizeDao.all_sizes_ordered():
         list.append(size.size)
         map[size.name] = index
         index += 1
     Subscription.sizes_cache = {
         'list': list,
         'map': map,
     }
コード例 #7
0
 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)
コード例 #8
0
ファイル: views_admin.py プロジェクト: cfra/juntagrico
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)
コード例 #9
0
ファイル: views_admin.py プロジェクト: olmaga/juntagrico
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)
コード例 #10
0
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)
コード例 #11
0
def size_change(request):
    """
    change the size of an subscription
    """
    saved = False
    if request.method == "POST" and int(time.strftime(
            "%m")) <= Config.business_year_cancelation_month() and int(
                request.POST.get("subscription")) > 0:
        request.user.member.subscription.future_size = int(
            request.POST.get("subscription"))
        request.user.member.subscription.save()
        saved = True
    renderdict = get_menu_dict(request)
    renderdict.update({
        'saved':
        saved,
        'next_cancel_date':
        temporal.next_cancelation_date(),
        'size':
        request.user.member.subscription.future_size,
        'subscription_sizes':
        SubscriptionSizeDao.all_sizes_ordered()
    })
    return render(request, "size_change.html", renderdict)
コード例 #12
0
    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')
コード例 #13
0
def createsubscription(request):
    """
    create a subscription
    """
    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())

    shareerror = False
    subscriptionform = SubscriptionForm()
    session_subscription = request.session.get('create_subscription')
    co_members = request.session.get('create_co_members', [])
    co_members_shares = request.session.get('create_co_members_shares', [])
    member_shares = request.session.get('create_member_shares', [])

    selectedsubscription = "none"
    selected_depot = None
    existing_member_shares = 0
    if member.pk is not None:
        existing_member_shares = member.share_set.all().count()
    shares = existing_member_shares

    if session_subscription is not None:
        selectedsubscription = next(
            iter(
                SubscriptionSizeDao.sizes_by_size(
                    session_subscription.size).values_list('name', flat=True)
                or []), 'none')
        selected_depot = session_subscription.depot

    co_member_shares = len(co_members_shares)
    if request.method == "POST":
        shares += int(request.POST.get("shares"))
        selectedsubscription = request.POST.get("subscription")
        subscriptionform = SubscriptionForm(request.POST)

        shares += co_member_shares
        min_num_shares = next(
            iter(
                SubscriptionSizeDao.sizes_by_name(
                    selectedsubscription).values_list('shares', flat=True)
                or []), 1)
        if shares < min_num_shares or not subscriptionform.is_valid():
            shareerror = shares < min_num_shares
        else:
            size = next(
                iter(
                    SubscriptionSizeDao.sizes_by_name(
                        selectedsubscription).values_list('size', flat=True)
                    or []), 0)

            if size > 0:
                session_subscription = Subscription(
                    **subscriptionform.cleaned_data)
                session_subscription.depot = DepotDao.depot_by_id(
                    request.POST.get("depot"))
                session_subscription.primary_member = member
                session_subscription.size = size

            if len(member_shares) < int(request.POST.get("shares")):
                toadd = int(request.POST.get("shares")) - len(member_shares)
                for num in range(0, toadd):
                    member_shares.append(Share(member=member, paid_date=None))
            elif len(member_shares) > int(request.POST.get("shares")):
                toremove = len(member_shares) - int(request.POST.get("shares"))
                for num in range(0, toremove):
                    member_shares.pop()

            if request.POST.get("add_member"):
                request.session['create_subscription'] = session_subscription
                request.session['create_member_shares'] = member_shares
                return redirect("/my/cosubmember/0")
            else:
                password = None
                if member.pk is None:
                    member.save()
                    password = password_generator()
                    member.user.set_password(password)
                    member.user.save()
                if session_subscription is not None:
                    session_subscription.save()
                    member.subscription_id = session_subscription.id
                    member.save()
                send_welcome_mail(
                    member.email, password,
                    hashlib.sha1((member.email +
                                  str(member.id)).encode('utf8')).hexdigest())
                for co_member in co_members:
                    co_member.subscription_id = session_subscription.id
                    co_member.save()
                    pw = None
                    if co_member.confirmed is False:
                        pw = password_generator()
                        co_member.user.set_password(pw)
                        co_member.user.save()
                    send_been_added_to_subscription(
                        co_member.email, pw, member.get_name(), shares,
                        hashlib.sha1(
                            (co_member.email +
                             str(co_member.id)).encode('utf8')).hexdigest())
                for share in member_shares + co_members_shares:
                    if share.id is None:
                        if share.member.email == member.email:
                            share.member = member
                        else:
                            share.member = list(
                                (co_member for co_member in co_members
                                 if co_member.email == share.member.email))[0]
                        share.save()
                        send_share_created_mail(share)
                request.session['create_subscription'] = None
                request.session['create_co_members'] = []
                request.session['create_co_members_shares'] = []
                request.session['create_member_shares'] = []
                if request.user.is_authenticated():
                    return redirect("/my/home")
                else:
                    return redirect("/my/welcome")

    renderdict = {
        'co_member_shares': co_member_shares,
        'existing_member_shares': existing_member_shares,
        'member': member,
        'subscription_sizes': SubscriptionSizeDao.all_sizes_ordered(),
        'depots': DepotDao.all_depots(),
        'selected_depot': selected_depot,
        'selected_subscription': selectedsubscription,
        'shareerror': shareerror,
        'co_members': co_members,
        'subscriptionform': subscriptionform
    }
    return render(request, "createsubscription.html", renderdict)