示例#1
0
文件: views.py 项目: skoczen/mycelium
def _account_numbers_dict(account):
    start_of_this_year = datetime.date(month=1, day=1, year=datetime.date.today().year)
    
    total_donations = Donation.objects_by_account(account).filter(date__gte=start_of_this_year).count()
    if not total_donations:
        total_donations = 0
    total_donors = Donation.objects_by_account(account).filter(date__gte=start_of_this_year).order_by().all().aggregate(Count('donor', distinct=True))["donor__count"]
    if not total_donors:
        total_donors = 0
    total_donation_amount = Donation.objects_by_account(account).filter(date__gte=start_of_this_year).order_by().all().aggregate(Sum('amount'))["amount__sum"]
    if not total_donation_amount:
        total_donation_amount = 0
    average_donation = Donation.objects_by_account(account).filter(date__gte=start_of_this_year).order_by().all().aggregate(Avg('amount'))["amount__avg"]
    if not average_donation:
        average_donation = 0
    total_volunteer_hours = CompletedShift.objects_by_account(account).filter(date__gte=start_of_this_year).order_by().all().aggregate(Sum('duration'))["duration__sum"]
    if not total_volunteer_hours:
        total_volunteer_hours = 0
    total_people = Person.objects_by_account(account).count()
    total_orgs = Organization.objects_by_account(account).count()
    total_groups = Group.objects_by_account(account).count()
    total_tags = Tag.objects_by_account(account).count()
    total_taggeditems = TaggedItem.objects_by_account(account).count()
    recent_conversations = Conversation.objects_by_account(account).all()[:5]

    return locals()
示例#2
0
    def check_challenge_progress(self):
        """This function checks each uncompleted challenge to see if it's been done,
           and updates the boolean fields as needed"""

        if not self.has_completed_all_challenges:
            from generic_tags.models import Tag
            from groups.models import Group
            from donors.models import Donation
            from volunteers.models import CompletedShift
            from data_import.models import DataImport
            from spreadsheets.models import Spreadsheet

            if not self.challenge_has_imported_contacts:
                if DataImport.objects_by_account(self).count() > 0:
                    self.challenge_has_imported_contacts = True

            if not self.challenge_has_set_up_tags:
                # One non-standard tag.
                if Tag.objects_by_account(self).count() > 0:
                    self.challenge_has_set_up_tags = True
                                
            if not self.challenge_has_added_board:
                # created a tag that contains "board"
                if Tag.objects_by_account(self).filter(name__icontains="board").count() > 0:
                    
                    # and, created a board group with at least one rule on tag
                    if Group.objects_by_account(self).filter(name__icontains="board").count() > 0:
                        for g in Group.objects_by_account(self).all():
                            for r in g.rules.all():
                                if r.is_valid and "board" in r.cleaned_right_side_value.lower():
                                    self.challenge_has_added_board = True


            if not self.challenge_has_created_other_accounts:
                if self.useraccount_set.all().count() > 1:
                    self.challenge_has_created_other_accounts = True

            if not self.challenge_has_downloaded_spreadsheet:
                if Spreadsheet.objects_by_account(self).count() > 0:
                    self.challenge_has_downloaded_spreadsheet = True

            if not self.challenge_has_submitted_support:
                pass
            
            if not self.challenge_has_added_a_donation:
                if Donation.objects_by_account(self).count() > 0:
                    self.challenge_has_added_a_donation = True
                
            if not self.challenge_has_logged_volunteer_hours:
                if CompletedShift.objects_by_account(self).count() > 0:
                    self.challenge_has_logged_volunteer_hours = True

            if not self.has_completed_all_challenges:
                # self.challenge_has_submitted_support and \
                if self.challenge_has_imported_contacts and self.challenge_has_set_up_tags and\
                    self.challenge_has_added_board and self.challenge_has_created_other_accounts and\
                    self.challenge_has_downloaded_spreadsheet and \
                    self.challenge_has_added_a_donation and self.challenge_has_logged_volunteer_hours:

                    if not self.has_completed_all_challenges and self.free_trial_ends_date and self.free_trial_ends_date.date() >= datetime.date.today():

                        self.free_trial_ends_date = self.signup_date + datetime.timedelta(days=44)
                        
                        # TODO: When stripe updates their API, move to this.
                        # sub = self.stripe_subscription
                        # sub.trial_end = self.free_trial_ends_date
                        # sub.save()

                        c = self.stripe_customer
                        c.update_subscription(plan=MONTHLY_PLAN_NAME, trial_end=self.free_trial_ends_date)

                    self.has_completed_all_challenges = True
                    


            if not self.has_completed_any_challenges:
                #  self.challenge_has_submitted_support or\
                if self.challenge_has_imported_contacts or self.challenge_has_set_up_tags or\
                    self.challenge_has_added_board or self.challenge_has_created_other_accounts or\
                    self.challenge_has_downloaded_spreadsheet or\
                    self.challenge_has_added_a_donation or self.challenge_has_logged_volunteer_hours:

                    self.has_completed_any_challenges = True

            self.save()
示例#3
0
 def test_num_groups(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.num_groups, Group.objects_by_account(a).count())