~linuxgoose/bocpress

ref: 936ac6d885385d9e80ea4b9852e3d7b0390ec758 bocpress/main/admin.py -rw-r--r-- 5.5 KiB
936ac6d8 — Jordan update readme wording 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
from django.conf import settings
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as DjUserAdmin
from django.utils.html import format_html

from main import models, util


@admin.action(description="Mark selected users as approved")
def make_approved(modeladmin, request, queryset):
    queryset.update(is_approved=True)

@admin.register(models.User)
class UserAdmin(DjUserAdmin):
    list_display = (
        "id",
        "username",
        "blog_url",
        "email",
        "stripe_customer_id",
        "is_premium",
        "mail_export_on",
        "post_count",
        "is_approved",
        "blog_title",
        "date_joined",
        "last_login",
    )
    list_display_links = ("id", "username")
    list_filter = ("is_premium", "mail_export_on", "comments_on")
    search_fields = ("username", "email", "stripe_customer_id", "blog_title")
    actions = [make_approved]

    @admin.display
    def blog_url(self, obj):
        url = f"{util.get_protocol()}"
        if obj.custom_domain:
            url += f"//{obj.custom_domain}"
        else:
            url += f"//{obj.username}.{settings.CANONICAL_HOST}"
        return format_html(f'<a href="{url}">{url}</a>')

    fieldsets = DjUserAdmin.fieldsets + (
        (
            "Blog options",
            {
                "fields": (
                    "about",
                    "blog_title",
                    "posts_page_title",
                    "blog_byline",
                    "blog_index_content",
                    "footer_note",
                    "theme_zialucia",
                    "redirect_domain",
                    "custom_domain",
                    "comments_on",
                    "notifications_on",
                    "mail_export_on",
                    "post_backups_on",
                    "show_posts_on_homepage",
                    "show_posts_in_nav",
                    "noindex_on",
                    "reading_time_on",
                    "export_unsubscribe_key",
                    "webring_name",
                    "webring_prev_url",
                    "webring_next_url",
                    "stripe_customer_id",
                    "stripe_subscription_id",
                    "monero_address",
                    "is_premium",
                    "is_grandfathered",
                    "is_approved",
                    "api_key",
                    "robots_txt",
                ),
            },
        ),
    )
    ordering = ["-id"]


@admin.register(models.Post)
class PostAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "title",
        "slug",
        "post_url",
        "owner",
        "created_at",
        "broadcasted_at",
        "published_at",
    )
    search_fields = ("title", "slug", "body", "owner__username")
    ordering = ["-id"]

    @admin.display
    def post_url(self, obj):
        url = util.get_protocol() + obj.get_proper_url()
        return format_html(f'<a href="{url}">{url}</a>')


@admin.register(models.Page)
class PageAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "title",
        "slug",
        "owner",
        "created_at",
        "updated_at",
        "is_hidden",
    )
    ordering = ["-id"]


@admin.register(models.Image)
class ImageAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "name",
        "slug",
        "extension",
        "owner",
        "uploaded_at",
    )
    ordering = ["-id"]


@admin.register(models.AnalyticPage)
class AnalyticPageAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "user",
        "path",
        "created_at",
    )
    ordering = ["-id"]


@admin.register(models.AnalyticPost)
class AnalyticPostAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "post",
        "created_at",
    )
    ordering = ["-id"]


@admin.register(models.Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "post",
        "is_approved",
        "name",
        "email",
        "body",
        "created_at",
    )
    ordering = ["-id"]


@admin.register(models.Notification)
class NotificationAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "email",
        "blog_user",
        "unsubscribe_key",
        "is_active",
    )
    ordering = ["-id"]


@admin.register(models.NotificationRecord)
class NotificationRecordAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "sent_at",
        "notification",
        "post",
    )
    ordering = ["-id"]


@admin.register(models.ExportRecord)
class ExportRecordAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "name",
        "sent_at",
        "user",
    )
    list_display_links = ("id", "name")
    ordering = ["-id"]


@admin.register(models.Snapshot)
class SnapshotAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "title",
        "owner",
    )
    list_display_links = ("id", "title")
    ordering = ["-id"]


@admin.register(models.Onboard)
class OnboardAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "user",
        "created_at",
    )
    ordering = ["-id"]

@admin.register(models.ReallySimpleLicensing)
class RSLAdmin(admin.ModelAdmin):
    list_display = (
        "id",
        "user",
        "license",
        "show_http",
        "show_rss",
        "show_robotstxt",
        "show_webpage",
    )
    list_display_links = ("id", "user")
    list_filter = ("show_http", "show_rss", "show_robotstxt", "show_webpage")
    search_fields = ("user__username", "license")
    ordering = ["-id"]