Show More
@@ -212,7 +212,7 b' class PostForm(NeboardForm):' | |||||
212 | for thread_id in threads_id_list: |
|
212 | for thread_id in threads_id_list: | |
213 | try: |
|
213 | try: | |
214 | thread = Post.objects.get(id=int(thread_id)) |
|
214 | thread = Post.objects.get(id=int(thread_id)) | |
215 | if not thread.is_opening(): |
|
215 | if not thread.is_opening() or thread.get_thread().archived: | |
216 | raise ObjectDoesNotExist() |
|
216 | raise ObjectDoesNotExist() | |
217 | threads.append(thread) |
|
217 | threads.append(thread) | |
218 | except (ObjectDoesNotExist, ValueError): |
|
218 | except (ObjectDoesNotExist, ValueError): |
@@ -1,19 +1,30 b'' | |||||
|
1 | import os | |||
|
2 | ||||
1 | from django.core.management import BaseCommand |
|
3 | from django.core.management import BaseCommand | |
2 | from django.db import transaction |
|
4 | from django.db import transaction | |
3 | from django.db.models import Count |
|
|||
4 |
|
5 | |||
5 | from boards.models import Tag |
|
6 | from boards.models.image import IMAGES_DIRECTORY, PostImage, IMAGE_THUMB_SIZE | |
|
7 | from neboard.settings import MEDIA_ROOT | |||
6 |
|
8 | |||
7 |
|
9 | |||
8 | __author__ = 'neko259' |
|
10 | __author__ = 'neko259' | |
9 |
|
11 | |||
10 |
|
12 | |||
11 | class Command(BaseCommand): |
|
13 | class Command(BaseCommand): | |
12 |
help = 'Remove |
|
14 | help = 'Remove image files whose models were deleted' | |
13 |
|
15 | |||
14 | @transaction.atomic |
|
16 | @transaction.atomic | |
15 | def handle(self, *args, **options): |
|
17 | def handle(self, *args, **options): | |
16 | empty = Tag.objects.annotate(num_threads=Count('thread'))\ |
|
18 | count = 0 | |
17 | .filter(num_threads=0).order_by('-required', 'name') |
|
19 | thumb_prefix = '.{}x{}'.format(*IMAGE_THUMB_SIZE) | |
18 | print('Removing {} empty tags'.format(empty.count())) |
|
20 | ||
19 | empty.delete() |
|
21 | model_files = os.listdir(MEDIA_ROOT + IMAGES_DIRECTORY) | |
|
22 | for file in model_files: | |||
|
23 | image_name = file if thumb_prefix not in file else file.replace(thumb_prefix, '') | |||
|
24 | found = PostImage.objects.filter(image=IMAGES_DIRECTORY + image_name).exists() | |||
|
25 | ||||
|
26 | if not found: | |||
|
27 | print('Missing {}'.format(image_name)) | |||
|
28 | os.remove(MEDIA_ROOT + IMAGES_DIRECTORY + file) | |||
|
29 | count += 1 | |||
|
30 | print('Deleted {} image files.'.format(count)) No newline at end of file |
@@ -1,4 +1,5 b'' | |||||
1 | from django.conf.urls import patterns, url |
|
1 | from django.conf.urls import patterns, url | |
|
2 | from django.views.i18n import javascript_catalog | |||
2 |
|
3 | |||
3 | from boards import views |
|
4 | from boards import views | |
4 | from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed |
|
5 | from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed | |
@@ -52,7 +53,7 b" urlpatterns = patterns(''," | |||||
52 | url(r'^thread/(?P<post_id>\d+)/rss/$', ThreadPostsFeed()), |
|
53 | url(r'^thread/(?P<post_id>\d+)/rss/$', ThreadPostsFeed()), | |
53 |
|
54 | |||
54 | # i18n |
|
55 | # i18n | |
55 |
url(r'^jsi18n/$', |
|
56 | url(r'^jsi18n/$', javascript_catalog, js_info_dict, | |
56 | name='js_info_dict'), |
|
57 | name='js_info_dict'), | |
57 |
|
58 | |||
58 | # API |
|
59 | # API |
@@ -46,6 +46,8 b' USE_L10N = True' | |||||
46 | # If you set this to False, Django will not use timezone-aware datetimes. |
|
46 | # If you set this to False, Django will not use timezone-aware datetimes. | |
47 | USE_TZ = True |
|
47 | USE_TZ = True | |
48 |
|
48 | |||
|
49 | USE_ETAGS = True | |||
|
50 | ||||
49 | # Absolute filesystem path to the directory that will hold user-uploaded files. |
|
51 | # Absolute filesystem path to the directory that will hold user-uploaded files. | |
50 | # Example: "/home/media/media.lawrence.com/media/" |
|
52 | # Example: "/home/media/media.lawrence.com/media/" | |
51 | MEDIA_ROOT = './media/' |
|
53 | MEDIA_ROOT = './media/' | |
@@ -109,6 +111,7 b' TEMPLATE_CONTEXT_PROCESSORS = (' | |||||
109 | ) |
|
111 | ) | |
110 |
|
112 | |||
111 | MIDDLEWARE_CLASSES = ( |
|
113 | MIDDLEWARE_CLASSES = ( | |
|
114 | 'django.middleware.http.ConditionalGetMiddleware', | |||
112 | 'django.contrib.sessions.middleware.SessionMiddleware', |
|
115 | 'django.contrib.sessions.middleware.SessionMiddleware', | |
113 | 'django.middleware.locale.LocaleMiddleware', |
|
116 | 'django.middleware.locale.LocaleMiddleware', | |
114 | 'django.middleware.common.CommonMiddleware', |
|
117 | 'django.middleware.common.CommonMiddleware', | |
@@ -142,7 +145,6 b' INSTALLED_APPS = (' | |||||
142 | # Uncomment the next line to enable admin documentation: |
|
145 | # Uncomment the next line to enable admin documentation: | |
143 | # 'django.contrib.admindocs', |
|
146 | # 'django.contrib.admindocs', | |
144 | 'django.contrib.humanize', |
|
147 | 'django.contrib.humanize', | |
145 | 'django_cleanup', |
|
|||
146 |
|
148 | |||
147 | 'debug_toolbar', |
|
149 | 'debug_toolbar', | |
148 |
|
150 |
General Comments 0
You need to be logged in to leave comments.
Login now