This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProjectService(LoginRequiredMixin, SingleObjectMixin, FormView): | |
| template_name = 'buffet/project_detail.html' | |
| model = Project | |
| form_class = ServiceTypeForm | |
| def get_form_kwargs(self): | |
| kwargs = super(ProjectService, self).get_form_kwargs() | |
| kwargs['project'] = self.object | |
| return kwargs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ServiceTypeForm(forms.ModelForm): | |
| class Meta: | |
| model = Service | |
| fields = ['name', 'service_type'] | |
| def __init__(self, *args, **kwargs): | |
| self.project = kwargs.pop('project') | |
| super(ServiceTypeForm, self).__init__(*args, **kwargs) | |
| def save(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ServiceTypeFormTest(TestCase): | |
| def setUp(self): | |
| self.project = Project.objects.create(name='google') | |
| self.service_type = ServiceType.objects.create(name='database', slug='database', template='{{ template }}') | |
| def test_form_save(self): | |
| form = ServiceTypeForm({ | |
| 'name': 'googledb', | |
| 'service_type': self.service_type, | |
| }, project=self.project) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ServiceTypeForm(forms.ModelForm): | |
| class Meta: | |
| model = Service | |
| fields = ['name', 'service_type'] | |
| def __init__(self, *args, **kwargs): | |
| self.project = kwargs.pop('project') | |
| super(ServiceTypeForm, self).__init__(*args, **kwargs) | |
| def save(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ServiceType(object): | |
| def __init__(self, name=None, form=None, template=None, context=None) | |
| self.name = name | |
| self.slug = slugify(self.name) if self.name else None | |
| self.form = form | |
| self.service_template = template | |
| self.context = context | |
| if not self.name and self.form and self.template: | |
| raise CustomError("You must define {}".format(missing_field) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ServiceType(object): | |
| name = None | |
| slug = slugify(name) if name else None | |
| form = None | |
| service_type_template = 'service_type_template' | |
| service_template = 'service_template' | |
| def __str__(self): | |
| return name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Creating test database for alias 'default'... | |
| ........F..... | |
| ====================================================================== | |
| FAIL: test_template (buffet.tests.ServiceTest) | |
| ---------------------------------------------------------------------- | |
| Traceback (most recent call last): | |
| File "/home/ldvp/virt/buffet/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched | |
| return func(*args, **keywargs) | |
| File "/home/ldvp/work/buffet/buffet/tests.py", line 53, in test_template | |
| self.assertEqual(self.service.template(), 'mek some other stuff grapes and %s' % self.service.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ServiceForm(forms.Form): | |
| name = forms.CharField() | |
| class PostgresForm(object): | |
| password = forms.PasswordField(default=generated_password_thing()) | |
| whatever_other_field = forms.ThatField(default=blah) | |
| def validate(self): | |
| #custom validation rules | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.shortcuts import render, redirect | |
| from django.views.generic import View | |
| from .forms import FinderForm | |
| from .api import query_api | |
| # Create your views here. | |
| class IndexView(View): | |
| def get(self, request, *args, **kwargs): | |
| return render(request, 'finder/index.html') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Django settings for politics project. | |
| For more information on this file, see | |
| https://docs.djangoproject.com/en/1.7/topics/settings/ | |
| For the full list of settings and their values, see | |
| https://docs.djangoproject.com/en/1.7/ref/settings/ | |
| """ |