from ummeli.base.models import *
from django.contrib import admin
from jmbocomments.models import UserComment
from jmbocomments.admin import UserCommentAdmin
from jmbo.admin import ModelBaseAdmin




class UmmeliUserCommentAdmin(UserCommentAdmin):
    list_display = ('content_object', 'user', 'comment_alias', 'comment',
                    'submit_date', 'is_public', 'is_removed', 'like_count',
                    'latest_flag')
    list_filter = ('submit_date', 'site', 'is_removed')

    def comment_alias(self, instance):
        return instance.user.get_profile().fullname()\
                if not instance.user.get_profile().comment_as_anon\
                else "Anon."


class BannerAdmin(ModelBaseAdmin):
    list_filter = (
        'state',
        'created',
        'categories',
        'banner_type'
    )
    list_display = (
        'title', 'description', 'thumbnail', 'schedule', '_actions')
    raw_id_fields = ('owner', 'location')

    def thumbnail(self, obj, *args, **kwargs):
        return '<img src="%s" />' % (obj.image.url,)
    thumbnail.allow_tags = True

    def schedule(self, obj, *args, **kwargs):
        if(obj.time_on and obj.time_off):
            return 'Randomly selected by Vlive between %s and %s' % (
                obj.time_on, obj.time_off)
        return 'Randomly selected by Vlive'

class CurriculumVitaeAdmin(admin.ModelAdmin):
    search_fields = ['user__username', 'first_name', 'surname']
    list_display = ('user', 'first_name', 'surname', 'province')
    raw_id_fields = ('user', 'certificates', 'languages', 'work_experiences',
                     'references', 'preferred_skill', 'skills',
                     'connection_requests')
    readonly_fields = ('user', 'province', 'certificates', 'languages',
                     'work_experiences', 'references', 'preferred_skill',
                     'skills', 'connection_requests')
    list_filter = ('province', )

admin.site.register(CurriculumVitae, CurriculumVitaeAdmin)
admin.site.register(Certificate)
admin.site.register(Language)
admin.site.register(WorkExperience)
admin.site.register(Reference)
admin.site.register(Banner, BannerAdmin)

if UserComment in admin.site._registry:
    admin.site.unregister(UserComment)
admin.site.register(UserComment, UmmeliUserCommentAdmin)

@@ -55,24 +55,69 @@
 mport admin%0A
+from django.core.urlresolvers import reverse%0A
 from jmbocom
@@ -148,16 +148,16 @@
 Comment%0A
-
 from jmb
@@ -236,18 +236,16 @@
 Admin%0A%0A%0A
-%0A%0A
 class Um
@@ -554,24 +554,19 @@
 s(self, 
-instance
+obj
 ):%0A     
@@ -572,23 +572,27 @@
     
-return instance
+comment_alias = obj
 .use
@@ -635,27 +635,18 @@
     
-    
 if not 
-instance
+obj
 .use
@@ -690,20 +690,16 @@
         
-    
 else %22An
@@ -702,16 +702,505 @@
  %22Anon.%22
+%0A%0A        url = reverse('admin:auth_user_change', args=(obj.user.id,))%0A        return '%3Ca href=%22%25s?user=%25s%22%3E%25s%3C/a%3E' %25 (%0A            reverse(%0A                'admin:%25s_%25s_changelist' %25 (%0A                    obj._meta.app_label,%0A                    obj._meta.module_name%0A                ),%0A            ),%0A            obj.user.id,%0A            comment_alias,%0A        ) + ' (%3Ca href=%22%25s%22%3Eedit%3C/a%3E)' %25 url%0A    comment_alias.allow_tags = True%0A    comment_alias.short_description = 'Comment Alias'
 %0A%0A%0Aclass

allow fitering comments by user