from django.conf import settings

from account.models import User, UserProfile
from common.consts import EOI_TYPES
from common.factories import (
    PartnerFactory,
    PartnerMemberFactory,
    AgencyMemberFactory,
    EOIFactory,
)


def clean_up_data_in_db():
    if settings.ENV == 'dev':
        print "Deleting all ORM objects"

        User.objects.all().delete()
        UserProfile.objects.all().delete()
        print "All ORM objects deleted"


def generate_fake_data(quantity=4):

    admin, created = User.objects.get_or_create(username='admin', defaults={
        'email': 'admin@unicef.org',
        'is_superuser': True,
        'is_staff': True,
    })
    password = 'Passw0rd!'
    admin.set_password(password)
    admin.save()
    print "Superuser created:{}/{}".format(admin.username, password)

    PartnerFactory.create_batch(quantity)
    print "{} Partner objects created".format(quantity)

    PartnerMemberFactory.create_batch(quantity/2)
    print "{} PartnerMember objects created".format(quantity/2)

    AgencyMemberFactory.create_batch(quantity/2)
    print "{} AgencyMember objects created".format(quantity/2)

    EOIFactory.create_batch(quantity)
    print "{} open EOI objects created".format(quantity)

    for idx in xrange(0, quantity):
        EOIFactory(display_type=EOI_TYPES.direct)
    print "{} direct EOI objects created".format(quantity)

@@ -228,16 +228,82 @@
 tory,%0A)%0A
+from partner.models import Partner%0Afrom project.models import EOI%0A
 %0A%0Adef cl
@@ -1425,28 +1425,235 @@
 s created%22.format(quantity)%0A
+%0A    for eoi in EOI.objects.filter(display_type=EOI_TYPES.direct):%0A        for partner in Partner.objects.all():%0A            eoi.invited_partners.add(partner)%0A    print %22All partners invited to direct EOI.%22%0A

add partner to invited_partners relation in eoi in fake data generator