Skip to content

Instantly share code, notes, and snippets.

View tonimichel's full-sized avatar

Toni Michel tonimichel

View GitHub Profile
[
{
"name": "root",
"type": "folder",
"children": [
{
"name": "Documents",
"type": "folder",
"children": [
{
# form.html
# Use the crispy tag:
"""
{% crispy_addon form.my_field prepend="$" append=".00" %}
"""
# => docs: http://django-crispy-forms.readthedocs.io/en/latest/api_templatetags.html?highlight=addon
class RedirectMixin(object):
def get_success_url(self):
return reverse('sd_portfolio-portfolios-detail', kwargs=dict(pk=self.object.pk))
class PortfolioCrud(BaseCrudBuilder):
custom_update_view_mixin = RedirectMixin
custom_create_view_mixin = RedirectMixin
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^news/$', views.index),
url(r'^news/(?P<year>[0-9]{4})/$', views.year_archive),
url(r'^news/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', views.month_archive),
url(r'^news/(?P<slug>[-\w]+)/$', views.detail),
]
from django.shortcuts import get_object_or_404, render
from news import models
def detail_view(request, slug):
news_obj = get_object_or_404(models.News, slug=slug)
return render(request, 'news/detail.html', dict(
news_obj=obj
))
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^news/$', views.index),
url(r'^news/([0-9]{4})/$', views.year_archive),
url(r'^news/([0-9]{4})/([0-9]{2})/$', views.month_archive),
url(r'^news/[-\w]+/$', views.detail),
]
from django.test import TestCase as DjangoTestCase
class NoMigrationsTestCase(DjangoTestCase):
"""
Extend your test cases from this class and migrations will be disabled.
"""
def __init__(self, *args, **kw):
from django.conf import settings
settings.MIGRATION_MODULES = DisableMigrations()
import zmq
import sys
import time
# Call start the client like this: python client.py addr1 addr2
# ------------------------------------------------------------------------------
def send(socket, msg, depth=0, max_depth=4, timeout=0.9):
I have a XREQ socket at the client, talking to a set of servers(XREP).
I want to handle server deaths. The client should notice this, as he
does not get an answer for a sent request in an
appropriate time. In this case, the client should resend the message. As
he is connected to more than 1 server,
the request will be accomplished by a server which is still available.
=> I cant use blocking recv at the client, as otherwise the client will
block once he sent a message to a death server
=> instead, the recv must use zmq.NOBLOCK. Each time the client sends a
message, he waits for 2 seconds max for a reply.
class XREQConnect(object):
def __init__(self, server_list):
context = zmq.Context()
self.socket = context.socket(zmq.XREQ)
for addr in server_list:
self.socket.connect(addr)