# Path: src/dsite/models.py
# class Feedback(BaseModel):
#     """
#     意见反馈 Model
#     """
# 
#     username = models.CharField('称呼', max_length=64, blank=True)
#     email = models.EmailField('邮箱')
# 
#     content = models.CharField('反馈内容', max_length=1000)
# 
#     ip_address = models.GenericIPAddressField('发布IP', unpack_ipv4=True, blank=True, null=True)
# 
#     is_reply = models.BooleanField('是否回复', default=False)
# 
#     def __str__(self):
#         return self.email
# 
#     class Meta:
#         verbose_name = '用户反馈'
#         verbose_name_plural = '用户反馈'
# 
# class ContactConfig(BaseModel):
#     """
#     站点联系方式配置 Model
#     """
# 
#     qq = models.CharField('QQ', max_length=16, blank=True)
#     weibo = models.URLField('微博链接', blank=True)
#     email = models.EmailField('电子邮箱', blank=True)
#     github = models.URLField('Github', blank=True)
# 
#     def __str__(self):
#         return '站点联系方式配置'
# 
#     class Meta:
#         verbose_name = '站点联系方式配置'
#         verbose_name_plural = '站点联系方式配置'
# 
# class Link(BaseModel):
#     """
#     友情链接 Model
#     """
# 
#     name = models.CharField('显示名称', max_length=50)
# 
#     url = models.URLField('链接')
#     desc = models.CharField('描述', max_length=500, blank=True)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = '友情链接'
#         verbose_name_plural = '友情链接'
# 
# class AccessLog(BaseModel):
#     """
#     访问日志 Model
#     """
# 
#     path = models.CharField(u'访问路径', max_length=512, blank=True)
#     referer = models.CharField(u'Referer', max_length=512, blank=True)
#     agent = models.CharField('User-Agent', max_length=512, blank=True)
#     ip_address = models.GenericIPAddressField('IP', unpack_ipv4=True, blank=True, null=True)
# 
#     class Meta:
#         verbose_name = '访问记录'
#         verbose_name_plural = '访问记录'


from django.contrib import admin, messages
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponseRedirect
from core.modeladmin import BaseModelAdmin
from .models import Feedback, ContactConfig, Link, AccessLog
        from django.conf.urls import patterns, url
    """

    list_display = ['username_display', 'email', 'ip_address', 'created', 'content', 'is_reply_handler']

    actions = None
    list_display_links = None

    def username_display(self, obj):
        return '站点用户 {0}'.format(obj.user.username) if obj.user \
            else '访客 {0}'.format(obj.username or obj.ip_address)
    username_display.short_description = '用户'

    def is_reply_handler(self, obj):
        if obj.is_reply:
            return '已回复'
        return '<a href="{0}">标记为已回复</a>'.format(reverse('admin:dsite_feedback_set_to_replied', args=[obj.id]))
    is_reply_handler.short_description = '回复状态'
    is_reply_handler.allow_tags = True

    def get_urls(self):

        patterns = patterns(
            '',
            url(r'^(\d+)/set_to_replied/$', self.admin_site.admin_view(self.set_to_replied), name='dsite_feedback_set_to_replied'),
        ) + super(FeedbackAdmin, self).get_urls()
        return patterns

    def set_to_replied(self, request, f_id):
        try:
            feedback = Feedback.objects.get(id=f_id, is_deleted=False)

# Path: src/dsite/models.py
# class Feedback(BaseModel):
#     """
#     意见反馈 Model
#     """
# 
#     username = models.CharField('称呼', max_length=64, blank=True)
#     email = models.EmailField('邮箱')
# 
#     content = models.CharField('反馈内容', max_length=1000)
# 
#     ip_address = models.GenericIPAddressField('发布IP', unpack_ipv4=True, blank=True, null=True)
# 
#     is_reply = models.BooleanField('是否回复', default=False)
# 
#     def __str__(self):
#         return self.email
# 
#     class Meta:
#         verbose_name = '用户反馈'
#         verbose_name_plural = '用户反馈'
# 
# class ContactConfig(BaseModel):
#     """
#     站点联系方式配置 Model
#     """
# 
#     qq = models.CharField('QQ', max_length=16, blank=True)
#     weibo = models.URLField('微博链接', blank=True)
#     email = models.EmailField('电子邮箱', blank=True)
#     github = models.URLField('Github', blank=True)
# 
#     def __str__(self):
#         return '站点联系方式配置'
# 
#     class Meta:
#         verbose_name = '站点联系方式配置'
#         verbose_name_plural = '站点联系方式配置'
# 
# class Link(BaseModel):
#     """
#     友情链接 Model
#     """
# 
#     name = models.CharField('显示名称', max_length=50)
# 
#     url = models.URLField('链接')
#     desc = models.CharField('描述', max_length=500, blank=True)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = '友情链接'
#         verbose_name_plural = '友情链接'
# 
# class AccessLog(BaseModel):
#     """
#     访问日志 Model
#     """
# 
#     path = models.CharField(u'访问路径', max_length=512, blank=True)
#     referer = models.CharField(u'Referer', max_length=512, blank=True)
#     agent = models.CharField('User-Agent', max_length=512, blank=True)
#     ip_address = models.GenericIPAddressField('IP', unpack_ipv4=True, blank=True, null=True)
# 
#     class Meta:
#         verbose_name = '访问记录'
#         verbose_name_plural = '访问记录'


# Path: src/dsite/admin.py
from django.contrib import admin, messages
from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponseRedirect
from core.modeladmin import BaseModelAdmin
from .models import Feedback, ContactConfig, Link, AccessLog
        from django.conf.urls import patterns, url

    """

    list_display = ['username_display', 'email', 'ip_address', 'created', 'content', 'is_reply_handler']

    actions = None
    list_display_links = None

    def username_display(self, obj):
        return '站点用户 {0}'.format(obj.user.username) if obj.user \
            else '访客 {0}'.format(obj.username or obj.ip_address)
    username_display.short_description = '用户'

    def is_reply_handler(self, obj):
        if obj.is_reply:
            return '已回复'
        return '<a href="{0}">标记为已回复</a>'.format(reverse('admin:dsite_feedback_set_to_replied', args=[obj.id]))
    is_reply_handler.short_description = '回复状态'
    is_reply_handler.allow_tags = True

    def get_urls(self):

        patterns = patterns(
            '',
            url(r'^(\d+)/set_to_replied/$', self.admin_site.admin_view(self.set_to_replied), name='dsite_feedback_set_to_replied'),
        ) + super(FeedbackAdmin, self).get_urls()
        return patterns

    def set_to_replied(self, request, f_id):
        try:
            feedback = Feedback.objects.get(id=f_id, is_deleted=False)

        except Feedback.DoesNotExist: