# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

# Third Party Stuff
from django.contrib import admin
from django.db import models
from pagedown.widgets import AdminPagedownWidget
from simple_history.admin import SimpleHistoryAdmin

# Junction Stuff
from junction.base.admin import AuditAdmin, TimeAuditAdmin
from junction.proposals.models import (
    Proposal,
    ProposalComment,
    ProposalCommentVote,
    ProposalSection,
    ProposalSectionReviewer,
    ProposalType,
    ProposalVote,
    ProposalSectionReviewerVote,
    ProposalSectionReviewerVoteValue
)


class ProposalSectionAdmin(AuditAdmin):
    list_display = ('name', 'active') + AuditAdmin.list_display


class ProposalSectionReviewerAdmin(AuditAdmin):
    list_display = ('conference_reviewer', 'proposal_section') + AuditAdmin.list_display
    list_filter = ['proposal_section']


class ProposalTypeAdmin(AuditAdmin):
    list_display = ('name', 'active', 'start_date', 'end_date') + AuditAdmin.list_display


class ProposalAdmin(TimeAuditAdmin, SimpleHistoryAdmin):
    list_display = ('title', 'conference', 'proposal_section', 'proposal_type', 'author',
                    'status', 'review_status') + TimeAuditAdmin.list_display
    list_filter = ['proposal_section__name', 'proposal_type', 'target_audience', 'conference', 'status']
    formfield_overrides = {
        models.TextField: {'widget': AdminPagedownWidget},
    }


class ProposalVoteAdmin(TimeAuditAdmin):
    list_display = ('proposal', 'voter', 'role', 'up_vote') + \
        TimeAuditAdmin.list_display


class ProposalSectionReviewerVoteValueAdmin(AuditAdmin):
    list_display = ('vote_value', 'description') + AuditAdmin.list_display


class ProposalSectionReviewerVoteAdmin(TimeAuditAdmin):
    list_filter = ['vote_value', 'proposal__proposal_type__name']
    list_display = ('proposal', 'voter', 'role', 'vote_value') + \
        TimeAuditAdmin.list_display


class ProposalCommentAdmin(TimeAuditAdmin):
    list_display = (
        'proposal', 'commenter', 'private', 'comment') + TimeAuditAdmin.list_display
    list_filter = ['private', 'reviewer']


class ProposalCommentVoteAdmin(TimeAuditAdmin):
    list_display = ('proposal_comment', 'voter', 'up_vote') + \
        TimeAuditAdmin.list_display


admin.site.register(ProposalSection, ProposalSectionAdmin)
admin.site.register(ProposalType, ProposalTypeAdmin)
admin.site.register(Proposal, ProposalAdmin)
admin.site.register(ProposalVote, ProposalVoteAdmin)
admin.site.register(ProposalSectionReviewerVote, ProposalSectionReviewerVoteAdmin)
admin.site.register(ProposalSectionReviewerVoteValue, ProposalSectionReviewerVoteValueAdmin)
admin.site.register(ProposalComment, ProposalCommentAdmin)
admin.site.register(ProposalCommentVote, ProposalCommentVoteAdmin)
admin.site.register(ProposalSectionReviewer, ProposalSectionReviewerAdmin)

@@ -1090,74 +1090,66 @@
 = ('
-title', 'conference', 'proposal_section', 'proposal_type', 'author
+proposal_info', 'author_info', 'author_email', 'conference
 ',%0A 
@@ -1196,39 +1196,11 @@
 tus'
-) + TimeAuditAdmin.list_display
+, )
 %0A   
@@ -1257,16 +1257,35 @@
 l_type',
+%0A                  
  'target
@@ -1318,16 +1318,33 @@
 'status'
+, 'review_status'
 %5D%0A    fo
@@ -1431,16 +1431,339 @@
 %0A    %7D%0A%0A
+    def proposal_info(self, obj):%0A        return '%25s (%25s)' %25 (obj.title, obj.proposal_type)%0A%0A    def author_email(self, obj):%0A        if obj.author:%0A            return obj.author.email%0A%0A    def author_info(self, obj):%0A        if obj.author:%0A            return %22%25s (%25s)%22 %25 (obj.author.get_full_name(), obj.author.username)%0A%0A
 %0Aclass P

Update proposal admin list view