Django Library PyGal
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

infoviews.py 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. from django.utils.translation import gettext as _
  2. import fractions
  3. import geo
  4. from ..models import get_item_type, TYPE_AUDIO, TYPE_FOLDER, TYPE_IMAGE, TYPE_VIDEO
  5. from .userviews import base_view as base_userview
  6. def get_wrapper_class(full_path):
  7. return {
  8. TYPE_FOLDER: folder_view,
  9. TYPE_IMAGE: image_view,
  10. TYPE_VIDEO: video_view,
  11. TYPE_AUDIO: audio_view,
  12. }.get(get_item_type(full_path), base_view)
  13. def get_wrapper_instance(full_path, request):
  14. return get_wrapper_class(full_path)(request, full_path)
  15. class base_view(base_userview):
  16. def __init__(self, *args, **kwargs):
  17. base_userview.__init__(self, *args, **kwargs)
  18. self.template = 'pygal/infoview.html'
  19. def context_adaption(self, context):
  20. base_userview.context_adaption(self, context)
  21. context['heading'] = {
  22. 'general': _('General'),
  23. 'information': _('Information'),
  24. 'database': _('Database')
  25. }
  26. @property
  27. def database_information(self):
  28. rv = []
  29. if self.request.user.is_superuser:
  30. if self.item is not None:
  31. rv.append({'description': 'DB-Item', 'data': 'Item (%d)' % self.item.id, 'url': self.item.get_admin_url()})
  32. i = 0
  33. for t in self.item.tag_set.all():
  34. i += 1
  35. rv.append({'description': 'TAG%d - %s' % (i % 10, t.text), 'data': 'Tag (%d)' % t.id, 'url': t.get_admin_url()})
  36. return rv
  37. @property
  38. def item_information(self):
  39. return []
  40. @property
  41. def upload_information(self):
  42. rv = []
  43. return rv
  44. class folder_view(base_view):
  45. def __init__(self, *args, **kwargs):
  46. base_view.__init__(self, *args, **kwargs)
  47. @property
  48. def item_information(self):
  49. rv = []
  50. rv.append({'description': _('Number of Folder(s)'), 'data': self.item.item_data.num_folders, 'url': None})
  51. rv.append({'description': _('Number of Audio File(s)'), 'data': self.item.item_data.num_audio, 'url': None})
  52. rv.append({'description': _('Number of Image(s)'), 'data': self.item.item_data.num_images, 'url': None})
  53. rv.append({'description': _('Number of Other File(s)'), 'data': self.item.item_data.num_other, 'url': None})
  54. rv.append({'description': _('Number of Video(s)'), 'data': self.item.item_data.num_videos, 'url': None})
  55. return rv
  56. class image_view(base_view):
  57. def __init__(self, *args, **kwargs):
  58. base_view.__init__(self, *args, **kwargs)
  59. @property
  60. def item_information(self):
  61. rv = []
  62. rv.append({'description': _('Camera'), 'data': '%s' % (self.item.item_data.camera), 'url': None})
  63. rv.append({'description': _('Resolution'), 'data': '%d x %d' % (self.item.item_data.width, self.item.item_data.height), 'url': None})
  64. gps_data = self.item.item_data.gps
  65. if gps_data is not None:
  66. c = geo.gps.coordinate(**gps_data)
  67. rv.append({'description': _('GPS'), 'data': str(c), 'url': geo.osm.landmark_link(c)})
  68. rv.append({'description': _('Exposure Program'), 'data': self.item.item_data.exposure_program, 'url': None})
  69. f = fractions.Fraction(self.item.item_data.exposure_time).limit_denominator()
  70. rv.append({'description': _('Exposure Time'), 'data': '%d/%d s' % (f.numerator, f.denominator), 'url': None})
  71. rv.append({'description': _('ISO'), 'data': self.item.item_data.iso, 'url': None})
  72. rv.append({'description': _('Focal Length'), 'data': self.item.item_data.focal_length, 'url': None})
  73. rv.append({'description': _('Apeture'), 'data': self.item.item_data.f_number, 'url': None})
  74. rv.append({'description': _('Flash'), 'data': self.item.item_data.flash, 'url': None})
  75. rv.append({'description': _('Orientation'), 'data': self.item.item_data.orientation, 'url': None})
  76. return rv
  77. class video_view(base_view):
  78. def __init__(self, *args, **kwargs):
  79. base_view.__init__(self, *args, **kwargs)
  80. @property
  81. def item_information(self):
  82. rv = []
  83. rv.append({'description': _('Duration'), 'data': self.__duration_txt__(self.item.item_data.duration), 'url': None})
  84. rv.append({'description': _('Resolution'), 'data': '%d x %d' % (self.item.item_data.width, self.item.item_data.height), 'url': None})
  85. rv.append({'description': _('Ratio'), 'data': self.item.item_data.ratio, 'url': None})
  86. return rv
  87. class audio_view(base_view):
  88. def __init__(self, *args, **kwargs):
  89. base_view.__init__(self, *args, **kwargs)
  90. @property
  91. def item_information(self):
  92. rv = []
  93. rv.append({'description': _('Artist'), 'data': self.item.item_data.artist, 'url': None})
  94. rv.append({'description': _('Album'), 'data': self.item.item_data.album, 'url': None})
  95. rv.append({'description': _('Year'), 'data': self.item.item_data.year, 'url': None})
  96. rv.append({'description': _('Title'), 'data': self.item.item_data.title, 'url': None})
  97. rv.append({'description': _('Track'), 'data': self.item.item_data.track, 'url': None})
  98. rv.append({'description': _('Duration'), 'data': self.__duration_txt__(self.item.item_data.duration), 'url': None})
  99. rv.append({'description': _('Genre'), 'data': self.item.item_data.genre, 'url': None})
  100. rv.append({'description': _('Bitrate'), 'data': self.__size_txt__(self.item.item_data.bitrate), 'url': None})
  101. return rv