def test_non_billable_project_not_requires_organization(self): project = Project(accounting_code=self.non_billable_accounting_code, profit_loss_account=self.profit_loss_account, name='Billable Project', start_date='2016-01-01', end_date='2016-02-01', agreement_URL='https://thisisaurl.com', project_lead=self.user) try: project.full_clean() except ValidationError: self.fail('full_clean raised a validation error')
def test_user_cannot_have_duplicate_projects(self): factories.ProjectFactory(name='dupe', user=u) with self.assertRaises(ValidationError): item = Project(name='dupe', user=u) item.full_clean()
def handle(self, *args, **options): """ Projects """ articles_to_link = [] projects_to_link = [] unlinked_projects = [] publisher = Publisher.objects.get(pk=1) user = User.objects.get(pk=1) l_projects = ProjectsProject.objects.all() for l_project in l_projects: # Get related data sites = Site.objects.filter(pk=1) ProjectsProjectProjectCategories categories = ProjectsProjectcategory.objects.filter(projectsprojectprojectcategories__project_id=l_project.id) types = ProjectsProjecttype.objects.filter(projectsprojectprojecttypes__project_id=l_project.id) try: status = ProjectsProjectstatus.objects.get(projectsproject__id=l_project.id) except: status = None # print u'' # print u'====================================' # print u'' print u'%s' % l_project.title # print u'' # print u'::: Categories: %s ::: Types: %s ::: Status: %s' % (categories.values_list(flat=True), types.values_list(flat=True), status) # ============================ # List & Create new records #### Organisations #### Projects p_kwargs = { 'title': l_project.title, 'building_area': l_project.building_area, 'budget_total': l_project.budget_total, 'city': l_project.city, 'client': l_project.client, 'client_website': l_project.client_website, 'client_website_name': l_project.client_website_name, 'construction': l_project.construction, 'content': l_project.content, 'country': l_project.country, 'created': datetime.datetime.now(), 'created_by': user, 'design_documentation': l_project.design_documentation, 'old_id': l_project.id, 'is_published': True, 'number_of_stories': l_project.number_of_stories, 'post_code': l_project.post_code, 'project_website': l_project.client_website, 'published': datetime.datetime.now(), 'published_by': user, 'publisher': publisher, 'short_title': l_project.title, 'site_size': l_project.site_size, 'slug': SlugifyUniquely(truncate_words(l_project.title, 4), Project), 'state': l_project.state, 'street': l_project.street, 'suburb': l_project.suburb, 'summary': l_project.summary } project = Project(**p_kwargs) if status: try: project.project_status = ProjectStatus.objects.get(pk=1) except: pass try: project = Project.objects.get(title=project.title) except ObjectDoesNotExist: # Create new try: project.full_clean() # pass except ValidationError, e: # Do something based on the errors contained in e.message_dict. # Display them to a user, or handle them programatically. print e else: # Save new # project.save() # if project.save(): # project.organisation_type = l_org_types project.save() print u'=== === === saving project %s' % project else: # Once saved, add related items == print u'=== === === project exists %s' % project # Clean up or add # Products l_p_products = ProjectsProjectproduct.objects.filter(project=l_project) for l_p_product in l_p_products: print u'--- --- %s :: %s' % (l_p_product.label, l_p_product.products) pp_kwargs = { 'project': project, 'label': l_p_product.label, 'products': l_p_product.products } project_product = ProjectProduct(**pp_kwargs) try: project_product.full_clean() # pass except ValidationError, e: # Do something based on the errors contained in e.message_dict. # Display them to a user, or handle them programatically. print e else: try: pp = ProjectProduct.objects.get(label=l_p_product.label, project=l_project) except MultipleObjectsReturned: pps = ProjectProduct.objects.filter(label=l_p_product.label, project=l_project)[2:] ipdb.set_trace() for pp in pps: pp.delete() print u'=== === === deleting products :: %s' % pp except ObjectDoesNotExist: project_product.save() print u'=== === === saving new products :: %s' % project_product else: print u'=== === === products already exists :: %s' % project_product ##### Project Roles # Individuals l_p_individuals = ProjectsProjectindividual.objects.filter(project=l_project) # l_p_individuals = [] # prevents from processing for l_p_individual in l_p_individuals: try: organisation = Organisation.objects.get(title=l_p_individual.organisation.title) except ObjectDoesNotExist: """ Does not exist, so create new. """ o_kwargs = { 'title': l_p_individual.organisation.title, 'content': l_p_individual.organisation.content, 'street': l_p_individual.organisation.street, 'suburb': l_p_individual.organisation.suburb, 'city': l_p_individual.organisation.city, 'country': l_p_individual.organisation.country, 'state': l_p_individual.organisation.state, 'post_code': l_p_individual.organisation.post_code, 'phone': l_p_individual.organisation.phone, 'fax': l_p_individual.organisation.fax, 'mobile': l_p_individual.organisation.mobile, 'email': l_p_individual.organisation.email, 'website': l_p_individual.organisation.website, 'website_name': l_p_individual.organisation.website_name, } organisation = Organisation(**o_kwargs) print u'=== === saving %s' % organisation try: organisation.full_clean() except ValidationError, e: # Do something based on the errors contained in e.message_dict. # Display them to a user, or handle them programatically. print e else: organisation.save() print u'=== === === saving %s' % organisation p_individual = { 'project': project, # 'role': role_type, # 'individual': None, 'credit': l_p_individual.credit, 'custom_credit': l_p_individual.role, 'organisation': organisation, } project_individual = ProjectIndividual(**p_individual) try: project_individual.full_clean() except ValidationError, e: # Do something based on the errors contained in e.message_dict. # Display them to a user, or handle them programatically. print e