Пример #1
0
    def _value_rows_from_queryset(cls, query_set, template, with_header=True,**kwargs):
        from spreadsheets.models import Spreadsheet
        rows = []

        template_instance = Spreadsheet.spreadsheet_template_instance_class(template.template_type)(query_set[0].account)
        if with_header:
            rows.append([f[1].name for f in template_instance.fields.iteritems()])
        
        for r in query_set:
            try:
                row = []
                template_instance.get_primary_target(r.account, r.pk, force_refresh=True)
                target_objects,created = template_instance.get_target_objects()

                for k,f in template.fields.iteritems():
                    col_val = None
                    if target_objects[f.model_key]:
                        # try:
                        if f.field in target_objects[f.model_key].__dict__:
                            col_val = target_objects[f.model_key].__dict__[f.field]
                        else:
                            col_val = eval("target_objects[f.model_key].%s" % f.field)
                        # except:
                        #     row.append("")    
                    if not col_val:
                        col_val = ""
                    row.append(col_val)
                rows.append(row)
            except Exception, e:
                print "Error exporting row %s %s %s\n %s" % (r, r.pk, template_instance, e)
                from qi_toolkit.helpers import print_exception
                print_exception()
                pass
Пример #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_spreadsheets(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.num_spreadsheets, Spreadsheet.objects_by_account(a).count())