예제 #1
0
def deletePayment(request, uid=None):
    """
  Delete payment (subscription) of User with id == uid which is made today.
  Subscription will be deleted ONLY IF (s.paymaster == request.user AND s.date == today).
  """
    if uid == None:
        return Http404("no params")
    if not ((request.user.is_staff and settings.cfgSubsPeriod) or request.user.is_superuser):
        return HttpResponse("user is not staff member or subs. collection period is over!", status=403)

    user = fetchUser(uid)
    nw = datetime.now()
    ss = (
        Subscription.objects.filter(user__id=int(uid))
        .filter(paymaster=request.user)
        .filter(valid=True)
        .filter(date__year=nw.year)
        .filter(date__month=nw.month)
        .filter(date__day=nw.day)
        .order_by("-date")
        .all()
    )
    request.session.modified = True
    if len(ss) == 0:
        return HttpResponse("there are no subscriptions to delete", status=404)
    else:
        sub = ss[0]
        deactOk = deactivateMember(user, sub.oldGroupId)
        if deactOk:
            sub.valid = False
            sub.save()

            logger.info(
                "Staff member (%s) invalidated (deleted) subscription with ID %d (date, user, userId) = (%s, %s, %d)"
                % (request.user.username, sub.id, sub.date, sub.user.username, sub.user.id)
            )
            return HttpResponse('{status:"ok"}', mimetype="application/javascript; charset=utf8")
        else:
            logger.warn(
                "Staff member (%s) FAILED to invalidate (delete) subscription with ID %d (date, user, userId) = (%s, %s, %d)"
                % (request.user.username, sub.id, sub.date, sub.user.username, sub.user.id)
            )
            return HttpResponse('{status:"failed"}', mimetype="application/javascript; charset=utf8", status=400)
예제 #2
0
def makePayment(request, uid=None, amount=None):
    """
  Make payment for user (create subscription).
  """
    if uid == None or amount == None:
        return Http404("no params")
    if not ((request.user.is_staff and settings.cfgSubsPeriod) or request.user.is_superuser):
        return HttpResponse("user is not staff member or subs. collection period is over!", status=403)

    intAmount = int(amount)

    request.session.modified = True

    user = fetchUser(uid)
    (actOk, oldGid) = activateMember(user)

    if not actOk:
        logger.warn(
            "Failed to activate in-person (live) payment for user (%d, %s) by paymaster (%d, %s), amount %d."
            % (user.id, user.username, request.user.id, request.user.username, intAmount)
        )
        return HttpResponse('{status:"failed"}', mimetype="application/javascript; charset=utf8", status=400)

    sub = Subscription(user=user, amount=intAmount)
    sub.oldGroupId = oldGid
    sub.delayed = intAmount == 0
    sub.paymaster = request.user
    sub.paymentType = "P"
    sub.date = datetime.now()
    sub.subsEnd = sub.date + timedelta(days=365)
    sub.save()

    logger.info(
        "Made in-person (live) payment for user (%d, %s) by paymaster (%d, %s), amount %d."
        % (user.id, user.username, request.user.id, request.user.username, intAmount)
    )

    return HttpResponse('{status:"ok"}', mimetype="application/javascript; charset=utf8")