Skip to content

Commit

Permalink
pep8 cleanup & more todos
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkuty committed Mar 13, 2015
1 parent d9cfc5e commit 434f0aa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* [x] for vanilla horizon usage must be extended DataTableOptions
* [x] support for generic table from model class - construct table from model.fields
* [ ] make generic views for index(PaginatedTable), create(ModalForm), update(ModalForm), delete(BatchAction)
* [ ] implement custom fields and lookups on FilterAction
* [ ] BaseClient and refactor API module
* [ ] TESTS !
* [ ] Pep8 cleanup

## Generic views and Actions

Expand Down
2 changes: 2 additions & 0 deletions horizon_contrib/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

from horizon_contrib.common.content_type import get_class, get_content_type # noqa
9 changes: 5 additions & 4 deletions horizon_contrib/common/content_type.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.contrib.contenttypes.models import ContentType

"""
helper for CT
helper for searching Content Type
"""


def get_class(name):
"""return model class
"""
Expand All @@ -16,7 +17,7 @@ def get_class(name):

if model_class is None:
raise Exception("get class by string: Neznama trida: %s " % name)

return model_class


Expand All @@ -32,5 +33,5 @@ def get_content_type(model_class):

if content_type is None:
raise Exception("Undefined content type %s " % model_class)
return content_type

return content_type
11 changes: 4 additions & 7 deletions horizon_contrib/forms/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import django

from distutils.version import StrictVersion

from horizon import forms as horizon_forms
from horizon import messages
from django import forms as django_forms
from django.conf import settings
from django.db import models

"""
Expand All @@ -15,6 +11,7 @@
https://docs.djangoproject.com/en/1.7/ref/models/querysets/#django.db.models.query.QuerySet.update_or_create
"""


def create_or_update_and_get(model_class, data):

if StrictVersion(django.get_version()) > StrictVersion('1.7'):
Expand All @@ -38,9 +35,9 @@ def create_or_update_and_get(model_class, data):
else:
# create
instance = model_class()

# update (or finish creating)
for key,value in data.items():
for key, value in data.items():
field = model_class._meta.get_field(key)
if not field:
continue
Expand Down
4 changes: 3 additions & 1 deletion horizon_contrib/forms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def get_context_data(self, **kwargs):
context['add_to_field'] = self.request.META[ADD_TO_FIELD_HEADER]
return context


class ModalFormView(ModalFormMixin, generic.FormView):
"""The main view class from which all views which handle forms in Horizon
should inherit. It takes care of all details with processing
Expand Down Expand Up @@ -97,5 +98,6 @@ def form_valid(self, form):
# wrong, and we should send back the form as-is.
return self.form_invalid(form)


class ModelModalView(ModalFormView):
pass
pass

0 comments on commit 434f0aa

Please sign in to comment.