Skip to content
This repository has been archived by the owner on Aug 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #71 from 18F/consolidate-buy-models
Browse files Browse the repository at this point in the history
Consolidate buy models
  • Loading branch information
stvnrlly committed Jan 6, 2017
2 parents dbecbfe + 282ddeb commit 03ce2c7
Show file tree
Hide file tree
Showing 74 changed files with 434 additions and 2,202 deletions.
1 change: 0 additions & 1 deletion acquisitions/settings.py
Expand Up @@ -55,7 +55,6 @@
'markdown_deux',
'floppyforms',
'rest_framework_docs',
'drf_multiple_model',
)

MIDDLEWARE_CLASSES = (
Expand Down
4 changes: 2 additions & 2 deletions nda/tests/test_buy_nda.py
@@ -1,6 +1,6 @@
import pytest
from django.contrib.auth.models import User, Group
from projects.factories import AgileBPAFactory
from projects.factories import BuyFactory
from acquisitions.factories import UserFactory


Expand All @@ -16,7 +16,7 @@ def user(self):
@pytest.fixture
@pytest.mark.django_db
def buy(self):
buy = AgileBPAFactory()
buy = BuyFactory()
return buy

@pytest.mark.django_db
Expand Down
16 changes: 7 additions & 9 deletions projects/admin.py
Expand Up @@ -7,13 +7,12 @@
from projects.models import (
Agency,
AgencyOffice,
AgileBPA,
Buy,
ContractingOffice,
ContractingOfficer,
ContractingOfficerRepresentative,
ContractingSpecialist,
IAA,
Micropurchase,
Project,
)
from projects.widgets import DurationMultiWidget
Expand All @@ -29,7 +28,6 @@
ContractingOfficerRepresentative,
Agency,
AgencyOffice,
Micropurchase,
)
class WorkAdmin(admin.ModelAdmin):
pass
Expand All @@ -52,9 +50,9 @@ def get_readonly_fields(self, request, obj=None):
return []


class AgileBPAForm(forms.ModelForm):
class BuyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(AgileBPAForm, self).__init__(*args, **kwargs)
super(BuyForm, self).__init__(*args, **kwargs)

# Limit the queryset for the technical evaluation panel to team members
# for this project
Expand Down Expand Up @@ -94,17 +92,17 @@ def __init__(self, *args, **kwargs):
)

class Meta:
model = AgileBPA
model = Buy
exclude = ('nda_signed',)
widgets = {
'base_period_length': DurationMultiWidget(),
'option_period_length': DurationMultiWidget(),
}


@admin.register(AgileBPA)
class AgileBPAAdmin(admin.ModelAdmin):
form = AgileBPAForm
@admin.register(Buy)
class BuyAdmin(admin.ModelAdmin):
form = BuyForm
filter_horizontal = ('technical_evaluation_panel',)
fieldsets = (
(None, {
Expand Down
37 changes: 9 additions & 28 deletions projects/factories.py
Expand Up @@ -6,8 +6,7 @@
from projects.models import (
IAA,
Project,
AgileBPA,
Micropurchase,
Buy,
ContractingOffice,
ContractingSpecialist,
ContractingOfficer,
Expand Down Expand Up @@ -119,48 +118,30 @@ class Meta:
ContractingOfficeFactory
)

procurement_methods = [x[0] for x in Buy.PROCUREMENT_METHOD_CHOICES]
def generate_procurement_method():
return random.choice(procurement_methods)

class AgileBPAFactory(factory.django.DjangoModelFactory):
class BuyFactory(factory.django.DjangoModelFactory):
class Meta:
model = AgileBPA

project = factory.SubFactory(
ProjectFactory,
public=factory.SelfAttribute('..public')
)
description = factory.Faker('paragraph')
name = factory.Faker('catch_phrase')
public = factory.Faker('boolean')

@factory.lazy_attribute
def dollars(self):
min = 500
max = self.project.dollars
return random.randint(min, max)


class AddAgileBPAFactory(AgileBPAFactory):
project = factory.Iterator(Project.objects.all())
model = Buy


class MicropurchaseFactory(factory.django.DjangoModelFactory):
class Meta:
model = Micropurchase

project = factory.SubFactory(
ProjectFactory,
public=factory.SelfAttribute('..public')
)
procurement_method = factory.LazyFunction(generate_procurement_method)
description = factory.Faker('paragraph')
name = factory.Faker('catch_phrase')
public = factory.Faker('boolean')

@factory.lazy_attribute
def dollars(self):
min = 500
max = 3500
max = self.project.dollars
return random.randint(min, max)


class AddMicropurchaseFactory(MicropurchaseFactory):
class AddBuyFactory(BuyFactory):
project = factory.Iterator(Project.objects.all())
14 changes: 3 additions & 11 deletions projects/filters.py
@@ -1,20 +1,12 @@
import django_filters
from projects.models import IAA, Project, AgileBPA, Micropurchase
from projects.models import IAA, Project, Buy


class AgileBPAFilter(django_filters.rest_framework.FilterSet):
class BuyFilter(django_filters.rest_framework.FilterSet):
project_id = django_filters.CharFilter(name="project__id")

class Meta:
model = AgileBPA
fields = ['id', 'name', 'project_id']


class MicropurchaseFilter(django_filters.rest_framework.FilterSet):
project_id = django_filters.CharFilter(name="project__id")

class Meta:
model = Micropurchase
model = Buy
fields = ['id', 'name', 'project_id']


Expand Down
12 changes: 4 additions & 8 deletions projects/management/commands/create_buys.py
@@ -1,10 +1,8 @@
#! /usr/bin/env python3
from django.core.management.base import BaseCommand, CommandError
from projects.factories import (
AgileBPAFactory,
AddAgileBPAFactory,
MicropurchaseFactory,
AddMicropurchaseFactory,
BuyFactory,
AddBuyFactory,
)


Expand All @@ -29,8 +27,6 @@ def handle(self, *args, **options):
number = int(options['number'])

if options['add']:
AddAgileBPAFactory.create_batch(number)
AddMicropurchaseFactory.create_batch(number)
AddBuyFactory.create_batch(number)
else:
AgileBPAFactory.create_batch(number)
MicropurchaseFactory.create_batch(number)
BuyFactory.create_batch(number)
34 changes: 0 additions & 34 deletions projects/migrations/0001_initial.py

This file was deleted.

0 comments on commit 03ce2c7

Please sign in to comment.