Toggle navigation
Christopher A. Kreid & Associates, LLC
About CK&A
Practice Areas
Commercial
Construction
Corporate
Labor & Employment
Transportation
Environmental
Real Results
Attorney Profiles
Contact Us
Christopher Kreid & Associates Trial + Counsel
Who We Are
Learn More
What We Do
Learn More
Where We Are
Learn More
Construction
Commercial
Employment
Environmental
Transportation


Summer 2016 Road Trip - June
Home
June
July
August
List of places I traveled in June
Portland, Maine
Baxter State Park, Maine:
Recommended
Acadia National Park, Maine:
Recommended
Burlington, Vermont
Buffalo, New York
Cleveland, Ohio
Ann Arbor, Michigan
Minneapolis, Minnesota
Banff, Alberta, Canada:
Recommended
Highlights
Baxter State Park, Maine
To learn more click here:
Baxter State Park
Banff National Park, Alberta, Canada
To learn more click here:
Banff National Park


Cover Style
Intro 101 Guide
Open
Rehabbing for Monster Paydays
Open
Virtual Wholesaling 3.0
Open
Rehabbing for Monster Paydays
Add to Cart - $7
Virtual Wholesaling 3.0
Add to Cart - $7
Button Style
Open
Open
Open
Open
Add to Cart - $47
Add to Cart - $47
Add to Cart - $47
Add to Cart - $47
Add to Cart - $47
Add to Cart - $47
Icon Style


Components
django-unicorn
uses the term "component" to refer to a set of interactive functionality that can be put into templates. A component consists of a Django HTML template with specific tags and a Python class which provides the backend code for the template.
The easiest way to create your first component is to run the following Django management command after django-unicorn
is installed.
python manage.py startunicorn hello-world
If this is the first component you create, you will also need to add "unicorn",
to INSTALLED_APPS
in your Django settings file (normally settings.py) to make sure that Django can find the component templates you create.
{% unicorn 'hello-world' %}
into the template you want to load the new component.
{% endverbatim %}
A basic example component could consist of the following template and class.
# hello_world.py
from django_unicorn.components import UnicornView
class HelloWorldView(UnicornView):
name = "World"
{% verbatim %}

<input unicorn:model="name" type="text" id="text">
Hello {{ name|title }}

{% endverbatim %}
unicorn:model
is the magic that ties the input to the backend component. The Django template variable can use any property or method on the component as if they were context variables passed in from a view. The attribute passed into unicorn:model
refers to the property in the component class and binds them together.
By default unicorn:model
updates are triggered by listening to input
events on the element. To listen for the blur
event instead, use the lazy modifier.
When a user types into the text input, the information is passed to the backend and populates the component class, which is then used to generate the output of the template HTML. The template can use any normal Django templatetags or filters (e.g. the title
filter above).
Supported property types
Properties of the component can be of many different types, including str
, int
, list
, dictionary
, Django Model
, Django QuerySet
, or custom classes
.
Dictionary and Django Models
Dictionaries
and Django models
can be used similary by unicorn:model
.
# hello_world.py
from django_unicorn.components import UnicornView
from book.models import Book
class HelloWorldView(UnicornView):
book = Book.objects.get(title='American Gods')
book_ratings = {'excellent': {'title: 'American Gods'}}

<input unicorn:model="book.title" type="text" id="model">
<input unicorn:model="book_ratings.excellent.title" type="text" id="dictionary">

Django QuerySet
Django QuerySet
can be referenced similary to the Django template language in a unicorn:model
.
# hello_world.py
from django_unicorn.components import UnicornView
from book.models import Book
class HelloWorldView(UnicornView):
books = Book.objects.all()

<input unicorn:model="books.0.title" type="text" id="text">

Custom class
Custom classes need to define how they are serialized. If you have access to the object to serialize, you can define a to_json
method on the object to return a dictionary that can be used to serialize. Inheriting from unicorn.components.UnicornField
is a quick way to serialize a custom class, but note that it just calls self.__dict__
under the hood, so it is not doing anything smart. from_json
would need to be defined to deserialize the dictionary back into the actual class.
Another option is to set the form_class
on the component and utilize Django's built-in forms and widgets to handle how the class should be deserialized. More details are provided in the validation section.
# hello_world.py
from django_unicorn.components import UnicornView, UnicornField
class Author(UnicornField):
def __init(self):
self.name = 'Neil Gaiman'
# Not needed because inherited from `UnicornField`
# def to_json(self):
# return {'name': self.name}
class HelloWorldView(UnicornView):
author = Author()

<input unicorn:model="author.name" type="text" id="author_name">

Never put sensitive data into a public property because that information will publicly available in the HTML source code.


MA-SIB free spots checker
Get the source on GitHub
Sample Sequances
Optimal - 2 Snakes on Dim 4
Optimal - 1 Snake on Dim 7
NonOptimal - 2 Snakes
3 Snakes Dim 6 Example
Hypercube dimentions:
Intra-Snake spread:
Inter-Snake spread (box):
Sequences (internal separated by [- or ,], external separated by |):
I.E: |0-1-3|422-486-230| for two snakes.
Decimal
Binary
Calculate!
Calculate empty locations & basic validation of snakes - i.e. Dimentions & intra-snake hamming distance is 1
Snakes Locations: {{snakeSpot.length}}
[{{spot}}]
IntraSnake Free Spots: {{intraSnakeFreeSpot.length}}
[{{spot}}]
InterSnake Free Spots: {{interSnakeFreeSpot.length}}
[{{spot}}]