def create_grant_clr_cache(): print('create_grant_clr_cache') from grants.tasks import update_grant_metadata pks = Grant.objects.filter(active=True, hidden=False).values_list('pk', flat=True) for pk in pks: update_grant_metadata.delay(pk)
def handle(self, *args, **options): pending_contribution = Contribution.objects.filter(tx_cleared=False) zcash_pending_contributions = pending_contribution.filter( subscription__tenant='ZCASH') if zcash_pending_contributions: # Auto expire pending transactions timeout_period = timezone.now() - timedelta(minutes=60) contrib_to_be_expired = zcash_pending_contributions.filter( created_on__lt=timeout_period) contrib_to_be_expired.update(success=False, tx_cleared=False) for contribution in contrib_to_be_expired: update_grant_metadata.delay(contribution.subscription.grant.pk) for contribution in zcash_pending_contributions.all(): sync_payout(contribution)
def record_contribution_activity(contribution): from dashboard.models import Activity from marketing.mails import new_supporter, thank_you_for_supporting, successful_contribution from grants.tasks import update_grant_metadata try: event_name = 'new_grant_contribution' subscription = contribution.subscription grant = subscription.grant metadata = { 'id': subscription.id, 'value_in_token': str(subscription.amount_per_period), 'value_in_usdt_now': str(round(subscription.amount_per_period_usdt, 2)), 'token_name': subscription.token_symbol, 'title': subscription.grant.title, 'grant_url': subscription.grant.url, 'num_tx_approved': round(subscription.num_tx_approved), 'category': 'grant', } kwargs = { 'activity_type': event_name, 'grant': grant, 'subscription': subscription, 'profile': subscription.contributor_profile, 'metadata': metadata } activity = Activity.objects.create(**kwargs) if subscription.comments and activity: Comment.objects.create(profile=subscription.contributor_profile, activity=activity, comment=subscription.comments) successful_contribution(grant, subscription, contribution) new_supporter(grant, subscription) thank_you_for_supporting(grant, subscription) update_grant_metadata.delay(grant.pk) except Exception as e: logger.error( f"error in record_contribution_activity: {e} - {contribution}")
def save(self, update=True, *args, **kwargs): """Override the Grant save to optionally handle modified_on logic.""" self.clr_prediction_curve = self.calc_clr_prediction_curve self.clr_round_num = self.calc_clr_round_label self.search_vector = ( SearchVector('title', weight='A') + SearchVector('description', weight='B') ) if self.modified_on < (timezone.now() - timezone.timedelta(minutes=15)): from grants.tasks import update_grant_metadata update_grant_metadata.delay(self.pk) from economy.models import get_time if update: self.modified_on = get_time() return super(Grant, self).save(*args, **kwargs)
def handle(self, *args, **options): pending_contribution = Contribution.objects.filter(tx_cleared=False) # Auto expire pending transactions timeout_period = timezone.now() - timedelta(minutes=60) tenants = ['ZCASH', 'ZIL', 'CELO', 'POLKADOT', 'HARMONY'] for tenant in tenants: tenant_pending_contributions = pending_contribution.filter( subscription__tenant=tenant) contrib_to_be_expired = tenant_pending_contributions.filter( created_on__lt=timeout_period) contrib_to_be_expired.update(success=False, tx_cleared=False) for contribution in contrib_to_be_expired: update_grant_metadata.delay(contribution.subscription.grant.pk) for contribution in tenant_pending_contributions.all(): sync_payout(contribution)
def create_contribution(self, tx_id, is_successful_contribution=True): from marketing.mails import successful_contribution from grants.tasks import update_grant_metadata now = timezone.now() self.last_contribution_date = now self.next_contribution_date = now self.num_tx_processed += 1 contribution = Contribution() contribution.success = False contribution.tx_cleared = False contribution.subscription = self contribution.split_tx_id = self.split_tx_id contribution.split_tx_confirmed = self.split_tx_confirmed if tx_id: contribution.tx_id = tx_id contribution.save() grant = self.grant value_usdt = self.get_converted_amount(False) if value_usdt: self.amount_per_period_usdt = value_usdt grant.amount_received += Decimal(value_usdt) if self.num_tx_processed == self.num_tx_approved and value_usdt: grant.monthly_amount_subscribed -= self.get_converted_monthly_amount( ) self.active = False self.save() grant.updateActiveSubscriptions() grant.save() if is_successful_contribution: successful_contribution(self.grant, self, contribution) update_grant_metadata.delay(self.pk) return contribution