PageRenderTime 154ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/reviewboard/reviews/admin.py

https://github.com/Kamlani/reviewboard
Python | 225 lines | 189 code | 36 blank | 0 comment | 6 complexity | 402009d57238d97fc0f7654bba304ac0 MD5 | raw file
  1. from django.contrib import admin
  2. from django.utils.translation import ugettext_lazy as _
  3. from reviewboard.reviews.forms import DefaultReviewerForm
  4. from reviewboard.reviews.models import Comment, DefaultReviewer, Group, \
  5. Review, ReviewRequest, \
  6. ReviewRequestDraft, Screenshot, \
  7. ScreenshotComment
  8. class CommentAdmin(admin.ModelAdmin):
  9. list_display = ('truncate_text', 'review_request_id', 'first_line',
  10. 'num_lines', 'timestamp')
  11. search_fields = ['text']
  12. list_filter = ('timestamp',)
  13. raw_id_fields = ('filediff', 'interfilediff', 'reply_to')
  14. ordering = ['-timestamp']
  15. def review_request_id(self, obj):
  16. return obj.review.get().review_request.local_id
  17. review_request_id.short_description = _('Review request ID')
  18. class DefaultReviewerAdmin(admin.ModelAdmin):
  19. form = DefaultReviewerForm
  20. filter_horizontal = ('repository', 'groups', 'people',)
  21. fieldsets = (
  22. (_('General Information'), {
  23. 'fields': ('name', 'file_regex'),
  24. 'classes': ['wide'],
  25. }),
  26. (_('Reviewers'), {
  27. 'fields': ('groups', 'people'),
  28. }),
  29. (_('Repositories'), {
  30. 'description': _('<p>A default reviewer will cover all '
  31. 'repositories, unless assigned one or more '
  32. 'specific repositories below.</p>'),
  33. 'fields': ('repository',),
  34. })
  35. )
  36. list_display = ('name', 'file_regex')
  37. class GroupAdmin(admin.ModelAdmin):
  38. list_display = ('name', 'display_name', 'mailing_list', 'invite_only',
  39. 'visible')
  40. filter_horizontal = ('users',)
  41. fieldsets = (
  42. (_('General Information'), {
  43. 'fields': ('name', 'display_name', 'mailing_list',
  44. 'visible'),
  45. }),
  46. (_('Access Control'), {
  47. 'fields': ('invite_only', 'users', 'local_site'),
  48. }),
  49. (_('State'), {
  50. 'fields': ('incoming_request_count',),
  51. 'classes': ('collapse',),
  52. }),
  53. )
  54. class ReviewAdmin(admin.ModelAdmin):
  55. list_display = ('review_request', 'user', 'public', 'ship_it',
  56. 'is_reply', 'timestamp')
  57. list_filter = ('public', 'timestamp')
  58. search_fields = ['review_request__summary']
  59. raw_id_fields = ('review_request', 'user', 'base_reply_to',
  60. 'body_top_reply_to', 'body_bottom_reply_to',
  61. 'comments', 'screenshot_comments',
  62. 'reviewed_diffset')
  63. fieldsets = (
  64. (_('General Information'), {
  65. 'fields': ('user', 'review_request', 'public', 'ship_it',
  66. 'body_top', 'body_bottom'),
  67. }),
  68. (_('Related Objects'), {
  69. 'fields': ('base_reply_to',
  70. 'body_top_reply_to',
  71. 'body_bottom_reply_to',
  72. 'comments',
  73. 'screenshot_comments'),
  74. 'classes': ('collapse',)
  75. }),
  76. (_('State'), {
  77. 'fields': ('email_message_id', 'time_emailed'),
  78. 'classes': ('collapse',)
  79. })
  80. )
  81. class ReviewRequestAdmin(admin.ModelAdmin):
  82. list_display = ('summary', 'submitter', 'status', 'public', 'last_updated')
  83. list_filter = ('public', 'status', 'time_added', 'last_updated',
  84. 'repository')
  85. search_fields = ['summary']
  86. raw_id_fields = ('submitter', 'diffset_history', 'screenshots',
  87. 'inactive_screenshots', 'changedescs')
  88. filter_horizontal = ('target_people', 'target_groups')
  89. fieldsets = (
  90. (_('General Information'), {
  91. 'fields': ('submitter', 'public', 'status',
  92. 'summary', 'description', 'testing_done',
  93. 'bugs_closed', 'repository', 'branch', 'changenum',
  94. 'time_added')
  95. }),
  96. (_('Reviewers'), {
  97. 'fields': ('target_people', 'target_groups'),
  98. }),
  99. (_('Related Objects'), {
  100. 'fields': ('screenshots', 'inactive_screenshots', 'changedescs',
  101. 'diffset_history', 'local_site'),
  102. 'classes': ['collapse'],
  103. }),
  104. (_('State'), {
  105. 'description': _('<p>This is advanced state that should not be '
  106. 'modified unless something is wrong.</p>'),
  107. 'fields': ('email_message_id', 'time_emailed',
  108. 'last_review_timestamp', 'shipit_count', 'local_id'),
  109. 'classes': ['collapse'],
  110. }),
  111. )
  112. actions = [
  113. 'close_submitted',
  114. 'close_discarded',
  115. 'reopen',
  116. ]
  117. def close_submitted(self, request, queryset):
  118. rows_updated = queryset.update(status=ReviewRequest.SUBMITTED)
  119. if rows_updated == 1:
  120. msg = '1 review request was closed as submitted.'
  121. else:
  122. msg = '%s review requests were closed as submitted.' % \
  123. rows_updated
  124. self.message_user(request, msg)
  125. close_submitted.short_description = \
  126. _("Close selected review requests as submitted")
  127. def close_discarded(self, request, queryset):
  128. rows_updated = queryset.update(status=ReviewRequest.DISCARDED)
  129. if rows_updated == 1:
  130. msg = '1 review request was closed as discarded.'
  131. else:
  132. msg = '%s review requests were closed as discarded.' % \
  133. rows_updated
  134. self.message_user(request, msg)
  135. close_discarded.short_description = \
  136. _("Close selected review requests as discarded")
  137. def reopen(self, request, queryset):
  138. rows_updated = queryset.update(status=ReviewRequest.PENDING_REVIEW)
  139. if rows_updated == 1:
  140. msg = '1 review request was reopened.'
  141. else:
  142. msg = '%s review requests were reopened.' % rows_updated
  143. self.message_user(request, msg)
  144. reopen.short_description = _("Reopen selected review requests")
  145. class ReviewRequestDraftAdmin(admin.ModelAdmin):
  146. list_display = ('summary', 'submitter', 'last_updated')
  147. list_filter = ('last_updated',)
  148. search_fields = ['summary']
  149. raw_id_fields = ('review_request', 'diffset', 'screenshots',
  150. 'inactive_screenshots', 'changedesc')
  151. filter_horizontal = ('target_people', 'target_groups')
  152. fieldsets = (
  153. (_('General Information'), {
  154. 'fields': ('review_request',
  155. 'summary', 'description', 'testing_done',
  156. 'bugs_closed', 'branch'),
  157. }),
  158. (_('Reviewers'), {
  159. 'fields': ('target_people', 'target_groups'),
  160. }),
  161. (_('Related Objects'), {
  162. 'fields': ('screenshots', 'inactive_screenshots', 'changedesc',
  163. 'diffset'),
  164. 'classes': ['collapse'],
  165. }),
  166. )
  167. class ScreenshotAdmin(admin.ModelAdmin):
  168. list_display = ('thumb', 'caption', 'image', 'review_request_id')
  169. list_display_links = ('thumb', 'caption')
  170. search_fields = ('caption',)
  171. def review_request_id(self, obj):
  172. return obj.review_request.get().id
  173. review_request_id.short_description = _('Review request ID')
  174. class ScreenshotCommentAdmin(admin.ModelAdmin):
  175. list_display = ('text', 'screenshot', 'review_request_id', 'timestamp')
  176. list_filter = ('timestamp',)
  177. search_fields = ['caption']
  178. raw_id_fields = ('screenshot', 'reply_to')
  179. def review_request_id(self, obj):
  180. return obj.review.get().review_request.id
  181. review_request_id.short_description = _('Review request ID')
  182. admin.site.register(Comment, CommentAdmin)
  183. admin.site.register(DefaultReviewer, DefaultReviewerAdmin)
  184. admin.site.register(Group, GroupAdmin)
  185. admin.site.register(Review, ReviewAdmin)
  186. admin.site.register(ReviewRequest, ReviewRequestAdmin)
  187. admin.site.register(ReviewRequestDraft, ReviewRequestDraftAdmin)
  188. admin.site.register(Screenshot, ScreenshotAdmin)
  189. admin.site.register(ScreenshotComment, ScreenshotCommentAdmin)