Exemple #1
0
    def add_supply(self, request, **kwargs):
        """
        Adds a new supply to the project
        """
        if request.method == "POST":
            #Get the project
            project = Project.objects.get(pk=kwargs['pk'])

            supply_data = json.loads(request.body)
            supply = Supply.objects.get(pk=supply_data['id'])

            try:
                ProjectSupply.objects.get(supply=supply, project=project)
            except ProjectSupply.DoesNotExist:
                ps = ProjectSupply(supply=supply, project=project)
                ps.save()

            return self.create_response(request, supply_data)
Exemple #2
0
    def _hydrate_supply(self, bundle, supply_obj):
        """
        Creates or updates an supply for the project
        """
        try:
            project_supply = ProjectSupply.objects.get(
                project=bundle.obj, supply_id=supply_obj['id'])
        except ProjectSupply.DoesNotExist as e:
            project_supply = ProjectSupply()
            project_supply.project = bundle.obj
            project_supply.supply = Supply.objects.get(pk=supply_obj['id'])

        for field in project_supply._meta.get_all_field_names():
            if field in supply_obj and field not in [
                    'id', 'project', 'supply'
            ]:
                setattr(project_supply, field, supply_obj[field])

        project_supply.save()
Exemple #3
0
 def setUp(self):
     """
     Sets up for tests
     """
     super(ProjectResourceTestCase, self).setUp()
     
     self.create_user()
     #self.api_client.client.login(username='******', password='******')
     
     #self.customer = Customer.create(**base_customer)
     #self.project = Project.create(**base_project)
     self.project = Project(codename="Ladawan")
     self.project.save()
     self.supply = Supply(description='Grommet')
     self.supply.save()
     self.supply2 = Supply(description='Hinge')
     self.supply2.save()
     self.project_supply = ProjectSupply(supply=self.supply,
                                         project=self.project,
                                         quantity=2)
     self.project_supply.save()