Django

Code

Changeset 2339

Show
Ignore:
Timestamp:
02/18/06 14:24:24 (3 years ago)
Author:
adrian
Message:

magic-removal: Merged to [2338]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/db/models/fields/__init__.py

    r2335 r2339  
    141141    def get_db_prep_lookup(self, lookup_type, value): 
    142142        "Returns field's value prepared for database lookup." 
    143         if lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte', 'ne', 'month', 'day'): 
     143        if lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte', 'ne', 'year', 'month', 'day'): 
    144144            return [value] 
    145145        elif lookup_type in ('range', 'in'): 
    146146            return value 
    147         elif lookup_type == 'year': 
    148             return ['%s-01-01' % value, '%s-12-31' % value] 
    149147        elif lookup_type in ('contains', 'icontains'): 
    150148            return ["%%%s%%" % prep_for_like_query(value)] 
  • django/branches/magic-removal/django/db/models/query.py

    r2314 r2339  
    517517    if lookup_type == 'in': 
    518518        return '%s%s IN (%s)' % (table_prefix, field_name, ','.join(['%s' for v in value])) 
    519     elif lookup_type in ('range', 'year')
     519    elif lookup_type == 'range'
    520520        return '%s%s BETWEEN %%s AND %%s' % (table_prefix, field_name) 
    521     elif lookup_type in ('month', 'day'): 
     521    elif lookup_type in ('year', 'month', 'day'): 
    522522        return "%s = %%s" % backend.get_date_extract_sql(lookup_type, table_prefix + field_name) 
    523523    elif lookup_type == 'isnull': 
  • django/branches/magic-removal/django/views/generic/date_based.py

    r2324 r2339  
    4444 
    4545def archive_year(request, year, queryset, date_field, template_name=None, 
    46         template_loader=loader, extra_context={}, context_processors=None): 
     46        template_loader=loader, extra_context={}, allow_empty=False, 
     47        context_processors=None): 
    4748    """ 
    4849    Generic yearly archive view. 
     
    6263        lookup_kwargs['%s__lte' % date_field] = now 
    6364    date_list = queryset.filter(**lookup_kwargs).dates(date_field, 'month') 
    64     if not date_list
     65    if not date_list and not allow_empty
    6566        raise Http404 
    6667    if not template_name: 
     
    8081def archive_month(request, year, month, queryset, date_field, 
    8182        month_format='%b', template_name=None, template_loader=loader, 
    82         extra_context={}, context_processors=None): 
     83        extra_context={}, allow_empty=False, context_processors=None): 
    8384    """ 
    8485    Generic monthly archive view. 
     
    113114        lookup_kwargs['%s__lte' % date_field] = now 
    114115    object_list = queryset.filter(**lookup_kwargs) 
    115     if not object_list
     116    if not object_list and not allow_empty
    116117        raise Http404 
    117118    if not template_name: 
  • django/branches/magic-removal/docs/cache.txt

    r1904 r2339  
    66 
    77Django's cache framework gives you three methods of caching dynamic pages in 
    8 memory or in a database. You can cache the output of entire pages, you can 
     8memory or in a database. You can cache the output of specific views, you can 
    99cache only the pieces that are difficult to produce, or you can cache your 
    1010entire site. 
     
    123123.. _`middleware documentation`: http://www.djangoproject.com/documentation/middleware/ 
    124124 
    125 The per-page cache 
     125The per-view cache 
    126126================== 
    127127 
     
    153153Sometimes, however, caching an entire rendered page doesn't gain you very much. 
    154154For example, you may find it's only necessary to cache the result of an 
    155 intensive database. In cases like this, you can use the low-level cache API to 
    156 store objects in the cache with any level of granularity you like. 
     155intensive database query. In cases like this, you can use the low-level cache 
     156API to store objects in the cache with any level of granularity you like. 
    157157 
    158158The cache API is simple:: 
  • django/branches/magic-removal/docs/generic_views.txt

    r2324 r2339  
    167167    pattern. 
    168168 
     169    Takes an optional ``allow_empty`` parameter, as ``archive_index``. 
     170 
    169171    Uses the template ``<app_label>/<model_name>_archive_year`` by default. 
    170172 
     
    185187    default, which is a three-letter month abbreviation. To change it to use 
    186188    numbers, use ``"%m"``. 
     189 
     190    Takes an optional ``allow_empty`` parameter, as ``archive_index``. 
    187191 
    188192    Uses the template ``<app_label>/<model_name>_archive_month`` by default. 
  • django/branches/magic-removal/docs/outputting_pdf.txt

    r1916 r2339  
    1111pieces of content. 
    1212 
    13 For example, Django was used at kusports.com to generate customized, 
     13For example, Django was used at kusports.com_ to generate customized, 
    1414printer-friendly NCAA tournament brackets, as PDF files, for people 
    1515participating in a March Madness contest. 
    1616 
    1717.. _ReportLab: http://www.reportlab.org/rl_toolkit.html 
     18.. _kusports.com: http://www.kusports.com/ 
    1819 
    1920Install ReportLab 
     
    8081      dialogue, etc. 
    8182 
     83    * The ``Content-Disposition`` header starts with ``'attachment; '`` in this 
     84      example. This forces Web browsers to pop-up a dialog box 
     85      prompting/confirming how to handle the document even if a default is set 
     86      on the machine. If you leave off ``'attachment;'``, browsers will handle 
     87      the PDF using whatever program/plugin they've been configured to use for 
     88      PDFs. Here's what that code would look like:: 
     89 
     90          response['Content-Disposition'] = 'filename=somefilename.pdf' 
     91 
    8292    * Hooking into the ReportLab API is easy: Just pass ``response`` as the 
    8393      first argument to ``canvas.Canvas``. The ``Canvas`` class expects a 
     
    8999    * Finally, it's important to call ``showPage()`` and ``save()`` on the PDF 
    90100      file. 
     101 
     102Complex PDFs 
     103============ 
     104 
     105If you're creating a complex PDF document with ReportLab, consider using the 
     106cStringIO_ library as a temporary holding place for your PDF file. The 
     107cStringIO library provides a file-like object interface that is particularly 
     108efficient. Here's the above "Hello World" example rewritten to use 
     109``cStringIO``:: 
     110 
     111    from cStringIO import StringIO 
     112    from reportlab.pdfgen import canvas 
     113    from django.utils.httpwrappers import HttpResponse 
     114 
     115    def some_view(request): 
     116        # Create the HttpResponse object with the appropriate PDF headers. 
     117        response = HttpResponse(mimetype='application/pdf') 
     118        response['Content-Disposition'] = 'attachment; filename=somefilename.pdf' 
     119 
     120        buffer = String() 
     121 
     122        # Create the PDF object, using the StringIO object as its "file." 
     123        p = canvas.Canvas(buffer) 
     124 
     125        # Draw things on the PDF. Here's where the PDF generation happens. 
     126        # See the ReportLab documentation for the full list of functionality. 
     127        p.drawString(100, 100, "Hello world.") 
     128 
     129        # Close the PDF object cleanly. 
     130        p.showPage() 
     131        p.save() 
     132 
     133        # Get the value of the StringIO buffer and write it to the response. 
     134        pdf = buffer.getvalue() 
     135        buffer.close() 
     136        response.write(pdf) 
     137        return response 
     138 
     139.. _cStringIO: http://www.python.org/doc/current/lib/module-cStringIO.html 
     140 
     141Further resources 
     142================= 
     143 
     144    * PDFlib_ is another PDF-generation library that has Python bindings. To 
     145      use it with Django, just use the same concepts explained in this article. 
     146    * HTMLdoc_ is a command-line script that can convert HTML to PDF. It 
     147      doesn't have a Python interface, but you can escape out to the shell 
     148      using ``system`` or ``popen`` and retrieve the output in Python. 
     149    * `forge_fdf in Python`_ is a library that fills in PDF forms. 
     150 
     151.. _PDFlib: http://www.pdflib.org/ 
     152.. _HTMLdoc: http://www.htmldoc.org/ 
     153.. _forge_fdf in Python: http://www.accesspdf.com/article.php/20050421092951834 
  • django/branches/magic-removal/tests/runtests.py

    r2313 r2339  
    242242    from optparse import OptionParser 
    243243    usage = "%prog [options] [model model model ...]" 
    244     parser = OptionParser(
     244    parser = OptionParser(usage=usage
    245245    parser.add_option('-v', help='How verbose should the output be? Choices are 0, 1 and 2, where 2 is most verbose. Default is 0.', 
    246246        type='choice', choices=['0', '1', '2'])