Login

Snippets by teepark

Snippet List

DiggBarMiddleware

give diggbar users something to think about (http://daringfireball.net/2009/04/how_to_block_the_diggbar)

  • middleware
Read More

general-purpose django XMLRC dispatcher

create an instance of this class: `rpcserver = XMLRPC()` then define handlers on it with the register decorator: @rpcserver.register("pingback.ping") def handle_pingback(sourceURI, targetURI) # ... de-serialization of the arguments and serialization of the return values is handled by the XMLRPC object, so just expect python built-in types as your arguments and use them as your return values. you can also raise instances of xmlrpclib.Fault from within your handlers and a proper xmlrpc fault will be sent out as the response. then you can use `rpcserver.view` in your urlconf to offer up your XML-RPC service at a URL: urlpatterns = patterns('', url(r'^$', rpcserver.view, name="xmlrpc"), # ... )

  • xmlrpc
Read More

server with debugging backdoor

this starts up two servers - HTTP serving the django application on port 8000 and a port 8001 server that will start an interactive interpreter with any incoming connections. this enables you to have an interpreter in the same process as your server. $ wget http://localhost:8000/someurl/ (...) $ nc localhost 8001 Python 2.5.2 (r252:60911, Jul 8 2008, 21:21:10) [GCC 4.3.1 20080626 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from django.db import connection >>> connection.queries [ ... ]

  • debugging
Read More

common model privacy

A BooleanField indicating privacy is common on models, but the name of the field and whether the field being True indicates private or public both may change across models. If there is more than one potentially private model, a common interface is needed. A commonly-named method would do the job with `[a for a in MyModel.objects.all() if not a.is_private()]`, but it would still retrieve private instances from the database only to filter them out. This approach puts the name of the privacy field and whether that field being True indicates private or public in a tuple attribute of the model class. A chainable method is added to all QuerySet objects. example use: class MyModel(models.Model): is_public = models.BooleanField(default=True) # ... privacy_field = ("is_public", False) \>\>\> publicMyModels = MyModel.objects.all().exclude_private() \>\>\> values = publicMyModels.values()

  • models
  • querysets
Read More

teepark has posted 4 snippets.