Changeset 552
- Timestamp:
- 02/15/10 15:00:16 (5 months ago)
- Location:
- trunk/telemeta
- Files:
-
- 7 modified
-
htdocs/css/telemeta.css (modified) (1 diff)
-
models/core.py (modified) (5 diffs)
-
models/location.py (modified) (1 diff)
-
models/query.py (modified) (2 diffs)
-
templates/telemeta_default/search_criteria.html (modified) (5 diffs)
-
templates/telemeta_default/search_results.html (modified) (1 diff)
-
web/base.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/telemeta/htdocs/css/telemeta.css
r550 r552 291 291 } 292 292 293 #searchform select.tiny { 294 width: 12%; 295 } 296 293 297 /* Navigation (borrowed from Trac) */ 294 298 .nav h2, .nav hr { display: none } -
trunk/telemeta/models/core.py
r538 r552 108 108 return self._delta.days * 24 * 3600 + self._delta.seconds 109 109 110 def normalize_field(args, default_value ):110 def normalize_field(args, default_value=None): 111 111 """Normalize field constructor arguments, so that the field is marked blank=True 112 112 and has a default value by default. … … 127 127 if args.get('null'): 128 128 args['default'] = None 129 el se:129 elif default_value is not None: 130 130 args['default'] = default_value 131 131 … … 294 294 295 295 class DateTimeField(models.DateTimeField): 296 """DateTimeField normalized with normalize_field()""" 297 298 def __init__(self, *args, **kwargs): 299 super(DateTimeField, self).__init__(*args, **normalize_field(kwargs, '0000-00-00 00:00')) 300 301 def get_db_prep_value(self, value): 302 if value is None and not self.null: 303 return '0000-00-00 00:00' 304 305 return super(DateTimeField, self).get_db_prep_value(value) 296 """DateTimeField normalized with normalize_field(). This field is allowed to 297 be null by default unless null=False is passed""" 298 299 def __init__(self, *args, **kwargs): 300 if not kwargs.has_key('null'): 301 kwargs['null'] = True 302 super(DateTimeField, self).__init__(*args, **normalize_field(kwargs)) 306 303 307 304 class FileField(models.FileField): … … 318 315 319 316 class DateField(models.DateField): 320 """DateField normalized with normalize_field()""" 321 322 def __init__(self, *args, **kwargs): 323 super(DateField, self).__init__(*args, **normalize_field(kwargs, '0000-00-00')) 324 325 def get_db_prep_value(self, value): 326 if value is None and not self.null: 327 return '0000-00-00' 328 329 return super(DateField, self).get_db_prep_value(value) 317 """DateField normalized with normalize_field(). This field is allowed to 318 be null by default unless null=False is passed""" 319 320 def __init__(self, *args, **kwargs): 321 if not kwargs.has_key('null'): 322 kwargs['null'] = True 323 super(DateField, self).__init__(*args, **normalize_field(kwargs)) 330 324 331 325 class RequiredFieldError(Exception): … … 399 393 400 394 @classmethod 401 def field_label(cls, field_name): 402 try: 403 return cls._meta.get_field(field_name).verbose_name 404 except FieldDoesNotExist: 395 def field_label(cls, field_name=None): 396 if field_name: 405 397 try: 406 return getattr(cls, field_name).verbose_name 407 except AttributeError: 408 return field_name 398 return cls._meta.get_field(field_name).verbose_name 399 except FieldDoesNotExist: 400 try: 401 return getattr(cls, field_name).verbose_name 402 except AttributeError: 403 return field_name 404 else: 405 return cls._meta.verbose_name 409 406 410 407 class Meta: -
trunk/telemeta/models/location.py
r539 r552 163 163 ancestor_location = ForeignKey('Location', related_name="descendant_relations", verbose_name=_('ancestor location')) 164 164 is_direct = BooleanField(db_index=True) 165 is_authoritative = BooleanField(_('authoritative')) 165 166 166 167 class Meta(MetaCore): -
trunk/telemeta/models/query.py
r551 r552 34 34 # David LIPSZYC <davidlipszyc@gmail.com> 35 35 36 from django.db.models import Q 36 from django.db.models import Q, Max, Min 37 37 from telemeta.models.core import * 38 38 from telemeta.util.unaccent import unaccent, unaccent_icmp … … 245 245 return qs 246 246 247 def recording_year_range(self): 248 from_max = self.aggregate(Max('recorded_from_year'))['recorded_from_year__max'] 249 to_max = self.aggregate(Max('recorded_to_year'))['recorded_to_year__max'] 250 year_max = max(from_max, to_max) 251 252 from_min = self.filter(recorded_from_year__gt=0).aggregate(Min('recorded_from_year'))['recorded_from_year__min'] 253 to_min = self.filter(recorded_to_year__gt=0).aggregate(Min('recorded_to_year'))['recorded_to_year__min'] 254 year_min = min(from_min, to_min) 255 256 return year_min, year_max 257 247 258 class MediaCollectionManager(CoreManager): 248 259 "Manage collection queries" -
trunk/telemeta/templates/telemeta_default/search_criteria.html
r551 r552 11 11 <script src="{% url telemeta-js "jquery.autocomplete.js" %}" type="text/javascript"></script> 12 12 <script type="text/javascript"> 13 function update_rec_period() { 14 var from_year = $('#rec_year_from'); 15 var to_year = $('#rec_year_to'); 16 17 if (from_year.val() == "0") { 18 to_year.attr('disabled', '1'); 19 to_year.val('0'); 20 } else { 21 to_year.removeAttr('disabled'); 22 if (this == to_year.get(0)) { 23 if (from_year.val() > to_year.val()) 24 from_year.val(to_year.val()); 25 } else if ((from_year.val() > to_year.val())) { 26 to_year.val(from_year.val()); 27 } 28 } 29 } 30 13 31 $(document).ready(function () { 14 32 $('#location').autocomplete('{% url telemeta-complete-location %}', { … … 19 37 } 20 38 }); 39 update_rec_period(); 40 $('#rec_year_from, #rec_year_to').change(update_rec_period); 21 41 }); 42 22 43 </script> 23 44 {% endblock %} … … 31 52 <p> 32 53 <label for="location">{% field_label "Location" %}</label> 33 <input type="text" name="location" id="location" />54 <input type="text" name="location" id="location" value="{{ criteria.location }}" /> 34 55 </p> 35 56 … … 39 60 <option value="">All ethnic groups</option> 40 61 {% for group in ethnic_groups %} 41 <option value="{{group.id}}" >{{group|escape}}</option>62 <option value="{{group.id}}" {% ifequal criteria.ethnic_group.id group.id %}selected {% endifequal %}>{{group|escape}}</option> 42 63 {% endfor %} 43 64 </select> … … 57 78 </p> 58 79 80 {% if rec_years %} 59 81 <p> 60 <label for="rec_date">Recording date</label> 61 <input type="text" id="rec_date" name="rec_date" /> 82 <label for="rec_date">{% trans "Year of recording" %}</label> 83 <select id="rec_year_from" name="rec_year_from" class="tiny"> 84 <option value="0"></option> 85 {% for year in rec_years %} 86 <option value="{{ year }}" {% ifequal criteria.rec_year_from year %}selected {% endifequal %}>{{year}}</option> 87 {% endfor %} 88 </select> 89 {% trans "to" %} 90 <select id="rec_year_to" name="rec_year_to" class="tiny"> 91 <option value="0"></option> 92 {% for year in rec_years %} 93 <option value="{{ year }}" {% ifequal criteria.rec_year_to year %}selected {% endifequal %}>{{year}}</option> 94 {% endfor %} 95 </select> 62 96 </p> 97 {% endif %} 63 98 64 99 <p> -
trunk/telemeta/templates/telemeta_default/search_results.html
r551 r552 23 23 <li><b>Title:</b> {{criteria.title}}</li> 24 24 {% endif %} 25 {% if criteria.rec_date %} 26 <li><b>{% trans "Year of recording" %}:</b> {{criteria.rec_date}}</li> 25 {% if criteria.rec_year_from %} 26 <li><b>{% trans "Year of recording" %}:</b> {{criteria.rec_year_from}} 27 {% ifnotequal criteria.rec_year_to criteria.rec_year_from %} 28 {% trans "to" %} {{criteria.rec_year_to}} 29 {% endifnotequal %} 30 </li> 27 31 {% endif %} 28 32 {% if criteria.pub_date %} -
trunk/telemeta/web/base.py
r551 r552 58 58 from telemeta.util.unaccent import unaccent 59 59 from telemeta.web import pages 60 import datetime 60 61 61 62 class WebView(Component): … … 167 168 return response 168 169 169 def edit_search(self, request): 170 170 def edit_search(self, request, criteria=None): 171 year_min, year_max = MediaCollection.objects.all().recording_year_range() 172 years = year_min and year_max and range(year_min, year_max + 1) \ 173 or year_min and [year_min] or year_max and [year_max] 171 174 return render_to_response('telemeta/search_criteria.html', { 175 'rec_years': years, 172 176 'ethnic_groups': MediaItem.objects.all().ethnic_groups(), 177 'criteria': criteria 173 178 }) 174 179 … … 215 220 collections.word_search('creator', value), 216 221 items.word_search('auteur', value)), 217 'rec_date': lambda value: ( 218 collections.by_recording_date(value), 219 items.by_recording_date(value)), 222 'rec_year_from': lambda value: ( 223 collections.by_recording_year(int(value), int(input['rec_year_to'])), 224 items.by_recording_date(datetime.date(int(value), 1, 1), 225 datetime.date(int(input['rec_year_to']), 12, 31))), 226 'rec_year_to': lambda value: (collections, items), 220 227 'pub_date': lambda value: ( 221 228 collections.by_publish_date(value),
