def create_memorg(): memorg = MemOrg(name="Test Member Organization") memorg.save() return memorg
def index(request): #return HttpResponse('worked') if not Group.objects.all(): vol = Group(name="Volunteer") vol.save() ed = Group(name="Member Organization Executive Director") ed.save() mc = Group(name="Member Organization Glean Coordinator") mc.save() sal = Group(name="Salvation Farms Administrator") sal.save() salc = Group(name="Salvation Farms Coordinator") salc.save() ed = Group.objects.get(name="Member Organization Executive Director") if not ed.permissions.all(): mo_list = [Announcement, Template, Distro, GleanEvent, Farm, RecipientSite, Profile, MemOrg, Post] uni_list = [Announcement, Template, Distro, GleanEvent, Farm, FarmLocation, Contact, RecipientSite, Profile, MemOrg, County, Post] mc = Group.objects.get(name="Member Organization Glean Coordinator") sal = Group.objects.get(name="Salvation Farms Administrator") salc = Group.objects.get(name="Salvation Farms Coordinator") for model in mo_list: content_type = ContentType.objects.get_for_model(model) perm = Permission.objects.get(codename='auth', content_type=content_type) ed.permissions.add(perm) mc.permissions.add(perm) sal.permissions.add(perm) salc.permissions.add(perm) for model in uni_list: content_type = ContentType.objects.get_for_model(model) perm = Permission.objects.get(codename='uniauth', content_type=content_type) sal.permissions.add(perm) salc.permissions.add(perm) if County.objects.filter(name='County1').exists(): return HttpResponse("<a href='/'>Go home.</a>") for i in range(memberorg_quant): new = MemOrg(name="MemberOrg"+str(i), description="This is the "+str(i)+"th member org in our gleaning collective!", counties = "A bunch of counties are covered by us, including {insert counties here}") new.save() newTemp = Template(template_name="Default template", body="<html><body>{{content}}{{glean.title}}{{glean.description}}{{rsvp}}{{info}}{{unsubscribe}}</body></html>", member_organization=new) newTemp.save() for i in range(recipient_sites): choices2 = range(memberorg_quant) choice2 = choices2.pop(random.choice(choices2)) memorg = MemOrg.objects.get(name="MemberOrg"+str(choice2)) new = RecipientSite(name="RecipientSite" + str(i), address_one = "515 Main Street", city="Morrisville", state="VT", zipcode="01771",member_organization=memorg) new.save() for i in range(county_quant): new = County(name="County"+str(i),description="County"+str(i), towns="Town"+str(i)) new.save() for i in range(user_quant): name = 'name' + str(i) choices2 = range(memberorg_quant) choice2 = choices2.pop(random.choice(choices2)) memorg = MemOrg.objects.get(name="MemberOrg"+str(choice2)) person = User.objects.create_user(name, '*****@*****.**', 'password') if name == "name0": vol = Group.objects.get(name="Salvation Farms Administrator") person.groups.add(vol) vol = None elif name == "name1": vol = Group.objects.get(name="Member Organization Executive Director") person.groups.add(vol) vol = None else: vol = Group.objects.get(name="Volunteer") person.groups.add(vol) vol = None userprof = Profile(user=person, first_name = 'firsty'+str(i),last_name='lasty'+str(i), member_organization=memorg) userprof.save() choices = range(county_quant) choice1 = choices.pop(random.choice(choices)) county = County.objects.get(name='County'+str(choice1)) userprof.counties.add(county) userprof.save() my_user = 0 my_county = 0 for i in range(farm_quant): if my_user >= user_quant: my_user = 0 if my_county >= county_quant: my_county = 0 choices2 = range(memberorg_quant) choice2 = choices2.pop(random.choice(choices2)) memorg = MemOrg.objects.get(name="MemberOrg"+str(choice2)) new = Farm(name="farm"+str(i),farm_type=FARM_TYPE[0][1],address_one="100 Main Street",address_two="apartment 3",city="Burlington",state="VT",description="generic farm",physical_is_mailing=True,phone_1='8025786266',email="*****@*****.**",direction="Many different directions",instructions="many instructions") new.save() new.member_organization.add(memorg) new.save() new.farmers.add(User.objects.all()[my_user]) new.counties.add(County.objects.all()[my_county]) my_user = my_user + 1 my_county = my_county + 1 my_farm = 0 my_county = 0 for i in range(loc_divinto_farms): if my_farm >= farm_quant: my_farm = 0 if my_county >= county_quant: my_county = 0 new = FarmLocation(farm=Farm.objects.all()[my_farm],name="location"+str(i),description="Grand Central Field",directions="all kinds of directions") new.save() new.counties.add(County.objects.all()[my_county]) my_farm = my_farm + 1 my_county = my_county + 1 return HttpResponse("Your data has been created. <a href='/'>Go home.</a>")