Permalink
Browse files

Removed django.contrib.databrowse.

RIP -- you served us well.
  • Loading branch information...
1 parent 02f3daa commit 052271168bc8f46c64451340d39682d5efdef9b6 @aaugustin aaugustin committed Dec 24, 2012
Showing with 0 additions and 1,120 deletions.
  1. +0 −1 MANIFEST.in
  2. +0 −5 django/contrib/databrowse/__init__.py
  3. +0 −214 django/contrib/databrowse/datastructures.py
  4. +0 −1 django/contrib/databrowse/models.py
  5. 0 django/contrib/databrowse/plugins/__init__.py
  6. +0 −147 django/contrib/databrowse/plugins/calendars.py
  7. +0 −77 django/contrib/databrowse/plugins/fieldchoices.py
  8. +0 −18 django/contrib/databrowse/plugins/objects.py
  9. +0 −147 django/contrib/databrowse/sites.py
  10. +0 −61 django/contrib/databrowse/templates/databrowse/base.html
  11. +0 −1 django/contrib/databrowse/templates/databrowse/base_site.html
  12. +0 −17 django/contrib/databrowse/templates/databrowse/calendar_day.html
  13. +0 −17 django/contrib/databrowse/templates/databrowse/calendar_homepage.html
  14. +0 −17 django/contrib/databrowse/templates/databrowse/calendar_main.html
  15. +0 −17 django/contrib/databrowse/templates/databrowse/calendar_month.html
  16. +0 −17 django/contrib/databrowse/templates/databrowse/calendar_year.html
  17. +0 −17 django/contrib/databrowse/templates/databrowse/choice_detail.html
  18. +0 −17 django/contrib/databrowse/templates/databrowse/choice_list.html
  19. +0 −17 django/contrib/databrowse/templates/databrowse/fieldchoice_detail.html
  20. +0 −17 django/contrib/databrowse/templates/databrowse/fieldchoice_homepage.html
  21. +0 −17 django/contrib/databrowse/templates/databrowse/fieldchoice_list.html
  22. +0 −21 django/contrib/databrowse/templates/databrowse/homepage.html
  23. +0 −19 django/contrib/databrowse/templates/databrowse/model_detail.html
  24. +0 −41 django/contrib/databrowse/templates/databrowse/object_detail.html
  25. +0 −62 django/contrib/databrowse/tests.py
  26. +0 −20 django/contrib/databrowse/urls.py
  27. +0 −19 django/contrib/databrowse/views.py
  28. +0 −1 docs/index.txt
  29. +0 −89 docs/ref/contrib/databrowse.txt
  30. +0 −1 docs/ref/contrib/index.txt
  31. +0 −5 tests/runtests.py
View
@@ -19,7 +19,6 @@ recursive-include django/contrib/auth/fixtures *
recursive-include django/contrib/auth/templates *
recursive-include django/contrib/auth/tests/templates *
recursive-include django/contrib/comments/templates *
-recursive-include django/contrib/databrowse/templates *
recursive-include django/contrib/formtools/templates *
recursive-include django/contrib/formtools/tests/templates *
recursive-include django/contrib/flatpages/fixtures *
@@ -1,5 +0,0 @@
-import warnings
-from django.contrib.databrowse.sites import DatabrowsePlugin, ModelDatabrowse, DatabrowseSite, site
-
-
-warnings.warn("The Databrowse contrib app is deprecated", DeprecationWarning)
@@ -1,214 +0,0 @@
-"""
-These classes are light wrappers around Django's database API that provide
-convenience functionality and permalink functions for the databrowse app.
-"""
-from __future__ import unicode_literals
-
-from django.db import models
-from django.utils import formats
-from django.utils.text import capfirst
-from django.utils.encoding import smart_text, force_str, iri_to_uri
-from django.db.models.query import QuerySet
-from django.utils.encoding import python_2_unicode_compatible
-
-EMPTY_VALUE = '(None)'
-DISPLAY_SIZE = 100
-
-class EasyModel(object):
- def __init__(self, site, model):
- self.site = site
- self.model = model
- self.model_list = list(site.registry.keys())
- self.verbose_name = model._meta.verbose_name
- self.verbose_name_plural = model._meta.verbose_name_plural
-
- def __repr__(self):
- return force_str('<EasyModel for %s>' % self.model._meta.object_name)
-
- def model_databrowse(self):
- "Returns the ModelDatabrowse class for this model."
- return self.site.registry[self.model]
-
- def url(self):
- return '%s%s/%s/' % (self.site.root_url, self.model._meta.app_label, self.model._meta.module_name)
-
- def objects(self, **kwargs):
- return self.get_query_set().filter(**kwargs)
-
- def get_query_set(self):
- easy_qs = self.model._default_manager.get_query_set()._clone(klass=EasyQuerySet)
- easy_qs._easymodel = self
- return easy_qs
-
- def object_by_pk(self, pk):
- return EasyInstance(self, self.model._default_manager.get(pk=pk))
-
- def sample_objects(self):
- for obj in self.model._default_manager.all()[:3]:
- yield EasyInstance(self, obj)
-
- def field(self, name):
- try:
- f = self.model._meta.get_field(name)
- except models.FieldDoesNotExist:
- return None
- return EasyField(self, f)
-
- def fields(self):
- return [EasyField(self, f) for f in (self.model._meta.fields + self.model._meta.many_to_many)]
-
-class EasyField(object):
- def __init__(self, easy_model, field):
- self.model, self.field = easy_model, field
-
- def __repr__(self):
- return force_str('<EasyField for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
-
- def choices(self):
- for value, label in self.field.choices:
- yield EasyChoice(self.model, self, value, label)
-
- def url(self):
- if self.field.choices:
- return '%s%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name)
- elif self.field.rel:
- return '%s%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name)
-
-class EasyChoice(object):
- def __init__(self, easy_model, field, value, label):
- self.model, self.field = easy_model, field
- self.value, self.label = value, label
-
- def __repr__(self):
- return force_str('<EasyChoice for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
-
- def url(self):
- return '%s%s/%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.field.name, iri_to_uri(self.value))
-
-@python_2_unicode_compatible
-class EasyInstance(object):
- def __init__(self, easy_model, instance):
- self.model, self.instance = easy_model, instance
-
- def __repr__(self):
- return force_str('<EasyInstance for %s (%s)>' % (self.model.model._meta.object_name, self.instance._get_pk_val()))
-
- def __str__(self):
- val = smart_text(self.instance)
- if len(val) > DISPLAY_SIZE:
- return val[:DISPLAY_SIZE] + '...'
- return val
-
- def pk(self):
- return self.instance._get_pk_val()
-
- def url(self):
- return '%s%s/%s/objects/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, iri_to_uri(self.pk()))
-
- def fields(self):
- """
- Generator that yields EasyInstanceFields for each field in this
- EasyInstance's model.
- """
- for f in self.model.model._meta.fields + self.model.model._meta.many_to_many:
- yield EasyInstanceField(self.model, self, f)
-
- def related_objects(self):
- """
- Generator that yields dictionaries of all models that have this
- EasyInstance's model as a ForeignKey or ManyToManyField, along with
- lists of related objects.
- """
- for rel_object in self.model.model._meta.get_all_related_objects() + self.model.model._meta.get_all_related_many_to_many_objects():
- if rel_object.model not in self.model.model_list:
- continue # Skip models that aren't in the model_list
- em = EasyModel(self.model.site, rel_object.model)
- yield {
- 'model': em,
- 'related_field': rel_object.field.verbose_name,
- 'object_list': [EasyInstance(em, i) for i in getattr(self.instance, rel_object.get_accessor_name()).all()],
- }
-
-class EasyInstanceField(object):
- def __init__(self, easy_model, instance, field):
- self.model, self.field, self.instance = easy_model, field, instance
- self.raw_value = getattr(instance.instance, field.name)
-
- def __repr__(self):
- return force_str('<EasyInstanceField for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
-
- def values(self):
- """
- Returns a list of values for this field for this instance. It's a list
- so we can accomodate many-to-many fields.
- """
- # This import is deliberately inside the function because it causes
- # some settings to be imported, and we don't want to do that at the
- # module level.
- if self.field.rel:
- if isinstance(self.field.rel, models.ManyToOneRel):
- objs = getattr(self.instance.instance, self.field.name)
- elif isinstance(self.field.rel, models.ManyToManyRel): # ManyToManyRel
- return list(getattr(self.instance.instance, self.field.name).all())
- elif self.field.choices:
- objs = dict(self.field.choices).get(self.raw_value, EMPTY_VALUE)
- elif isinstance(self.field, models.DateField) or isinstance(self.field, models.TimeField):
- if self.raw_value:
- if isinstance(self.field, models.DateTimeField):
- objs = capfirst(formats.date_format(self.raw_value, 'DATETIME_FORMAT'))
- elif isinstance(self.field, models.TimeField):
- objs = capfirst(formats.time_format(self.raw_value, 'TIME_FORMAT'))
- else:
- objs = capfirst(formats.date_format(self.raw_value, 'DATE_FORMAT'))
- else:
- objs = EMPTY_VALUE
- elif isinstance(self.field, models.BooleanField) or isinstance(self.field, models.NullBooleanField):
- objs = {True: 'Yes', False: 'No', None: 'Unknown'}[self.raw_value]
- else:
- objs = self.raw_value
- return [objs]
-
- def urls(self):
- "Returns a list of (value, URL) tuples."
- # First, check the urls() method for each plugin.
- plugin_urls = []
- for plugin_name, plugin in self.model.model_databrowse().plugins.items():
- urls = plugin.urls(plugin_name, self)
- if urls is not None:
- return zip(self.values(), urls)
- if self.field.rel:
- m = EasyModel(self.model.site, self.field.rel.to)
- if self.field.rel.to in self.model.model_list:
- lst = []
- for value in self.values():
- if value is None:
- continue
- url = '%s%s/%s/objects/%s/' % (self.model.site.root_url, m.model._meta.app_label, m.model._meta.module_name, iri_to_uri(value._get_pk_val()))
- lst.append((smart_text(value), url))
- else:
- lst = [(value, None) for value in self.values()]
- elif self.field.choices:
- lst = []
- for value in self.values():
- url = '%s%s/%s/fields/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name, iri_to_uri(self.raw_value))
- lst.append((value, url))
- elif isinstance(self.field, models.URLField):
- val = list(self.values())[0]
- lst = [(val, iri_to_uri(val))]
- else:
- lst = [(list(self.values())[0], None)]
- return lst
-
-class EasyQuerySet(QuerySet):
- """
- When creating (or cloning to) an `EasyQuerySet`, make sure to set the
- `_easymodel` variable to the related `EasyModel`.
- """
- def iterator(self, *args, **kwargs):
- for obj in super(EasyQuerySet, self).iterator(*args, **kwargs):
- yield EasyInstance(self._easymodel, obj)
-
- def _clone(self, *args, **kwargs):
- c = super(EasyQuerySet, self)._clone(*args, **kwargs)
- c._easymodel = self._easymodel
- return c
@@ -1 +0,0 @@
-# Empty models.py to allow for specifying databrowse as a test label.
@@ -1,147 +0,0 @@
-from __future__ import unicode_literals
-
-from django import http
-from django.db import models
-from django.contrib.databrowse.datastructures import EasyModel
-from django.contrib.databrowse.sites import DatabrowsePlugin
-from django.shortcuts import render_to_response
-from django.utils.html import format_html, format_html_join
-from django.utils.text import capfirst
-from django.utils.encoding import force_text
-from django.views.generic import dates
-from django.utils import datetime_safe
-
-
-class DateViewMixin(object):
- allow_empty = False
- allow_future = True
- root_url = None
- model = None
- field = None
-
- def get_context_data(self, **kwargs):
- context = super(DateViewMixin, self).get_context_data(**kwargs)
- context.update({
- 'root_url': self.root_url,
- 'model': self.model,
- 'field': self.field
- })
- return context
-
-
-class DayView(DateViewMixin, dates.DayArchiveView):
- template_name = 'databrowse/calendar_day.html'
-
-
-class MonthView(DateViewMixin, dates.MonthArchiveView):
- template_name = 'databrowse/calendar_month.html'
-
-
-class YearView(DateViewMixin, dates.YearArchiveView):
- template_name = 'databrowse/calendar_year.html'
-
-
-class IndexView(DateViewMixin, dates.ArchiveIndexView):
- template_name = 'databrowse/calendar_main.html'
-
-
-class CalendarPlugin(DatabrowsePlugin):
- def __init__(self, field_names=None):
- self.field_names = field_names
-
- def field_dict(self, model):
- """
- Helper function that returns a dictionary of all DateFields or
- DateTimeFields in the given model. If self.field_names is set, it takes
- take that into account when building the dictionary.
- """
- if self.field_names is None:
- return dict([(f.name, f) for f in model._meta.fields if isinstance(f, models.DateField)])
- else:
- return dict([(f.name, f) for f in model._meta.fields if isinstance(f, models.DateField) and f.name in self.field_names])
-
- def model_index_html(self, request, model, site):
- fields = self.field_dict(model)
- if not fields:
- return ''
- return format_html('<p class="filter"><strong>View calendar by:</strong> {0}</p>',
- format_html_join(', ', '<a href="calendars/{0}/">{1}</a>',
- ((f.name, force_text(capfirst(f.verbose_name))) for f in fields.values())))
-
- def urls(self, plugin_name, easy_instance_field):
- if isinstance(easy_instance_field.field, models.DateField):
- d = easy_instance_field.raw_value
- return ['%s%s/%s/%s/%s/%s/' % (
- easy_instance_field.model.url(),
- plugin_name, easy_instance_field.field.name,
- str(d.year),
- datetime_safe.new_date(d).strftime('%b').lower(),
- d.day)]
-
- def model_view(self, request, model_databrowse, url):
- self.model, self.site = model_databrowse.model, model_databrowse.site
- self.fields = self.field_dict(self.model)
-
- # If the model has no DateFields, there's no point in going further.
- if not self.fields:
- raise http.Http404('The requested model has no calendars.')
-
- if url is None:
- return self.homepage_view(request)
- url_bits = url.split('/')
- if url_bits[0] in self.fields:
- return self.calendar_view(request, self.fields[url_bits[0]], *url_bits[1:])
-
- raise http.Http404('The requested page does not exist.')
-
- def homepage_view(self, request):
- easy_model = EasyModel(self.site, self.model)
- field_list = list(self.fields.values())
- field_list.sort(key=lambda k:k.verbose_name)
- return render_to_response('databrowse/calendar_homepage.html', {
- 'root_url': self.site.root_url,
- 'model': easy_model,
- 'field_list': field_list
- })
-
- def calendar_view(self, request, field, year=None, month=None, day=None):
- easy_model = EasyModel(self.site, self.model)
- root_url = self.site.root_url
-
- if day is not None:
- return DayView.as_view(
- year=year, month=month, day=day,
- date_field=field.name,
- queryset=easy_model.get_query_set(),
- root_url=root_url,
- model=easy_model,
- field=field
- )(request)
- elif month is not None:
- return MonthView.as_view(
- year=year, month=month,
- date_field=field.name,
- queryset=easy_model.get_query_set(),
- root_url=root_url,
- model=easy_model,
- field=field
- )(request)
- elif year is not None:
- return YearView.as_view(
- year=year,
- date_field=field.name,
- queryset=easy_model.get_query_set(),
- root_url=root_url,
- model=easy_model,
- field=field
- )(request)
- else:
- return IndexView.as_view(
- date_field=field.name,
- queryset=easy_model.get_query_set(),
- root_url=root_url,
- model=easy_model,
- field=field
- )(request)
-
- assert False, ('%s, %s, %s, %s' % (field, year, month, day))
Oops, something went wrong.

0 comments on commit 0522711

Please sign in to comment.