From 52dbd11e047e0c737d2d2a2768b806e0d8d23226 Mon Sep 17 00:00:00 2001 From: Alfredo Aguirre Date: Fri, 11 May 2012 16:47:34 +0100 Subject: [PATCH] Added missing dependencies --- .../lib/python/django_extensions/__init__.py | 13 + .../django_extensions/admin/__init__.py | 147 + .../python/django_extensions/admin/widgets.py | 77 + .../conf/app_template/__init__.py.tmpl | 0 .../conf/app_template/forms.py.tmpl | 3 + .../conf/app_template/models.py.tmpl | 3 + .../conf/app_template/urls.py.tmpl | 3 + .../conf/app_template/views.py.tmpl | 1 + .../management/__init__.py.tmpl | 0 .../management/commands/__init__.py.tmpl | 0 .../management/commands/sample.py.tmpl | 7 + .../conf/jobs_template/jobs/__init__.py.tmpl | 0 .../jobs_template/jobs/daily/__init__.py.tmpl | 0 .../jobs/hourly/__init__.py.tmpl | 0 .../jobs/monthly/__init__.py.tmpl | 0 .../conf/jobs_template/jobs/sample.py.tmpl | 8 + .../jobs/weekly/__init__.py.tmpl | 0 .../jobs/yearly/__init__.py.tmpl | 0 .../python/django_extensions/db/__init__.py | 0 .../django_extensions/db/fields/__init__.py | 280 ++ .../django_extensions/db/fields/encrypted.py | 79 + .../django_extensions/db/fields/json.py | 101 + .../lib/python/django_extensions/db/models.py | 75 + .../python/django_extensions/jobs/__init__.py | 0 .../django_extensions/jobs/daily/__init__.py | 0 .../jobs/daily/cache_cleanup.py | 26 + .../jobs/daily/daily_cleanup.py | 16 + .../django_extensions/jobs/hourly/__init__.py | 0 .../jobs/monthly/__init__.py | 0 .../django_extensions/jobs/weekly/__init__.py | 0 .../django_extensions/jobs/yearly/__init__.py | 0 .../django_extensions/management/__init__.py | 0 .../django_extensions/management/color.py | 16 + .../management/commands/__init__.py | 0 .../management/commands/clean_pyc.py | 42 + .../management/commands/compile_pyc.py | 40 + .../management/commands/create_app.py | 146 + .../management/commands/create_command.py | 80 + .../management/commands/create_jobs.py | 56 + .../management/commands/describe_form.py | 64 + .../management/commands/dumpscript.py | 556 +++ .../management/commands/export_emails.py | 127 + .../management/commands/find_template.py | 26 + .../commands/generate_secret_key.py | 11 + .../management/commands/graph_models.py | 71 + .../management/commands/mail_debug.py | 42 + .../management/commands/notes.py | 39 + .../management/commands/passwd.py | 38 + .../commands/print_user_for_session.py | 47 + .../management/commands/reset_db.py | 174 + .../management/commands/runjob.py | 60 + .../management/commands/runjobs.py | 95 + .../management/commands/runprofileserver.py | 226 ++ .../management/commands/runscript.py | 167 + .../management/commands/runserver_plus.py | 97 + .../management/commands/set_fake_emails.py | 76 + .../management/commands/set_fake_passwords.py | 44 + .../management/commands/shell_plus.py | 151 + .../management/commands/show_templatetags.py | 101 + .../management/commands/show_urls.py | 99 + .../management/commands/sqlcreate.py | 85 + .../management/commands/sqldiff.py | 658 +++ .../management/commands/sync_media_s3.py | 271 ++ .../management/commands/syncdata.py | 220 + .../management/commands/unreferenced_files.py | 47 + .../management/commands/update_permissions.py | 21 + .../django_extensions/management/jobs.py | 175 + .../django_extensions/management/modelviz.py | 359 ++ .../django_extensions/management/signals.py | 11 + .../django_extensions/management/utils.py | 8 + .../css/jquery.autocomplete.css | 43 + .../media/django_extensions/img/indicator.gif | Bin 0 -> 1553 bytes .../django_extensions/js/jquery.ajaxQueue.js | 116 + .../js/jquery.autocomplete.js | 759 ++++ .../js/jquery.bgiframe.min.js | 10 + .../media/django_extensions/js/jquery.js | 3558 +++++++++++++++++ .../lib/python/django_extensions/models.py | 0 .../django_extensions/mongodb/__init__.py | 0 .../mongodb/fields/__init__.py | 239 ++ .../mongodb/fields/encrypted.py | 59 + .../django_extensions/mongodb/fields/json.py | 75 + .../django_extensions/mongodb/models.py | 69 + .../lib/python/django_extensions/settings.py | 7 + .../django_extensions/graph_models/body.html | 34 + .../django_extensions/graph_models/head.html | 15 + .../django_extensions/graph_models/rel.html | 15 + .../django_extensions/graph_models/tail.html | 1 + .../widgets/foreignkey_searchinput.html | 60 + .../templatetags/__init__.py | 0 .../templatetags/highlighting.py | 92 + .../templatetags/syntax_color.py | 97 + .../templatetags/truncate_letters.py | 22 + .../django_extensions/templatetags/widont.py | 61 + .../django_extensions/tests/__init__.py | 16 + .../tests/encrypted_fields.py | 75 + .../django_extensions/tests/json_field.py | 31 + .../python/django_extensions/tests/models.py | 21 + .../tests/test_dumpscript.py | 20 + .../python/django_extensions/tests/urls.py | 0 .../python/django_extensions/tests/utils.py | 51 + .../django_extensions/tests/uuid_field.py | 53 + .../django_extensions/utils/__init__.py | 0 .../django_extensions/utils/dia2django.py | 214 + .../python/django_extensions/utils/text.py | 14 + .../python/django_extensions/utils/uuid.py | 564 +++ vendor-local/src/django-haystack | 1 + vendor-local/src/pyelasticsearch | 1 + 107 files changed, 11778 insertions(+) create mode 100644 vendor-local/lib/python/django_extensions/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/admin/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/admin/widgets.py create mode 100644 vendor-local/lib/python/django_extensions/conf/app_template/__init__.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/app_template/forms.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/app_template/models.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/app_template/urls.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/app_template/views.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/command_template/management/__init__.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/command_template/management/commands/__init__.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/command_template/management/commands/sample.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/jobs_template/jobs/__init__.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/jobs_template/jobs/daily/__init__.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/jobs_template/jobs/hourly/__init__.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/jobs_template/jobs/monthly/__init__.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/jobs_template/jobs/sample.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/jobs_template/jobs/weekly/__init__.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/conf/jobs_template/jobs/yearly/__init__.py.tmpl create mode 100644 vendor-local/lib/python/django_extensions/db/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/db/fields/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/db/fields/encrypted.py create mode 100644 vendor-local/lib/python/django_extensions/db/fields/json.py create mode 100644 vendor-local/lib/python/django_extensions/db/models.py create mode 100644 vendor-local/lib/python/django_extensions/jobs/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/jobs/daily/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/jobs/daily/cache_cleanup.py create mode 100644 vendor-local/lib/python/django_extensions/jobs/daily/daily_cleanup.py create mode 100644 vendor-local/lib/python/django_extensions/jobs/hourly/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/jobs/monthly/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/jobs/weekly/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/jobs/yearly/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/management/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/management/color.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/clean_pyc.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/compile_pyc.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/create_app.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/create_command.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/create_jobs.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/describe_form.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/dumpscript.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/export_emails.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/find_template.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/generate_secret_key.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/graph_models.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/mail_debug.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/notes.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/passwd.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/print_user_for_session.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/reset_db.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/runjob.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/runjobs.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/runprofileserver.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/runscript.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/runserver_plus.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/set_fake_emails.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/set_fake_passwords.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/shell_plus.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/show_templatetags.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/show_urls.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/sqlcreate.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/sqldiff.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/sync_media_s3.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/syncdata.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/unreferenced_files.py create mode 100644 vendor-local/lib/python/django_extensions/management/commands/update_permissions.py create mode 100644 vendor-local/lib/python/django_extensions/management/jobs.py create mode 100644 vendor-local/lib/python/django_extensions/management/modelviz.py create mode 100644 vendor-local/lib/python/django_extensions/management/signals.py create mode 100644 vendor-local/lib/python/django_extensions/management/utils.py create mode 100644 vendor-local/lib/python/django_extensions/media/django_extensions/css/jquery.autocomplete.css create mode 100644 vendor-local/lib/python/django_extensions/media/django_extensions/img/indicator.gif create mode 100644 vendor-local/lib/python/django_extensions/media/django_extensions/js/jquery.ajaxQueue.js create mode 100644 vendor-local/lib/python/django_extensions/media/django_extensions/js/jquery.autocomplete.js create mode 100644 vendor-local/lib/python/django_extensions/media/django_extensions/js/jquery.bgiframe.min.js create mode 100644 vendor-local/lib/python/django_extensions/media/django_extensions/js/jquery.js create mode 100644 vendor-local/lib/python/django_extensions/models.py create mode 100644 vendor-local/lib/python/django_extensions/mongodb/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/mongodb/fields/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/mongodb/fields/encrypted.py create mode 100644 vendor-local/lib/python/django_extensions/mongodb/fields/json.py create mode 100644 vendor-local/lib/python/django_extensions/mongodb/models.py create mode 100644 vendor-local/lib/python/django_extensions/settings.py create mode 100644 vendor-local/lib/python/django_extensions/templates/django_extensions/graph_models/body.html create mode 100644 vendor-local/lib/python/django_extensions/templates/django_extensions/graph_models/head.html create mode 100644 vendor-local/lib/python/django_extensions/templates/django_extensions/graph_models/rel.html create mode 100644 vendor-local/lib/python/django_extensions/templates/django_extensions/graph_models/tail.html create mode 100644 vendor-local/lib/python/django_extensions/templates/django_extensions/widgets/foreignkey_searchinput.html create mode 100644 vendor-local/lib/python/django_extensions/templatetags/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/templatetags/highlighting.py create mode 100644 vendor-local/lib/python/django_extensions/templatetags/syntax_color.py create mode 100644 vendor-local/lib/python/django_extensions/templatetags/truncate_letters.py create mode 100644 vendor-local/lib/python/django_extensions/templatetags/widont.py create mode 100644 vendor-local/lib/python/django_extensions/tests/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/tests/encrypted_fields.py create mode 100644 vendor-local/lib/python/django_extensions/tests/json_field.py create mode 100644 vendor-local/lib/python/django_extensions/tests/models.py create mode 100644 vendor-local/lib/python/django_extensions/tests/test_dumpscript.py create mode 100644 vendor-local/lib/python/django_extensions/tests/urls.py create mode 100644 vendor-local/lib/python/django_extensions/tests/utils.py create mode 100644 vendor-local/lib/python/django_extensions/tests/uuid_field.py create mode 100644 vendor-local/lib/python/django_extensions/utils/__init__.py create mode 100644 vendor-local/lib/python/django_extensions/utils/dia2django.py create mode 100644 vendor-local/lib/python/django_extensions/utils/text.py create mode 100644 vendor-local/lib/python/django_extensions/utils/uuid.py create mode 160000 vendor-local/src/django-haystack create mode 160000 vendor-local/src/pyelasticsearch diff --git a/vendor-local/lib/python/django_extensions/__init__.py b/vendor-local/lib/python/django_extensions/__init__.py new file mode 100644 index 0000000..572acbc --- /dev/null +++ b/vendor-local/lib/python/django_extensions/__init__.py @@ -0,0 +1,13 @@ + +VERSION = (0, 8) + +# Dynamically calculate the version based on VERSION tuple +if len(VERSION) > 2 and VERSION[2] is not None: + if isinstance(VERSION[2], int): + str_version = "%s.%s.%s" % VERSION[:3] + else: + str_version = "%s.%s_%s" % VERSION[:3] +else: + str_version = "%s.%s" % VERSION[:2] + +__version__ = str_version diff --git a/vendor-local/lib/python/django_extensions/admin/__init__.py b/vendor-local/lib/python/django_extensions/admin/__init__.py new file mode 100644 index 0000000..dba47c3 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/admin/__init__.py @@ -0,0 +1,147 @@ +# +# Autocomplete feature for admin panel +# +# Most of the code has been written by Jannis Leidel and was updated a bit +# for django_extensions. +# http://jannisleidel.com/2008/11/autocomplete-form-widget-foreignkey-model-fields/ +# +# to_string_function, Satchmo adaptation and some comments added by emes +# (Michal Salaban) +# + +import operator +from django.http import HttpResponse, HttpResponseNotFound +from django.db import models +from django.db.models.query import QuerySet +from django.utils.encoding import smart_str +from django.utils.translation import ugettext as _ +from django.utils.text import get_text_list +try: + from functools import update_wrapper +except ImportError: + from django.utils.functional import update_wrapper + +from django_extensions.admin.widgets import ForeignKeySearchInput + +from django.conf import settings + +if 'reversion' in settings.INSTALLED_APPS: + from reversion.admin import VersionAdmin as ModelAdmin +else: + from django.contrib.admin import ModelAdmin + + +class ForeignKeyAutocompleteAdmin(ModelAdmin): + """Admin class for models using the autocomplete feature. + + There are two additional fields: + - related_search_fields: defines fields of managed model that + have to be represented by autocomplete input, together with + a list of target model fields that are searched for + input string, e.g.: + + related_search_fields = { + 'author': ('first_name', 'email'), + } + + - related_string_functions: contains optional functions which + take target model instance as only argument and return string + representation. By default __unicode__() method of target + object is used. + """ + + related_search_fields = {} + related_string_functions = {} + + def get_urls(self): + from django.conf.urls.defaults import patterns, url + + def wrap(view): + def wrapper(*args, **kwargs): + return self.admin_site.admin_view(view)(*args, **kwargs) + return update_wrapper(wrapper, view) + + info = self.model._meta.app_label, self.model._meta.module_name + + urlpatterns = patterns('', + url(r'foreignkey_autocomplete/$', + wrap(self.foreignkey_autocomplete), + name='%s_%s_autocomplete' % info), + ) + super(ForeignKeyAutocompleteAdmin, self).get_urls() + return urlpatterns + + def foreignkey_autocomplete(self, request): + """ + Searches in the fields of the given related model and returns the + result as a simple string to be used by the jQuery Autocomplete plugin + """ + query = request.GET.get('q', None) + app_label = request.GET.get('app_label', None) + model_name = request.GET.get('model_name', None) + search_fields = request.GET.get('search_fields', None) + object_pk = request.GET.get('object_pk', None) + try: + to_string_function = self.related_string_functions[model_name] + except KeyError: + to_string_function = lambda x: x.__unicode__() + if search_fields and app_label and model_name and (query or object_pk): + def construct_search(field_name): + # use different lookup methods depending on the notation + if field_name.startswith('^'): + return "%s__istartswith" % field_name[1:] + elif field_name.startswith('='): + return "%s__iexact" % field_name[1:] + elif field_name.startswith('@'): + return "%s__search" % field_name[1:] + else: + return "%s__icontains" % field_name + model = models.get_model(app_label, model_name) + queryset = model._default_manager.all() + data = '' + if query: + for bit in query.split(): + or_queries = [models.Q(**{construct_search( + smart_str(field_name)): smart_str(bit)}) + for field_name in search_fields.split(',')] + other_qs = QuerySet(model) + other_qs.dup_select_related(queryset) + other_qs = other_qs.filter(reduce(operator.or_, or_queries)) + queryset = queryset & other_qs + data = ''.join([u'%s|%s\n' % ( + to_string_function(f), f.pk) for f in queryset]) + elif object_pk: + try: + obj = queryset.get(pk=object_pk) + except: + pass + else: + data = to_string_function(obj) + return HttpResponse(data) + return HttpResponseNotFound() + + def get_help_text(self, field_name, model_name): + searchable_fields = self.related_search_fields.get(field_name, None) + if searchable_fields: + help_kwargs = { + 'model_name': model_name, + 'field_list': get_text_list(searchable_fields, _('and')), + } + return _('Use the left field to do %(model_name)s lookups in the fields %(field_list)s.') % help_kwargs + return '' + + def formfield_for_dbfield(self, db_field, **kwargs): + """ + Overrides the default widget for Foreignkey fields if they are + specified in the related_search_fields class attribute. + """ + if (isinstance(db_field, models.ForeignKey) and + db_field.name in self.related_search_fields): + model_name = db_field.rel.to._meta.object_name + help_text = self.get_help_text(db_field.name, model_name) + if kwargs.get('help_text'): + help_text = u'%s %s' % (kwargs['help_text'], help_text) + kwargs['widget'] = ForeignKeySearchInput(db_field.rel, + self.related_search_fields[db_field.name]) + kwargs['help_text'] = help_text + return super(ForeignKeyAutocompleteAdmin, + self).formfield_for_dbfield(db_field, **kwargs) diff --git a/vendor-local/lib/python/django_extensions/admin/widgets.py b/vendor-local/lib/python/django_extensions/admin/widgets.py new file mode 100644 index 0000000..2ee17e5 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/admin/widgets.py @@ -0,0 +1,77 @@ +from django import forms +from django.conf import settings +from django.utils.safestring import mark_safe +from django.utils.text import truncate_words +from django.template.loader import render_to_string +from django.contrib.admin.widgets import ForeignKeyRawIdWidget + + +class ForeignKeySearchInput(ForeignKeyRawIdWidget): + """ + A Widget for displaying ForeignKeys in an autocomplete search input + instead in a " ] || + + !tags.indexOf("", "" ] || + + tags.match(/^<(thead|tbody|tfoot|colg|cap)/) && + [ 1, "", "
" ] || + + !tags.indexOf("", "" ] || + + // matched above + (!tags.indexOf("", "" ] || + + !tags.indexOf("", "" ] || + + // IE can't serialize and \ No newline at end of file diff --git a/vendor-local/lib/python/django_extensions/templatetags/__init__.py b/vendor-local/lib/python/django_extensions/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vendor-local/lib/python/django_extensions/templatetags/highlighting.py b/vendor-local/lib/python/django_extensions/templatetags/highlighting.py new file mode 100644 index 0000000..6d84504 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/templatetags/highlighting.py @@ -0,0 +1,92 @@ +""" +Similar to syntax_color.py but this is intended more for being able to +copy+paste actual code into your Django templates without needing to +escape or anything crazy. + +http://lobstertech.com/2008/aug/30/django_syntax_highlight_template_tag/ + +Example: + + {% load highlighting %} + + + +

check out this code

+ + {% highlight 'python' 'Excerpt: blah.py' %} + def need_food(self): + print "Love is than &death&" + {% endhighlight %} + +""" + +from pygments import highlight as pyghighlight +from pygments.lexers import get_lexer_by_name, guess_lexer +from pygments.formatters import HtmlFormatter +from django.conf import settings +from django import template +from django.template import Template, Context, Node, Variable +from django.template.defaultfilters import stringfilter +from django.utils.safestring import mark_safe + +register = template.Library() + + +@register.filter +@stringfilter +def parse_template(value): + return mark_safe(Template(value).render(Context())) +parse_template.is_safe = True + + +class CodeNode(Node): + def __init__(self, language, nodelist, name=''): + self.language = Variable(language) + self.nodelist = nodelist + if name: + self.name = Variable(name) + else: + self.name = None + + def render(self, context): + code = self.nodelist.render(context).strip() + lexer = get_lexer_by_name(self.language.resolve(context)) + formatter = HtmlFormatter(linenos=False) + html = "" + if self.name: + name = self.name.resolve(context) + html = '
%s
' % (name) + return html + pyghighlight(code, lexer, formatter) + + +@register.tag +def highlight(parser, token): + """ + Allows you to put a highlighted source code
 block in your code.
+    This takes two arguments, the language and a little explaination message
+    that will be generated before the code.  The second argument is optional.
+
+    Your code will be fed through pygments so you can use any language it
+    supports.
+
+    {% load highlighting %}
+    {% highlight 'python' 'Excerpt: blah.py' %}
+    def need_food(self):
+        print "Love is colder than death"
+    {% endhighlight %}
+    """
+    nodelist = parser.parse(('endhighlight',))
+    parser.delete_first_token()
+    bits = token.split_contents()[1:]
+    if len(bits) < 1:
+        raise TemplateSyntaxError("'highlight' statement requires an argument")
+    return CodeNode(bits[0], nodelist, *bits[1:])
diff --git a/vendor-local/lib/python/django_extensions/templatetags/syntax_color.py b/vendor-local/lib/python/django_extensions/templatetags/syntax_color.py
new file mode 100644
index 0000000..4c4c23d
--- /dev/null
+++ b/vendor-local/lib/python/django_extensions/templatetags/syntax_color.py
@@ -0,0 +1,97 @@
+r"""
+Template filter for rendering a string with syntax highlighting.
+It relies on Pygments to accomplish this.
+
+Some standard usage examples (from within Django templates).
+Coloring a string with the Python lexer:
+
+    {% load syntax_color %}
+    {{ code_string|colorize:"python" }}
+
+You may use any lexer in Pygments. The complete list of which
+can be found [on the Pygments website][1].
+
+[1]: http://pygments.org/docs/lexers/
+
+You may also have Pygments attempt to guess the correct lexer for
+a particular string. However, if may not be able to choose a lexer,
+in which case it will simply return the string unmodified. This is
+less efficient compared to specifying the lexer to use.
+
+    {{ code_string|colorize }}
+
+You may also render the syntax highlighed text with line numbers.
+
+    {% load syntax_color %}
+    {{ some_code|colorize_table:"html+django" }}
+    {{ let_pygments_pick_for_this_code|colorize_table }}
+
+Please note that before you can load the ``syntax_color`` template filters
+you will need to add the ``django_extensions.utils`` application to the
+``INSTALLED_APPS``setting in your project's ``settings.py`` file.
+"""
+
+__author__ = 'Will Larson '
+
+
+from django import template
+from django.template.defaultfilters import stringfilter
+from django.utils.safestring import mark_safe
+from django.core.exceptions import ImproperlyConfigured
+
+try:
+    from pygments import highlight
+    from pygments.formatters import HtmlFormatter
+    from pygments.lexers import get_lexer_by_name, guess_lexer, ClassNotFound
+except ImportError:
+    raise ImproperlyConfigured(
+        "Please install 'pygments' library to use syntax_color.")
+
+register = template.Library()
+
+
+@register.simple_tag
+def pygments_css():
+    return HtmlFormatter().get_style_defs('.highlight')
+
+
+def generate_pygments_css(path=None):
+    if path is None:
+        import os
+        path = os.path.join(os.getcwd(), 'pygments.css')
+    f = open(path, 'w')
+    f.write(pygments_css())
+    f.close()
+
+
+def get_lexer(value, arg):
+    if arg is None:
+        return guess_lexer(value)
+    return get_lexer_by_name(arg)
+
+
+@register.filter(name='colorize')
+@stringfilter
+def colorize(value, arg=None):
+    try:
+        return mark_safe(highlight(value, get_lexer(value, arg), HtmlFormatter()))
+    except ClassNotFound:
+        return value
+
+
+@register.filter(name='colorize_table')
+@stringfilter
+def colorize_table(value, arg=None):
+    try:
+        return mark_safe(highlight(value, get_lexer(value, arg), HtmlFormatter(linenos='table')))
+    except ClassNotFound:
+        return value
+
+
+@register.filter(name='colorize_noclasses')
+@stringfilter
+def colorize_noclasses(value, arg=None):
+    try:
+        return mark_safe(highlight(value, get_lexer(value, arg), HtmlFormatter(noclasses=True)))
+    except ClassNotFound:
+        return value
diff --git a/vendor-local/lib/python/django_extensions/templatetags/truncate_letters.py b/vendor-local/lib/python/django_extensions/templatetags/truncate_letters.py
new file mode 100644
index 0000000..0490a71
--- /dev/null
+++ b/vendor-local/lib/python/django_extensions/templatetags/truncate_letters.py
@@ -0,0 +1,22 @@
+from django import template
+from django.template.defaultfilters import stringfilter
+
+register = template.Library()
+
+
+def truncateletters(value, arg):
+    """
+    Truncates a string after a certain number of letters
+
+    Argument: Number of letters to truncate after
+    """
+    from django_extensions.utils.text import truncate_letters
+    try:
+        length = int(arg)
+    except ValueError:  # invalid literal for int()
+        return value  # Fail silently
+    return truncate_letters(value, length)
+
+truncateletters.is_safe = True
+truncateletters = stringfilter(truncateletters)
+register.filter(truncateletters)
diff --git a/vendor-local/lib/python/django_extensions/templatetags/widont.py b/vendor-local/lib/python/django_extensions/templatetags/widont.py
new file mode 100644
index 0000000..084e3e1
--- /dev/null
+++ b/vendor-local/lib/python/django_extensions/templatetags/widont.py
@@ -0,0 +1,61 @@
+from django.template import Library
+from django.utils.encoding import force_unicode
+import re
+
+register = Library()
+re_widont = re.compile(r'\s+(\S+\s*)$')
+re_widont_html = re.compile(r'([^<>\s])\s+([^<>\s]+\s*)(]*>|$)', re.IGNORECASE)
+
+
+def widont(value, count=1):
+    """
+    Adds an HTML non-breaking space between the final two words of the string to
+    avoid "widowed" words.
+
+    Examples:
+
+    >>> print widont('Test   me   out')
+    Test   me out
+
+    >>> widont('It works with trailing spaces too  ')
+    u'It works with trailing spaces too  '
+
+    >>> print widont('NoEffect')
+    NoEffect
+    """
+    def replace(matchobj):
+        return u' %s' % matchobj.group(1)
+    for i in range(count):
+        value = re_widont.sub(replace, force_unicode(value))
+    return value
+
+
+def widont_html(value):
+    """
+    Adds an HTML non-breaking space between the final two words at the end of
+    (and in sentences just outside of) block level tags to avoid "widowed"
+    words.
+
+    Examples:
+
+    >>> print widont_html('

Here is a simple example

Single

') +

Here is a simple example

Single

+ + >>> print widont_html('

test me
out

Ok?

Not in a p

and this

') +

test me
out

Ok?

Not in a p

and this

+ + >>> print widont_html('leading text

test me out

trailing text') + leading text

test me out

trailing text + """ + def replace(matchobj): + return u'%s %s%s' % matchobj.groups() + return re_widont_html.sub(replace, force_unicode(value)) + +register.filter(widont) +register.filter(widont_html) + +if __name__ == "__main__": + def _test(): + import doctest + doctest.testmod() + _test() diff --git a/vendor-local/lib/python/django_extensions/tests/__init__.py b/vendor-local/lib/python/django_extensions/tests/__init__.py new file mode 100644 index 0000000..e5beb14 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/tests/__init__.py @@ -0,0 +1,16 @@ +from django.db import models +from django_extensions.tests.test_dumpscript import DumpScriptTests +from django_extensions.tests.utils import UTILS_TRUNCATE_LETTERS_TESTS +from django_extensions.tests.utils import UTILS_UUID_TESTS +from django_extensions.tests.json_field import JsonFieldTest +from django_extensions.tests.uuid_field import UUIDFieldTest +try: + from django_extensions.tests.encrypted_fields import EncryptedFieldsTestCase + from django_extensions.tests.models import Secret +except ImportError: + pass + +__test__ = { + 'UTILS_TRUNCATE_LETTERS_TESTS': UTILS_TRUNCATE_LETTERS_TESTS, + 'UTILS_UUID_TESTS': UTILS_UUID_TESTS, +} diff --git a/vendor-local/lib/python/django_extensions/tests/encrypted_fields.py b/vendor-local/lib/python/django_extensions/tests/encrypted_fields.py new file mode 100644 index 0000000..c744289 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/tests/encrypted_fields.py @@ -0,0 +1,75 @@ +import unittest + + +from django.db import connection +from django.conf import settings +from django.core.management import call_command +from django.db.models import loading + +# Only perform encrypted fields tests if keyczar is present +# Resolves http://github.com/django-extensions/django-extensions/issues/#issue/17 +try: + from keyczar import keyczar + from django_extensions.tests.models import Secret + from django_extensions.db.fields.encrypted import EncryptedTextField, EncryptedCharField + keyczar_active = True +except ImportError: + keyczar_active = False + + +class EncryptedFieldsTestCase(unittest.TestCase): + + def __init__(self, *args, **kwargs): + if keyczar_active: + self.crypt = keyczar.Crypter.Read(settings.ENCRYPTED_FIELD_KEYS_DIR) + super(EncryptedFieldsTestCase, self).__init__(*args, **kwargs) + + def setUp(self): + self.old_installed_apps = settings.INSTALLED_APPS + settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + settings.INSTALLED_APPS.append('django_extensions.tests') + loading.cache.loaded = False + call_command('syncdb', verbosity=0) + + def tearDown(self): + settings.INSTALLED_APPS = self.old_installed_apps + + def testCharFieldCreate(self): + if not keyczar_active: + return + test_val = "Test Secret" + secret = Secret.objects.create(name=test_val) + cursor = connection.cursor() + query = "SELECT name FROM %s WHERE id = %d" % (Secret._meta.db_table, secret.id) + cursor.execute(query) + db_val, = cursor.fetchone() + decrypted_val = self.crypt.Decrypt(db_val[len(EncryptedCharField.prefix):]) + self.assertEqual(test_val, decrypted_val) + + def testCharFieldRead(self): + if not keyczar_active: + return + test_val = "Test Secret" + secret = Secret.objects.create(name=test_val) + retrieved_secret = Secret.objects.get(id=secret.id) + self.assertEqual(test_val, retrieved_secret.name) + + def testTextFieldCreate(self): + if not keyczar_active: + return + test_val = "Test Secret" + secret = Secret.objects.create(text=test_val) + cursor = connection.cursor() + query = "SELECT text FROM %s WHERE id = %d" % (Secret._meta.db_table, secret.id) + cursor.execute(query) + db_val, = cursor.fetchone() + decrypted_val = self.crypt.Decrypt(db_val[len(EncryptedCharField.prefix):]) + self.assertEqual(test_val, decrypted_val) + + def testTextFieldRead(self): + if not keyczar_active: + return + test_val = "Test Secret" + secret = Secret.objects.create(text=test_val) + retrieved_secret = Secret.objects.get(id=secret.id) + self.assertEqual(test_val, retrieved_secret.text) diff --git a/vendor-local/lib/python/django_extensions/tests/json_field.py b/vendor-local/lib/python/django_extensions/tests/json_field.py new file mode 100644 index 0000000..0dc6b11 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/tests/json_field.py @@ -0,0 +1,31 @@ +import unittest + + +from django.db import connection +from django.conf import settings +from django.core.management import call_command +from django.db.models import loading +from django.db import models +from django_extensions.db.fields.json import JSONField + + +class TestModel(models.Model): + a = models.IntegerField() + j_field = JSONField() + +class JsonFieldTest(unittest.TestCase): + + def setUp(self): + self.old_installed_apps = settings.INSTALLED_APPS + settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + settings.INSTALLED_APPS.append('django_extensions.tests') + loading.cache.loaded = False + call_command('syncdb', verbosity=0) + + def tearDown(self): + settings.INSTALLED_APPS = self.old_installed_apps + + def testCharFieldCreate(self): + + j = TestModel.objects.create(a=6, j_field=dict(foo='bar')) + diff --git a/vendor-local/lib/python/django_extensions/tests/models.py b/vendor-local/lib/python/django_extensions/tests/models.py new file mode 100644 index 0000000..fadb7f3 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/tests/models.py @@ -0,0 +1,21 @@ +from django.db import models + +try: + from django_extensions.db.fields.encrypted import EncryptedTextField, EncryptedCharField +except ImportError: + class EncryptedCharField(object): + def __init__(self, **kwargs): + pass + + class EncryptedTextField(object): + def __init__(self, **kwargs): + pass + + +class Secret(models.Model): + name = EncryptedCharField(blank=True, max_length=255) + text = EncryptedTextField(blank=True) + +class Name(models.Model): + name = models.CharField(max_length=50) + diff --git a/vendor-local/lib/python/django_extensions/tests/test_dumpscript.py b/vendor-local/lib/python/django_extensions/tests/test_dumpscript.py new file mode 100644 index 0000000..5bdad80 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/tests/test_dumpscript.py @@ -0,0 +1,20 @@ +import sys +from StringIO import StringIO +from django.test import TestCase +from django.core.management import call_command +from django_extensions.tests.models import Name + +class DumpScriptTests(TestCase): + def setUp(self): + self.real_stdout = sys.stdout + sys.stdout = StringIO() + + def tearDown(self): + sys.stdout = self.real_stdout + + def test_runs(self): + # lame test...does it run? + n = Name(name='Gabriel') + n.save() + call_command('dumpscript', 'tests') + self.assertTrue('Gabriel' in sys.stdout.getvalue()) diff --git a/vendor-local/lib/python/django_extensions/tests/urls.py b/vendor-local/lib/python/django_extensions/tests/urls.py new file mode 100644 index 0000000..e69de29 diff --git a/vendor-local/lib/python/django_extensions/tests/utils.py b/vendor-local/lib/python/django_extensions/tests/utils.py new file mode 100644 index 0000000..738aa00 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/tests/utils.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +UTILS_TRUNCATE_LETTERS_TESTS = """ +>>> from django_extensions.utils.text import truncate_letters +>>> truncate_letters("hello tests", 100) +u'hello tests' +>>> truncate_letters("hello tests", 5) +u'hello...' +>>> for i in range(10,-1,-1): truncate_letters("hello tests", i),i +(u'hello test...', 10) +(u'hello tes...', 9) +(u'hello te...', 8) +(u'hello t...', 7) +(u'hello ...', 6) +(u'hello...', 5) +(u'hell...', 4) +(u'hel...', 3) +(u'he...', 2) +(u'h...', 1) +(u'...', 0) +>>> truncate_letters("峠 (とうげ tōge - mountain pass)", 10) +u'\u5ce0 (\u3068\u3046\u3052 t\u014dg...' + +""" + +UTILS_UUID_TESTS = """ +>>> from django_extensions.utils import uuid + +# make a UUID using an MD5 hash of a namespace UUID and a name +>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org') +UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e') + +# make a UUID using a SHA-1 hash of a namespace UUID and a name +>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org') +UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d') + +# make a UUID from a string of hex digits (braces and hyphens ignored) +>>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}') + +# convert a UUID to a string of hex digits in standard form +>>> str(x) +'00010203-0405-0607-0809-0a0b0c0d0e0f' + +# get the raw 16 bytes of the UUID +>>> x.bytes +'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f' + +# make a UUID from a 16-byte string +>>> uuid.UUID(bytes=x.bytes) +UUID('00010203-0405-0607-0809-0a0b0c0d0e0f') +""" diff --git a/vendor-local/lib/python/django_extensions/tests/uuid_field.py b/vendor-local/lib/python/django_extensions/tests/uuid_field.py new file mode 100644 index 0000000..1e9fa29 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/tests/uuid_field.py @@ -0,0 +1,53 @@ +import unittest + + +from django.db import connection +from django.conf import settings +from django.core.management import call_command +from django.db.models import loading +from django.db import models +from django_extensions.db.fields import UUIDField + + +class TestModel_field(models.Model): + a = models.IntegerField() + uuid_field = UUIDField() + +class TestModel_pk(models.Model): + uuid_field = UUIDField(primary_key=True) + +class TestAgregateModel(TestModel_pk): + a = models.IntegerField() + +class TestManyToManyModel(TestModel_pk): + many = models.ManyToManyField(TestModel_field) + +class UUIDFieldTest(unittest.TestCase): + + def setUp(self): + self.old_installed_apps = settings.INSTALLED_APPS + settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + settings.INSTALLED_APPS.append('django_extensions.tests') + loading.cache.loaded = False + call_command('syncdb', verbosity=0) + + def tearDown(self): + settings.INSTALLED_APPS = self.old_installed_apps + + def testUUIDFieldCreate(self): + j = TestModel_field.objects.create(a=6, uuid_field=u'550e8400-e29b-41d4-a716-446655440000') + self.assertEquals(j.uuid_field, u'550e8400-e29b-41d4-a716-446655440000') + + def testUUIDField_pkCreate(self): + j = TestModel_pk.objects.create(uuid_field=u'550e8400-e29b-41d4-a716-446655440000') + self.assertEquals(j.uuid_field, u'550e8400-e29b-41d4-a716-446655440000') + self.assertEquals(j.pk, u'550e8400-e29b-41d4-a716-446655440000') + + def testUUIDField_pkAgregateCreate(self): + j = TestAgregateModel.objects.create(a=6) + + def testUUIDFieldManyToManyCreate(self): + j = TestManyToManyModel.objects.create(uuid_field=u'550e8400-e29b-41d4-a716-446655440010') + self.assertEquals(j.uuid_field, u'550e8400-e29b-41d4-a716-446655440010') + self.assertEquals(j.pk, u'550e8400-e29b-41d4-a716-446655440010') + diff --git a/vendor-local/lib/python/django_extensions/utils/__init__.py b/vendor-local/lib/python/django_extensions/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/vendor-local/lib/python/django_extensions/utils/dia2django.py b/vendor-local/lib/python/django_extensions/utils/dia2django.py new file mode 100644 index 0000000..0d42e69 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/utils/dia2django.py @@ -0,0 +1,214 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +##Author Igor Támara igor@tamarapatino.org +##Use this little program as you wish, if you +#include it in your work, let others know you +#are using it preserving this note, you have +#the right to make derivative works, Use it +#at your own risk. +#Tested to work on(etch testing 13-08-2007): +# Python 2.4.4 (#2, Jul 17 2007, 11:56:54) +# [GCC 4.1.3 20070629 (prerelease) (Debian 4.1.2-13)] on linux2 + +dependclasses = ["User", "Group", "Permission", "Message"] + +import codecs +import sys +import gzip +from xml.dom.minidom import * +import re + +#Type dictionary translation types SQL -> Django +tsd = { + "text": "TextField", + "date": "DateField", + "varchar": "CharField", + "int": "IntegerField", + "float": "FloatField", + "serial": "AutoField", + "boolean": "BooleanField", + "numeric": "FloatField", + "timestamp": "DateTimeField", + "bigint": "IntegerField", + "datetime": "DateTimeField", + "date": "DateField", + "time": "TimeField", + "bool": "BooleanField", + "int": "IntegerField", +} + +#convert varchar -> CharField +v2c = re.compile('varchar\((\d+)\)') + + +def index(fks, id): + """Looks for the id on fks, fks is an array of arrays, each array has on [1] + the id of the class in a dia diagram. When not present returns None, else + it returns the position of the class with id on fks""" + for i, j in fks.items(): + if fks[i][1] == id: + return i + return None + + +def addparentstofks(rels, fks): + """Gets a list of relations, between parents and sons and a dict of + clases named in dia, and modifies the fks to add the parent as fk to get + order on the output of classes and replaces the base class of the son, to + put the class parent name. + """ + for j in rels: + son = index(fks, j[1]) + parent = index(fks, j[0]) + fks[son][2] = fks[son][2].replace("models.Model", parent) + if parent not in fks[son][0]: + fks[son][0].append(parent) + + +def dia2django(archivo): + models_txt = '' + f = codecs.open(archivo, "rb") + #dia files are gzipped + data = gzip.GzipFile(fileobj=f).read() + ppal = parseString(data) + #diagram -> layer -> object -> UML - Class -> name, (attribs : composite -> name,type) + datos = ppal.getElementsByTagName("dia:diagram")[0].getElementsByTagName("dia:layer")[0].getElementsByTagName("dia:object") + clases = {} + herit = [] + imports = u"" + for i in datos: + #Look for the classes + if i.getAttribute("type") == "UML - Class": + myid = i.getAttribute("id") + for j in i.childNodes: + if j.nodeType == Node.ELEMENT_NODE and j.hasAttributes(): + if j.getAttribute("name") == "name": + actclas = j.getElementsByTagName("dia:string")[0].childNodes[0].data[1:-1] + myname = "\nclass %s(models.Model) :\n" % actclas + clases[actclas] = [[], myid, myname, 0] + if j.getAttribute("name") == "attributes": + for l in j.getElementsByTagName("dia:composite"): + if l.getAttribute("type") == "umlattribute": + #Look for the attribute name and type + for k in l.getElementsByTagName("dia:attribute"): + if k.getAttribute("name") == "name": + nc = k.getElementsByTagName("dia:string")[0].childNodes[0].data[1:-1] + elif k.getAttribute("name") == "type": + tc = k.getElementsByTagName("dia:string")[0].childNodes[0].data[1:-1] + elif k.getAttribute("name") == "value": + val = k.getElementsByTagName("dia:string")[0].childNodes[0].data[1:-1] + if val == '##': + val = '' + elif k.getAttribute("name") == "visibility" and k.getElementsByTagName("dia:enum")[0].getAttribute("val") == "2": + if tc.replace(" ", "").lower().startswith("manytomanyfield("): + #If we find a class not in our model that is marked as being to another model + newc = tc.replace(" ", "")[16:-1] + if dependclasses.count(newc) == 0: + dependclasses.append(newc) + if tc.replace(" ", "").lower().startswith("foreignkey("): + #If we find a class not in our model that is marked as being to another model + newc = tc.replace(" ", "")[11:-1] + if dependclasses.count(newc) == 0: + dependclasses.append(newc) + + #Mapping SQL types to Django + varch = v2c.search(tc) + if tc.replace(" ", "").startswith("ManyToManyField("): + myfor = tc.replace(" ", "")[16:-1] + if actclas == myfor: + #In case of a recursive type, we use 'self' + tc = tc.replace(myfor, "'self'") + elif clases[actclas][0].count(myfor) == 0: + #Adding related class + if myfor not in dependclasses: + #In case we are using Auth classes or external via protected dia visibility + clases[actclas][0].append(myfor) + tc = "models." + tc + if len(val) > 0: + tc = tc.replace(")", "," + val + ")") + elif tc.find("Field") != -1: + if tc.count("()") > 0 and len(val) > 0: + tc = "models.%s" % tc.replace(")", "," + val + ")") + else: + tc = "models.%s(%s)" % (tc, val) + elif tc.replace(" ", "").startswith("ForeignKey("): + myfor = tc.replace(" ", "")[11:-1] + if actclas == myfor: + #In case of a recursive type, we use 'self' + tc = tc.replace(myfor, "'self'") + elif clases[actclas][0].count(myfor) == 0: + #Adding foreign classes + if myfor not in dependclasses: + #In case we are using Auth classes + clases[actclas][0].append(myfor) + tc = "models." + tc + if len(val) > 0: + tc = tc.replace(")", "," + val + ")") + elif varch == None: + tc = "models." + tsd[tc.strip().lower()] + "(" + val + ")" + else: + tc = "models.CharField(max_length=" + varch.group(1) + ")" + if len(val) > 0: + tc = tc.replace(")", ", " + val + " )") + if not (nc == "id" and tc == "AutoField()"): + clases[actclas][2] = clases[actclas][2] + (" %s = %s\n" % (nc, tc)) + elif i.getAttribute("type") == "UML - Generalization": + mycons = ['A', 'A'] + a = i.getElementsByTagName("dia:connection") + for j in a: + if len(j.getAttribute("to")): + mycons[int(j.getAttribute("handle"))] = j.getAttribute("to") + print mycons + if not 'A' in mycons: + herit.append(mycons) + elif i.getAttribute("type") == "UML - SmallPackage": + a = i.getElementsByTagName("dia:string") + for j in a: + if len(j.childNodes[0].data[1:-1]): + imports += u"from %s.models import *" % j.childNodes[0].data[1:-1] + + addparentstofks(herit, clases) + #Ordering the appearance of classes + #First we make a list of the classes each classs is related to. + ordered = [] + for j, k in clases.iteritems(): + k[2] = k[2] + "\n def __unicode__(self):\n return u\"\"\n" + for fk in k[0]: + if fk not in dependclasses: + clases[fk][3] += 1 + ordered.append([j] + k) + + i = 0 + while i < len(ordered): + mark = i + j = i + 1 + while j < len(ordered): + if ordered[i][0] in ordered[j][1]: + mark = j + j += 1 + if mark == i: + i += 1 + else: + # swap %s in %s" % ( ordered[i] , ordered[mark]) to make ordered[i] to be at the end + if ordered[i][0] in ordered[mark][1] and ordered[mark][0] in ordered[i][1]: + #Resolving simplistic circular ForeignKeys + print "Not able to resolve circular ForeignKeys between %s and %s" % (ordered[i][1], ordered[mark][0]) + break + a = ordered[i] + ordered[i] = ordered[mark] + ordered[mark] = a + if i == len(ordered) - 1: + break + ordered.reverse() + if imports: + models_txt = str(imports) + for i in ordered: + models_txt += '%s\n' % str(i[3]) + + return models_txt + +if __name__ == '__main__': + if len(sys.argv) == 2: + dia2django(sys.argv[1]) + else: + print " Use:\n \n " + sys.argv[0] + " diagram.dia\n\n" diff --git a/vendor-local/lib/python/django_extensions/utils/text.py b/vendor-local/lib/python/django_extensions/utils/text.py new file mode 100644 index 0000000..639a324 --- /dev/null +++ b/vendor-local/lib/python/django_extensions/utils/text.py @@ -0,0 +1,14 @@ +from django.utils.encoding import force_unicode +from django.utils.functional import allow_lazy + + +def truncate_letters(s, num): + """ truncates a string to a number of letters, similar to truncate_words """ + s = force_unicode(s) + length = int(num) + if len(s) > length: + s = s[:length] + if not s.endswith('...'): + s += '...' + return s +truncate_letters = allow_lazy(truncate_letters, unicode) diff --git a/vendor-local/lib/python/django_extensions/utils/uuid.py b/vendor-local/lib/python/django_extensions/utils/uuid.py new file mode 100644 index 0000000..cd0421f --- /dev/null +++ b/vendor-local/lib/python/django_extensions/utils/uuid.py @@ -0,0 +1,564 @@ +r"""UUID objects (universally unique identifiers) according to RFC 4122. + +This module provides immutable UUID objects (class UUID) and the functions +uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5 +UUIDs as specified in RFC 4122. + +If all you want is a unique ID, you should probably call uuid1() or uuid4(). +Note that uuid1() may compromise privacy since it creates a UUID containing +the computer's network address. uuid4() creates a random UUID. + +Typical usage: + + >>> import uuid + + # make a UUID based on the host ID and current time + >>> uuid.uuid1() + UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') + + # make a UUID using an MD5 hash of a namespace UUID and a name + >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org') + UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e') + + # make a random UUID + >>> uuid.uuid4() + UUID('16fd2706-8baf-433b-82eb-8c7fada847da') + + # make a UUID using a SHA-1 hash of a namespace UUID and a name + >>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org') + UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d') + + # make a UUID from a string of hex digits (braces and hyphens ignored) + >>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}') + + # convert a UUID to a string of hex digits in standard form + >>> str(x) + '00010203-0405-0607-0809-0a0b0c0d0e0f' + + # get the raw 16 bytes of the UUID + >>> x.bytes + '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f' + + # make a UUID from a 16-byte string + >>> uuid.UUID(bytes=x.bytes) + UUID('00010203-0405-0607-0809-0a0b0c0d0e0f') +""" + +__author__ = 'Ka-Ping Yee ' + +RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE = [ + 'reserved for NCS compatibility', 'specified in RFC 4122', + 'reserved for Microsoft compatibility', 'reserved for future definition' +] + + +class UUID(object): + """Instances of the UUID class represent UUIDs as specified in RFC 4122. + UUID objects are immutable, hashable, and usable as dictionary keys. + Converting a UUID to a string with str() yields something in the form + '12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts + five possible forms: a similar string of hexadecimal digits, or a tuple + of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and + 48-bit values respectively) as an argument named 'fields', or a string + of 16 bytes (with all the integer fields in big-endian order) as an + argument named 'bytes', or a string of 16 bytes (with the first three + fields in little-endian order) as an argument named 'bytes_le', or a + single 128-bit integer as an argument named 'int'. + + UUIDs have these read-only attributes: + + bytes the UUID as a 16-byte string (containing the six + integer fields in big-endian byte order) + + bytes_le the UUID as a 16-byte string (with time_low, time_mid, + and time_hi_version in little-endian byte order) + + fields a tuple of the six integer fields of the UUID, + which are also available as six individual attributes + and two derived attributes: + + time_low the first 32 bits of the UUID + time_mid the next 16 bits of the UUID + time_hi_version the next 16 bits of the UUID + clock_seq_hi_variant the next 8 bits of the UUID + clock_seq_low the next 8 bits of the UUID + node the last 48 bits of the UUID + + time the 60-bit timestamp + clock_seq the 14-bit sequence number + + hex the UUID as a 32-character hexadecimal string + + int the UUID as a 128-bit integer + + urn the UUID as a URN as specified in RFC 4122 + + variant the UUID variant (one of the constants RESERVED_NCS, + RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE) + + version the UUID version number (1 through 5, meaningful only + when the variant is RFC_4122) + """ + + def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None, + int=None, version=None): + r"""Create a UUID from either a string of 32 hexadecimal digits, + a string of 16 bytes as the 'bytes' argument, a string of 16 bytes + in little-endian order as the 'bytes_le' argument, a tuple of six + integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version, + 8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as + the 'fields' argument, or a single 128-bit integer as the 'int' + argument. When a string of hex digits is given, curly braces, + hyphens, and a URN prefix are all optional. For example, these + expressions all yield the same UUID: + + UUID('{12345678-1234-5678-1234-567812345678}') + UUID('12345678123456781234567812345678') + UUID('urn:uuid:12345678-1234-5678-1234-567812345678') + UUID(bytes='\x12\x34\x56\x78'*4) + UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' + + '\x12\x34\x56\x78\x12\x34\x56\x78') + UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678)) + UUID(int=0x12345678123456781234567812345678) + + Exactly one of 'hex', 'bytes', 'bytes_le', 'fields', or 'int' must + be given. The 'version' argument is optional; if given, the resulting + UUID will have its variant and version set according to RFC 4122, + overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'. + """ + + if [hex, bytes, bytes_le, fields, int].count(None) != 4: + raise TypeError('need one of hex, bytes, bytes_le, fields, or int') + if hex is not None: + hex = hex.replace('urn:', '').replace('uuid:', '') + hex = hex.strip('{}').replace('-', '') + if len(hex) != 32: + raise ValueError('badly formed hexadecimal UUID string') + int = long(hex, 16) + if bytes_le is not None: + if len(bytes_le) != 16: + raise ValueError('bytes_le is not a 16-char string') + bytes = (bytes_le[3] + bytes_le[2] + bytes_le[1] + bytes_le[0] + + bytes_le[5] + bytes_le[4] + bytes_le[7] + bytes_le[6] + + bytes_le[8:]) + if bytes is not None: + if len(bytes) != 16: + raise ValueError('bytes is not a 16-char string') + int = long(('%02x' * 16) % tuple(map(ord, bytes)), 16) + if fields is not None: + if len(fields) != 6: + raise ValueError('fields is not a 6-tuple') + (time_low, time_mid, time_hi_version, + clock_seq_hi_variant, clock_seq_low, node) = fields + if not 0 <= time_low < 1 << 32L: + raise ValueError('field 1 out of range (need a 32-bit value)') + if not 0 <= time_mid < 1 << 16L: + raise ValueError('field 2 out of range (need a 16-bit value)') + if not 0 <= time_hi_version < 1 << 16L: + raise ValueError('field 3 out of range (need a 16-bit value)') + if not 0 <= clock_seq_hi_variant < 1 << 8L: + raise ValueError('field 4 out of range (need an 8-bit value)') + if not 0 <= clock_seq_low < 1 << 8L: + raise ValueError('field 5 out of range (need an 8-bit value)') + if not 0 <= node < 1 << 48L: + raise ValueError('field 6 out of range (need a 48-bit value)') + clock_seq = (clock_seq_hi_variant << 8L) | clock_seq_low + int = ((time_low << 96L) | (time_mid << 80L) | + (time_hi_version << 64L) | (clock_seq << 48L) | node) + if int is not None: + if not 0 <= int < 1 << 128L: + raise ValueError('int is out of range (need a 128-bit value)') + if version is not None: + if not 1 <= version <= 5: + raise ValueError('illegal version number') + # Set the variant to RFC 4122. + int &= ~(0xc000 << 48L) + int |= 0x8000 << 48L + # Set the version number. + int &= ~(0xf000 << 64L) + int |= version << 76L + self.__dict__['int'] = int + + def __cmp__(self, other): + if isinstance(other, UUID): + return cmp(self.int, other.int) + return NotImplemented + + def __hash__(self): + return hash(self.int) + + def __int__(self): + return self.int + + def __repr__(self): + return 'UUID(%r)' % str(self) + + def __setattr__(self, name, value): + raise TypeError('UUID objects are immutable') + + def __str__(self): + hex = '%032x' % self.int + return '%s-%s-%s-%s-%s' % ( + hex[:8], hex[8:12], hex[12:16], hex[16:20], hex[20:]) + + def get_bytes(self): + bytes = '' + for shift in range(0, 128, 8): + bytes = chr((self.int >> shift) & 0xff) + bytes + return bytes + + bytes = property(get_bytes) + + def get_bytes_le(self): + bytes = self.bytes + return (bytes[3] + bytes[2] + bytes[1] + bytes[0] + + bytes[5] + bytes[4] + bytes[7] + bytes[6] + bytes[8:]) + + bytes_le = property(get_bytes_le) + + def get_fields(self): + return (self.time_low, self.time_mid, self.time_hi_version, + self.clock_seq_hi_variant, self.clock_seq_low, self.node) + + fields = property(get_fields) + + def get_time_low(self): + return self.int >> 96L + + time_low = property(get_time_low) + + def get_time_mid(self): + return (self.int >> 80L) & 0xffff + + time_mid = property(get_time_mid) + + def get_time_hi_version(self): + return (self.int >> 64L) & 0xffff + + time_hi_version = property(get_time_hi_version) + + def get_clock_seq_hi_variant(self): + return (self.int >> 56L) & 0xff + + clock_seq_hi_variant = property(get_clock_seq_hi_variant) + + def get_clock_seq_low(self): + return (self.int >> 48L) & 0xff + + clock_seq_low = property(get_clock_seq_low) + + def get_time(self): + return (((self.time_hi_version & 0x0fffL) << 48L) | + (self.time_mid << 32L) | self.time_low) + + time = property(get_time) + + def get_clock_seq(self): + return (((self.clock_seq_hi_variant & 0x3fL) << 8L) | + self.clock_seq_low) + + clock_seq = property(get_clock_seq) + + def get_node(self): + return self.int & 0xffffffffffff + + node = property(get_node) + + def get_hex(self): + return '%032x' % self.int + + hex = property(get_hex) + + def get_urn(self): + return 'urn:uuid:' + str(self) + + urn = property(get_urn) + + def get_variant(self): + if not self.int & (0x8000 << 48L): + return RESERVED_NCS + elif not self.int & (0x4000 << 48L): + return RFC_4122 + elif not self.int & (0x2000 << 48L): + return RESERVED_MICROSOFT + else: + return RESERVED_FUTURE + + variant = property(get_variant) + + def get_version(self): + # The version bits are only meaningful for RFC 4122 UUIDs. + if self.variant == RFC_4122: + return int((self.int >> 76L) & 0xf) + + version = property(get_version) + + +def _find_mac(command, args, hw_identifiers, get_index): + import os + for dir in ['', '/sbin/', '/usr/sbin']: + executable = os.path.join(dir, command) + if not os.path.exists(executable): + continue + + try: + # LC_ALL to get English output, 2>/dev/null to + # prevent output on stderr + cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args) + pipe = os.popen(cmd) + except IOError: + continue + + for line in pipe: + words = line.lower().split() + for i in range(len(words)): + if words[i] in hw_identifiers: + return int(words[get_index(i)].replace(':', ''), 16) + return None + + +def _ifconfig_getnode(): + """Get the hardware address on Unix by running ifconfig.""" + + # This works on Linux ('' or '-a'), Tru64 ('-av'), but not all Unixes. + for args in ('', '-a', '-av'): + mac = _find_mac('ifconfig', args, ['hwaddr', 'ether'], lambda i: i + 1) + if mac: + return mac + + import socket + ip_addr = socket.gethostbyname(socket.gethostname()) + + # Try getting the MAC addr from arp based on our IP address (Solaris). + mac = _find_mac('arp', '-an', [ip_addr], lambda i: -1) + if mac: + return mac + + # This might work on HP-UX. + mac = _find_mac('lanscan', '-ai', ['lan0'], lambda i: 0) + if mac: + return mac + + return None + + +def _ipconfig_getnode(): + """Get the hardware address on Windows by running ipconfig.exe.""" + import os + import re + dirs = ['', r'c:\windows\system32', r'c:\winnt\system32'] + try: + import ctypes + buffer = ctypes.create_string_buffer(300) + ctypes.windll.kernel32.GetSystemDirectoryA(buffer, 300) + dirs.insert(0, buffer.value.decode('mbcs')) + except: + pass + for dir in dirs: + try: + pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all') + except IOError: + continue + for line in pipe: + value = line.split(':')[-1].strip().lower() + if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value): + return int(value.replace('-', ''), 16) + + +def _netbios_getnode(): + """Get the hardware address on Windows using NetBIOS calls. + See http://support.microsoft.com/kb/118623 for details.""" + import win32wnet + import netbios + ncb = netbios.NCB() + ncb.Command = netbios.NCBENUM + ncb.Buffer = adapters = netbios.LANA_ENUM() + adapters._pack() + if win32wnet.Netbios(ncb) != 0: + return + adapters._unpack() + for i in range(adapters.length): + ncb.Reset() + ncb.Command = netbios.NCBRESET + ncb.Lana_num = ord(adapters.lana[i]) + if win32wnet.Netbios(ncb) != 0: + continue + ncb.Reset() + ncb.Command = netbios.NCBASTAT + ncb.Lana_num = ord(adapters.lana[i]) + ncb.Callname = '*'.ljust(16) + ncb.Buffer = status = netbios.ADAPTER_STATUS() + if win32wnet.Netbios(ncb) != 0: + continue + status._unpack() + bytes = map(ord, status.adapter_address) + return ((bytes[0] << 40L) + (bytes[1] << 32L) + (bytes[2] << 24L) + + (bytes[3] << 16L) + (bytes[4] << 8L) + bytes[5]) + +# Thanks to Thomas Heller for ctypes and for his help with its use here. + +# If ctypes is available, use it to find system routines for UUID generation. +_uuid_generate_random = _uuid_generate_time = _UuidCreate = None +try: + import ctypes + import ctypes.util + _buffer = ctypes.create_string_buffer(16) + + # The uuid_generate_* routines are provided by libuuid on at least + # Linux and FreeBSD, and provided by libc on Mac OS X. + for libname in ['uuid', 'c']: + try: + lib = ctypes.CDLL(ctypes.util.find_library(libname)) + except: + continue + if hasattr(lib, 'uuid_generate_random'): + _uuid_generate_random = lib.uuid_generate_random + if hasattr(lib, 'uuid_generate_time'): + _uuid_generate_time = lib.uuid_generate_time + + # On Windows prior to 2000, UuidCreate gives a UUID containing the + # hardware address. On Windows 2000 and later, UuidCreate makes a + # random UUID and UuidCreateSequential gives a UUID containing the + # hardware address. These routines are provided by the RPC runtime. + # NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last + # 6 bytes returned by UuidCreateSequential are fixed, they don't appear + # to bear any relationship to the MAC address of any network device + # on the box. + try: + lib = ctypes.windll.rpcrt4 + except: + lib = None + _UuidCreate = getattr(lib, 'UuidCreateSequential', + getattr(lib, 'UuidCreate', None)) +except: + pass + + +def _unixdll_getnode(): + """Get the hardware address on Unix using ctypes.""" + _uuid_generate_time(_buffer) + return UUID(bytes=_buffer.raw).node + + +def _windll_getnode(): + """Get the hardware address on Windows using ctypes.""" + if _UuidCreate(_buffer) == 0: + return UUID(bytes=_buffer.raw).node + + +def _random_getnode(): + """Get a random node ID, with eighth bit set as suggested by RFC 4122.""" + import random + return random.randrange(0, 1 << 48L) | 0x010000000000L + +_node = None + + +def getnode(): + """Get the hardware address as a 48-bit positive integer. + + The first time this runs, it may launch a separate program, which could + be quite slow. If all attempts to obtain the hardware address fail, we + choose a random 48-bit number with its eighth bit set to 1 as recommended + in RFC 4122. + """ + + global _node + if _node is not None: + return _node + + import sys + if sys.platform == 'win32': + getters = [_windll_getnode, _netbios_getnode, _ipconfig_getnode] + else: + getters = [_unixdll_getnode, _ifconfig_getnode] + + for getter in getters + [_random_getnode]: + try: + _node = getter() + except: + continue + if _node is not None: + return _node + +_last_timestamp = None + + +def uuid1(node=None, clock_seq=None): + """Generate a UUID from a host ID, sequence number, and the current time. + If 'node' is not given, getnode() is used to obtain the hardware + address. If 'clock_seq' is given, it is used as the sequence number; + otherwise a random 14-bit sequence number is chosen.""" + + # When the system provides a version-1 UUID generator, use it (but don't + # use UuidCreate here because its UUIDs don't conform to RFC 4122). + if _uuid_generate_time and node is clock_seq is None: + _uuid_generate_time(_buffer) + return UUID(bytes=_buffer.raw) + + global _last_timestamp + import time + nanoseconds = int(time.time() * 1e9) + # 0x01b21dd213814000 is the number of 100-ns intervals between the + # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00. + timestamp = int(nanoseconds / 100) + 0x01b21dd213814000L + if timestamp <= _last_timestamp: + timestamp = _last_timestamp + 1 + _last_timestamp = timestamp + if clock_seq is None: + import random + clock_seq = random.randrange(1 << 14L) # instead of stable storage + time_low = timestamp & 0xffffffffL + time_mid = (timestamp >> 32L) & 0xffffL + time_hi_version = (timestamp >> 48L) & 0x0fffL + clock_seq_low = clock_seq & 0xffL + clock_seq_hi_variant = (clock_seq >> 8L) & 0x3fL + if node is None: + node = getnode() + return UUID(fields=(time_low, time_mid, time_hi_version, + clock_seq_hi_variant, clock_seq_low, node), version=1) + + +def uuid3(namespace, name): + """Generate a UUID from the MD5 hash of a namespace UUID and a name.""" + try: + from hashlib import md5 + except ImportError: + from md5 import md5 + hash = md5(namespace.bytes + name).digest() + return UUID(bytes=hash[:16], version=3) + + +def uuid4(): + """Generate a random UUID.""" + + # When the system provides a version-4 UUID generator, use it. + if _uuid_generate_random: + _uuid_generate_random(_buffer) + return UUID(bytes=_buffer.raw) + + # Otherwise, get randomness from urandom or the 'random' module. + try: + import os + return UUID(bytes=os.urandom(16), version=4) + except: + import random + bytes = [chr(random.randrange(256)) for i in range(16)] + return UUID(bytes=bytes, version=4) + + +def uuid5(namespace, name): + """Generate a UUID from the SHA-1 hash of a namespace UUID and a name.""" + try: + from hashlib import sha1 as sha + except ImportError: + from sha import sha + hash = sha(namespace.bytes + name).digest() + return UUID(bytes=hash[:16], version=5) + +# The following standard UUIDs are for use with uuid3() or uuid5(). + +NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8') +NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8') +NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8') +NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8') diff --git a/vendor-local/src/django-haystack b/vendor-local/src/django-haystack new file mode 160000 index 0000000..ec1f917 --- /dev/null +++ b/vendor-local/src/django-haystack @@ -0,0 +1 @@ +Subproject commit ec1f917588b3be1ce89f077a6c3c72be1551f84d diff --git a/vendor-local/src/pyelasticsearch b/vendor-local/src/pyelasticsearch new file mode 160000 index 0000000..bf72826 --- /dev/null +++ b/vendor-local/src/pyelasticsearch @@ -0,0 +1 @@ +Subproject commit bf72826a3fc768f3fe0238b42f33c4fb450c6261