コード例 #1
0
ファイル: control.py プロジェクト: F483/bitcoin-bounties.com
def get(user, bounty):
  if not can_fund(user, bounty):
    return None
  userfund = get_object_or_none(UserFund, user=user, bounty=bounty)
  if not userfund:
    userfund = create(user, bounty)
  return userfund
コード例 #2
0
ファイル: control.py プロジェクト: F483/bitcoin-bounties.com
def get(user, bounty):
    if not can_fund(user, bounty):
        return None
    userfund = get_object_or_none(UserFund, user=user, bounty=bounty)
    if not userfund:
        userfund = create(user, bounty)
    return userfund
コード例 #3
0
ファイル: views.py プロジェクト: F483/bitcoin-bounties.com
def claim(request, bounty_id, claim_id=None):
  bounty = control.get_or_404(request.user, bounty_id)
  if not claim_control.can_view_claims(request.user, bounty):
    raise PermissionDenied
  claims = bounty.claims.all()

  # get selected claim
  claim = None
  if claim_id:
    claim = get_object_or_404(Claim, id=claim_id, bounty=bounty)
  if not claim and len(claims) > 0: # set default claim when none given
    if request.user.is_authenticated(): # default to users claim if it exists
      claim = get_object_or_none(Claim, bounty=bounty, user=request.user)
    if not claim: # default to first claim if user does not have a claim
      claim = claims[0]

  # save comment
  form = None
  if claim and claim_control.can_comment(request.user, claim):
    if request.method == "POST":
      form = comment_forms.Comment(request.POST)
      if form.is_valid():
        claim = claim_control.comment(
          request.user, claim, form.cleaned_data["text"].strip()
        )
        return HttpResponseRedirect(claim.url_details)
    else:
      form = comment_forms.Comment()

  tabs = _view_tabs(request.user, bounty, "CLAIMS")
  args = {
    "tabs" : tabs, "bounty" : bounty, "claim" : claim,
    "claims" : claims, "form" : form
  }
  return render_response(request, 'bounty/view/claims.html', args)
コード例 #4
0
ファイル: models.py プロジェクト: F483/bitcoin-bounties.com
    def torefund(self):

        # no refund for ongoing bounties
        if self.bounty.state in ['PENDING', 'ACTIVE', 'MEDIATION']:
            return Decimal("0.0")

        # no refund for successful bounties not yet payed
        from apps.claim.models import Claim  # avoid circular import
        claim = get_object_or_none(Claim, bounty=self.bounty, successful=True)
        if claim and not claim.payout:
            return Decimal("0.0")

        # everything <= minheight already processed
        minheight = 0
        if claim and claim.payout:
            minheight = claim.payout.chainheight
        for payment in self.refund_payments.all():
            if payment.chainheight > minheight:
                minheight = payment.chainheight

        unprocessedtx = lambda tx: self._am.get_tx_height(tx['txid']
                                                          ) > minheight
        txlist = filter(unprocessedtx, self.receive_transactions)
        total = Decimal(sum(map(lambda tx: tx["amount"], txlist)))
        return total - self._am.quantize(total * self.bounty.fraction_fees)
コード例 #5
0
ファイル: control.py プロジェクト: F483/bitcoin-bounties.com
def can_claim(user, bounty):
  if not user.is_authenticated():
    return False
  if bounty.state != "ACTIVE":
    return False # can only claim active bounties
  if get_object_or_none(Claim, user=user, bounty=bounty):
    return False # claim from user already exists
  return True
コード例 #6
0
def can_claim(user, bounty):
    if not user.is_authenticated():
        return False
    if bounty.state != "ACTIVE":
        return False  # can only claim active bounties
    if get_object_or_none(Claim, user=user, bounty=bounty):
        return False  # claim from user already exists
    return True
コード例 #7
0
ファイル: control.py プロジェクト: F483/bitcoin-bounties.com
def can_accept(user, claim):
  if not user.is_authenticated():
    return False
  if not userfund_control.funded_bounty(user, claim.bounty):
    return False # user did not fund bounty
  if claim.bounty.state not in ["ACTIVE", "MEDIATION"]:
    return False # invalid state
  if get_object_or_none(Accepted, user=user, claim__bounty=claim.bounty):
    return False # already accepted a claim
  return True
コード例 #8
0
def can_accept(user, claim):
    if not user.is_authenticated():
        return False
    if not userfund_control.funded_bounty(user, claim.bounty):
        return False  # user did not fund bounty
    if claim.bounty.state not in ["ACTIVE", "MEDIATION"]:
        return False  # invalid state
    if get_object_or_none(Accepted, user=user, claim__bounty=claim.bounty):
        return False  # already accepted a claim
    return True
コード例 #9
0
ファイル: control.py プロジェクト: F483/bitcoin-bounties.com
def can_view_claims(user, bounty):
  if bounty.public:
    return True
  if not user.is_authenticated():
    return False
  if user.is_staff:
    return True
  if bounty.created_by == user:
    return True
  if get_object_or_none(Claim, user=user, bounty=bounty):
    return True # user has a claim for this bounty
  return False
コード例 #10
0
def can_view_claims(user, bounty):
    if bounty.public:
        return True
    if not user.is_authenticated():
        return False
    if user.is_staff:
        return True
    if bounty.created_by == user:
        return True
    if get_object_or_none(Claim, user=user, bounty=bounty):
        return True  # user has a claim for this bounty
    return False
コード例 #11
0
ファイル: models.py プロジェクト: F483/bitcoin-bounties.com
  def torefund(self):

    # no refund for ongoing bounties
    if self.bounty.state in ['PENDING', 'ACTIVE', 'MEDIATION']:
      return Decimal("0.0")

    # no refund for successful bounties not yet payed 
    from apps.claim.models import Claim # avoid circular import
    claim = get_object_or_none(Claim, bounty=self.bounty, successful=True)
    if claim and not claim.payout:
      return Decimal("0.0")

    # everything <= minheight already processed
    minheight = 0
    if claim and claim.payout:
      minheight = claim.payout.chainheight
    for payment in self.refund_payments.all():
      if payment.chainheight > minheight:
        minheight = payment.chainheight

    unprocessedtx = lambda tx: self._am.get_tx_height(tx['txid']) > minheight
    txlist = filter(unprocessedtx, self.receive_transactions)
    total = Decimal(sum(map(lambda tx: tx["amount"], txlist)))
    return total - self._am.quantize(total * self.bounty.fraction_fees)
コード例 #12
0
ファイル: control.py プロジェクト: F483/bitcoin-bounties.com
def funded_bounty(user, bounty):
    userfund = get_object_or_none(UserFund, user=user, bounty=bounty)
    if userfund:
        return userfund.received > Decimal("0.0")
    return False
コード例 #13
0
ファイル: control.py プロジェクト: F483/bitcoin-bounties.com
def funded_bounty(user, bounty):
  userfund = get_object_or_none(UserFund, user=user, bounty=bounty)
  if userfund:
    return userfund.received > Decimal("0.0")
  return False
コード例 #14
0
ファイル: models.py プロジェクト: F483/bitcoin-bounties.com
 def awarded(self):
   from apps.claim.models import Claim # prevent circular import ...
   return get_object_or_none(Claim, bounty=self, successful=True)
コード例 #15
0
ファイル: email.py プロジェクト: F483/bitcoin-bounties.com
def get_emailaddress_or_none(user):
  email_address = get_object_or_none(EmailAddress, user=user, primary=True)
  return email_address and email_address.email or None