示例#1
0
    def test_challenge_has_set_up_tags(self):
        # needed since the setup creates some and I don't want to add it to all the other tests.
        Tag.objects_by_account(self.a1).delete()

        self.a1.check_challenge_progress()
        assert self.a1.challenge_has_set_up_tags == False
        Factory.tag_person(self.a1)
        self.a1.check_challenge_progress()
        assert self.a1.challenge_has_set_up_tags == True
示例#2
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()
示例#3
0
文件: views.py 项目: skoczen/mycelium
    def create_tag(self, request, tag_set_id, target_id):
        success = False
        self.__init__(target=get_or_404_by_account(self.TargetModel, request.account, target_id, using='default'), tag_set_id=tag_set_id)
        new_tag = request.REQUEST['new_tag'].strip()
        if new_tag != "":
            ts = get_or_404_by_account(TagSet, request.account, tag_set_id)
            person = get_or_404_by_account(Person, request.account, target_id)
            t = Tag.create_new_tag(tagset=ts,name=new_tag)
            # Needed to trigger group creation.
            t.save()
            t.add_tag_to_person(person)
            success = True

        return self._return_fragments_or_redirect(request,locals())
示例#4
0
    def create_demo_site(cls, organization_name, subdomain=None, delete_existing=False, quick=False, verbose=None, mostly_empty=False, single_user=False, create_subscription=False, with_demo_flag=True):
        if quick:
            max_num_people = 5
            max_num_orgs = 2
            num_tags = 1
            if not verbose:
                verbose = False
        else:
            max_num_people = 2000
            max_num_orgs = 200
            num_tags = 10
            if not verbose:
                verbose = True

        site = Site.objects.get(pk=settings.SITE_ID)

        # Create account
        print_if_verbose(verbose, "Starting creation of %s's site." % organization_name)
        account = cls.account(name=organization_name, subdomain=subdomain, delete_existing=delete_existing, is_demo=with_demo_flag)
        request = DummyObj()
        request.account = account

        print_if_verbose(verbose, "Creating site at %s.%s." % (account.subdomain, site))
        print_if_verbose(verbose, "Account created.")

        admin_accesslevel = AccessLevel.objects.get(name__iexact="Admin")
        staff_accesslevel = AccessLevel.objects.get(name__iexact="Staff")
        volunteer_accesslevel = AccessLevel.objects.get(name__iexact="Volunteer")

        # create admin user (admin / admin)
        cls.useraccount(account=account, username="******", password="******", access_level=admin_accesslevel)
    
        if not single_user:
            # create staff user (staff / staff)
            cls.useraccount(account=account, username="******", password="******", access_level=staff_accesslevel)

            # create volunteer user ( volunteer / volunteer )
            cls.useraccount(account=account, username="******", password="******", access_level=volunteer_accesslevel)
        
        print_if_verbose(verbose, "Users created.")

        # create a bunch of reasonable tags, including the favorite color category
        gen_ts = cls.tagset(account, name="General")
        vol_ts = cls.tagset(account, name="Volunteer")
        don_ts = cls.tagset(account, name="Donor")
        color_ts = cls.tagset(account, name="Favorite Color")
        from rules.tasks import populate_rule_components_for_an_account
        populate_rule_components_for_an_account(account)
        print_if_verbose(verbose, "Tagsets created.")

        if not mostly_empty:
            # gen tags
            cls.tag(account, tagset=gen_ts, name="Board of Directors")
            cls.tag(account, tagset=gen_ts, name="Advocate")
            cls.tag(account, tagset=gen_ts, name="Media Contact")
            cls.tag(account, tagset=gen_ts, name="Community Partner")

            # vol tags
            cls.tag(account, tagset=vol_ts, name="Monday")
            cls.tag(account, tagset=vol_ts, name="Tuesday")
            cls.tag(account, tagset=vol_ts, name="Wednesday")
            cls.tag(account, tagset=vol_ts, name="Thursday")
            cls.tag(account, tagset=vol_ts, name="Friday")
            cls.tag(account, tagset=vol_ts, name="Weekly")
            cls.tag(account, tagset=vol_ts, name="Monthly")
            cls.tag(account, tagset=vol_ts, name="Phone Skills")

            # don tags
            cls.tag(account, tagset=don_ts, name="Major Donor")
            cls.tag(account, tagset=don_ts, name="Potential Major Donor")
            cls.tag(account, tagset=don_ts, name="Fundraiser")
            cls.tag(account, tagset=don_ts, name="Monthly Donor")
            cls.tag(account, tagset=don_ts, name="Quarterly Donor")
            cls.tag(account, tagset=don_ts, name="Yearly Donor")

            # color tags
            cls.tag(account, tagset=color_ts, name="Red")
            cls.tag(account, tagset=color_ts, name="Orange")
            cls.tag(account, tagset=color_ts, name="Yellow")
            cls.tag(account, tagset=color_ts, name="Green")
            cls.tag(account, tagset=color_ts, name="Aquamarine")
            cls.tag(account, tagset=color_ts, name="Blue")
            cls.tag(account, tagset=color_ts, name="Violet")
            cls.tag(account, tagset=color_ts, name="Purple")
            cls.tag(account, tagset=color_ts, name="Black")
            cls.tag(account, tagset=color_ts, name="White")
            cls.tag(account, tagset=color_ts, name="Gray")
            print_if_verbose(verbose, "Tags created.")

            # create a bunch of people
            people_created = []
            num = cls.rand_int(3,max_num_people)
            print_if_verbose(verbose, "Creating %s people" % num,)
            for i in range(0, num):
                p = cls.person(account)
                people_created.append(p)
                print_nobreak_if_verbose(verbose)
            print_if_verbose(verbose, "done.")

            num = cls.rand_int(2,max_num_orgs)
            print_if_verbose(verbose, "Creating %s organizations" % num,)
            # create a few organizations, with people
            for i in range(0, num):
                cls.organization(account)
                print_nobreak_if_verbose(verbose)

            print_if_verbose(verbose, "done.")

            # give some of the people volunteer histories and statii
            print_if_verbose(verbose, "Adding volunteer histories",)
            for p in people_created:
                if cls.rand_bool():
                    cls.volunteer_history(account, p)
                    
                if cls.rand_bool():
                    v = p.volunteer
                    v.status = VOLUNTEER_STATII[1][0]
                    v.save()
                
                print_nobreak_if_verbose(verbose)
            print_if_verbose(verbose, "done.")

            # give some of the people donation histories
            print_if_verbose(verbose, "Adding donation histories",)
            for p in people_created:
                if cls.rand_bool():
                    cls.donor_history(account, p)
                
                print_nobreak_if_verbose(verbose)
            print_if_verbose(verbose, "done.")

            print_if_verbose(verbose, "Adding conversations",)
            for p in people_created:
                if cls.rand_bool():
                    cls.conversation_history(account, p)
                
                print_nobreak_if_verbose(verbose)
            print_if_verbose(verbose, "done.")            

            print_if_verbose(verbose, "Adding tags",)
            # give some of the people tags
            all_tags = [t for t in Tag.objects_by_account(account).all()]
            for p in people_created:
                for i in range(0,cls.rand_int(0,num_tags)):
                    t = all_tags[cls.rand_int(0,len(all_tags)-1)]
                    if t.tagset!=gen_ts or  (cls.rand_bool() and cls.rand_bool()):
                        t.add_tag_to_person(p)
                print_nobreak_if_verbose(verbose)
                
            
            print_if_verbose(verbose, "done."        )

            # create a few groups
            

            # Board of Directors
            group = cls.group(account, name="Board of Directors")
            cls.grouprule(account, "have a general tag that","contains","Board of Directors", group=group)
            print_if_verbose(verbose, "Created Board of Directors group")

            # Active Volunteers
            group = cls.group(account, name="Active Volunteers")
            cls.grouprule(account, "volunteer status","is",VOLUNTEER_STATII[0][0], group=group)
            print_if_verbose(verbose, "Created Active Volunteers group")

            # Warm color people
            group = cls.group(account, name="Warm Color People", rules_boolean=False)
            cls.grouprule(account, "have a Favorite Color tag that","contains","red", group=group)
            cls.grouprule(account, "have a Favorite Color tag that","contains","orange", group=group)
            cls.grouprule(account, "have a Favorite Color tag that","contains","yellow", group=group)
            print_if_verbose(verbose, "Created Warm color people group")

            # Recurring donors
            group = cls.group(account, name="Recurring Donors", rules_boolean=False)
            cls.grouprule(account, "have a Donor tag that","is exactly","monthly donor", group=group)
            cls.grouprule(account, "have a Donor tag that","is exactly","quarterly donor", group=group)
            cls.grouprule(account, "have a Donor tag that","is exactly","yearly donor", group=group)
            print_if_verbose(verbose, "Created Recurring donors group")

            # Volunteers this year
            today = datetime.date.today()
            group = cls.group(account, name="Volunteers this year")
            cls.grouprule(account, "last volunteer shift","is after",datetime.date(day=1,month=1,year=today.year), group=group)
        else:
            print_if_verbose(verbose, "Mostly empty called - skipping people, etc.")

        if create_subscription:
            sub = account.create_stripe_subscription()
            print_if_verbose(verbose, "Created subscription.")

        print_if_verbose(verbose, "Setup complete.")
        return account
示例#5
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()
示例#6
0
 def test_num_tags(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.num_tags, Tag.objects_by_account(a).count())
示例#7
0
文件: views.py 项目: skoczen/mycelium
def save_tags_and_tagsets(request):
    success = False

    data = json.loads(request.POST["data"])
    created_tagsets = []
    created_tags = []
    deleted_tagsets = []
    deleted_tags = []
    
    
    for ts in data["tag_sets"]:
        tagset = None
        if ts["db_pk"]:
            try:
                tagset = TagSet.objects_by_account(request.account).using('default').get(pk=ts["db_pk"])
                tagset.name = ts["name"]
            except TagSet.DoesNotExist: 
                pass
        else:
            tagset, created = TagSet.objects_by_account(request.account).using('default').get_or_create(account=request.account, name=ts["name"])
            created_tagsets.append(tagset)
        if tagset:
            tagset.page_pk = ts["page_pk"]
            if ts["is_deleted"]:
                tagset.delete()
                deleted_tagsets.append(tagset)
            else:
                tagset.order = ts["order"]
                tagset.save()
                for t in ts["tags"]:
                    tag = None

                    if t["db_pk"]:
                        try:
                            tag = Tag.objects_by_account(request.account).using('default').get(pk=t["db_pk"])
                            tag.name = t["name"]
                            tag.tagset = tagset
                        except Tag.DoesNotExist:
                            pass
                    else:
                        tag, created = Tag.objects_by_account(request.account).using('default').get_or_create(account=request.account, name=t["name"], tagset=tagset)
                        try:
                            transaction.commit()
                        except:
                            pass
                        created_tags.append(tag)
                    
                    if tag:
                        tag.page_pk = t["page_pk"]
                        if t["is_deleted"]:
                            tag.delete()
                            deleted_tags.append(tag)
                        else:
                            tag.order = t["order"]
                            try:
                                transaction.commit()
                            except:
                                pass
                            tag.save()
                
    ret_dict = {}
    ret_dict["created_tagsets"] = [{"name":ts.name, "order":ts.order, "db_pk":ts.pk, "page_pk": ts.page_pk} for ts in created_tagsets]
    ret_dict["created_tags"] = [{"name":t.name, "order":t.order, "db_pk":t.pk, "page_pk": t.page_pk} for t in created_tags]
    ret_dict["deleted_tagsets"] = [{"name":ts.name, "order":ts.order, "db_pk":ts.pk, "page_pk": ts.page_pk} for ts in deleted_tagsets]
    ret_dict["deleted_tags"] = [{"name":t.name, "order":t.order, "db_pk":t.pk, "page_pk": t.page_pk} for t in deleted_tags]
    ret_dict["success"] = True

    return ret_dict