Sumar dias habiles / Working days
Dada una fecha_origen, incrementa N dias a partir de esa fecha ignorando sábados y domingos. Increments a date by n days without counting weekends. Just working days.
- date
- python
- dias_habiles
- working_days
Dada una fecha_origen, incrementa N dias a partir de esa fecha ignorando sábados y domingos. Increments a date by n days without counting weekends. Just working days.
Python's [descriptor][1] protocol can seem a bit esoteric at first; however, it can be invaluable in handling everyday idioms and patterns - something that the Django framework authors have taken advantage of in numerous occasions (e.g.: [auth middleware][2]). One such idiom I see and use often and would like to generalize is the attribute-existence check-or-set routine illustrated here: def get_foo(self): if not hasattr(self, '_foo'): self._foo = init_foo() return self._foo Rather than coding this up multiple times (either for a given class or across many unrelated classes), I would prefer to delegate this repetitive work to a descriptor and remain [DRY][3]. The means to this end is implemented as a variation on the Python `property` construct, and is intentionally over simplistic (I leave the details of the heavy lifting up to the reader). The basic premise shown in source here is simply straight-forward Python, a quick and dirty example of how it could be utilized within a Django context is shown here: from django.db import models from cacheprop import CacheProperty2 ARTIFACT_TYPES = ( ('F', _('File')), ('D', _('Directory')), ('A', _('Alias')), ) class Artifact(models.Model): # model fields name = models.CharField(maxlength=64) type = models.CharField(maxlength=1, choices=ARTIFACT_TYPES) file_metadata = CacheProperty2( lambda self: self.filemetadata_set.get(artifact__id=self.id) ) class FileMetadata(models.Model): byte_size = models.IntegerField() artifact = models.ForeignKey(Artifact, unique=True) [1]: http://users.rcn.com/python/download/Descriptor.htm [2]: http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/middleware.py [3]: http://c2.com/cgi/wiki?DontRepeatYourself
[ToofPy](http://pyds.muensterland.org/wiki/toolserver.html) is a python server that supports WSGI so you can integrate Django with it via the WSGI handler. There is already some default Django integration in the source, but it looked really hacked up with many `if hasdjango:` lines all over the place and hardcoded URLs. A really simple solution is to create a Tool for wrapping around Django. That is what the above file does. So I removed most of the hardcoded django lines and created the tool above. ToofPy dynamically loads tools based on paths on the filesystem, so you'll need to put the file above in the WSGI folder path. Or, if you want to pre-integrate, import the file in the _initops function of WSGIMainTool just after the code to scan the directory.
I tend to have all my python code together in a 'python' directory. e.g. a typical project layout of mine looks like: /python /python/myproject - project python code /python/django - local copy of django /python/foolib - some third party library /media /templates ... Since I don't want to set the python path explicitly I just assume the 'manage.py' is in the right place and use its __file__ variable to set up the python path correctly. I use the same trick for my settings.py for setting MEDIA_ROOT and TEMPLATE_DIRS.
Simple contact form, using a javascript form checker which you can use any you want to you can just modify the form in the way you want to. The form checker I use I include in the 'base.html' page before the </head> section end. You can use it freely. http://media.xorl.de/form.js . A lot of this code is comprised of other peoples forms that didn't suit the simple purpose of a *really* basic contact form which I wanted, so I rebuilt it up from bits and pieces to make a simple basic form.
This is a general-purpose utility function, but since it uses lazy sequences via itertools, so it should be suitable for use with Querysets.
Template filter to convert integer or long integer into roman numeral with support for upper and lower case numerals. Requires python-roman package on Debian which apparently comes from http://www.diveintopython.org/
A short little bit of code to test for comment spam against Akimet. Use: a = Akismet('<AkismetKey>', 'http://sneeu.com/blog/') a.verify_key() print a.comment_check( comment_author='...', comment_author_email='[email protected]', user_ip='10.0.0.1', comment_content="""Comment content!""" )
This very simple middleware will set the 'user' attribute of a mod_python request.. this way the username is logged into the apache log ... useful when making webalizer statistics to see the activity of users .. (http://sct.sphene.net)
54 snippets posted so far.