Ejemplo n.º 1
0
    def handle(self, *args, **options):
        self.stdout.write('Starting fill db')

        site = Site.objects.get(pk=1)
        site.domain = site.name = settings.DOMAIN
        site.save()

        user = User.objects.create_superuser(email='*****@*****.**', password='')
        user.set_password('admin')
        user.save()

        accounts = AccountFactory.create_batch(2)
        for account in Account.objects.all():
            admin = AdminFactory(accounts=[account])
            membership = admin.get_membership(account)
            BillingSettingsFactory(account=account)
            board_of_directors = CommitteeFactory(name=_('Board of Directors'), account=account)
            membership.committees.add(board_of_directors)
        UserFactory.create_batch(5, accounts=accounts)
        for account in Account.objects.all():
            CommitteeFactory.create_batch(10, account=account)
        for membership in Membership.objects.filter(user__in=User.objects.select_related().exclude(is_superuser=True)):
            membership.committees.add(*random.sample(set(Committee.objects.filter(account_id=membership.account_id)), 2))
        MeetingFactory.create_batch(10)
        DocumentFactory.create_batch(5)

        self.stdout.write('Completed fill db')
Ejemplo n.º 2
0
    def create_init_data(self):
        from committees.models import Committee
        from profiles.models import User, Membership
        from accounts.factories import AccountFactory
        from profiles.factories import AdminFactory, UserFactory
        from meetings.factories import MeetingFactory
        from committees.factories import CommitteeFactory
        from django.contrib.contenttypes.models import ContentType
        from dashboard.models import RecentActivity
        from meetings.models import Meeting

        self.create_manual_migrations_if_needed()

        self.account = AccountFactory()
        self.admin = AdminFactory(accounts=[self.account])

        UserFactory.create_batch(5, accounts=[self.account])
        CommitteeFactory.create_batch(5)

        for membership in Membership.objects.filter(user__in=User.objects.select_related().exclude(is_superuser=True)):
            membership.committees.add(*random.sample(set(Committee.objects.filter(account_id=membership.account_id)), 2))

        # Set last membership as comittee chairman (comittee_set)
        membership.committee_set.add(*random.sample(set(Committee.objects.filter(account_id=membership.account_id)), 1))
        self.meetings = MeetingFactory.create_batch(2)

        # Document creation is broken and needs fixing
        # for meeting in self.meetings:
        #     DocumentFactory.create_batch(2, meeting=meeting)
        self.membership = Membership.objects.filter(is_admin=False, account=self.account).order_by('pk')[0]
        self.membership_admin = Membership.objects.filter(is_admin=True, account=self.account)[0]

        self.user = self.membership.user

        for meeting in self.meetings:
            RecentActivity.objects.create(init_user=self.user,
                                          account=self.account,
                                          content_type=ContentType.objects.get_for_model(Meeting),
                                          object_id=meeting.id,
                                          action_flag=RecentActivity.ADDITION)