Show More
@@ -0,0 +1,20 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | # Generated by Django 1.9.5 on 2016-05-11 09:23 | |
|
3 | from __future__ import unicode_literals | |
|
4 | ||
|
5 | from django.db import migrations, models | |
|
6 | ||
|
7 | ||
|
8 | class Migration(migrations.Migration): | |
|
9 | ||
|
10 | dependencies = [ | |
|
11 | ('boards', '0044_globalid_content'), | |
|
12 | ] | |
|
13 | ||
|
14 | operations = [ | |
|
15 | migrations.AddField( | |
|
16 | model_name='post', | |
|
17 | name='version', | |
|
18 | field=models.IntegerField(default=1), | |
|
19 | ), | |
|
20 | ] |
@@ -1,6 +1,7 b'' | |||
|
1 | 1 | from django.contrib import admin |
|
2 | 2 | from django.utils.translation import ugettext_lazy as _ |
|
3 | 3 | from django.core.urlresolvers import reverse |
|
4 | from django.db.models import F | |
|
4 | 5 | from boards.models import Post, Tag, Ban, Thread, Banner, PostImage, KeyPair, GlobalId |
|
5 | 6 | |
|
6 | 7 | |
@@ -12,7 +13,8 b' class PostAdmin(admin.ModelAdmin):' | |||
|
12 | 13 | search_fields = ('id', 'title', 'text', 'poster_ip') |
|
13 | 14 | exclude = ('referenced_posts', 'refmap', 'images', 'global_id') |
|
14 | 15 | readonly_fields = ('poster_ip', 'threads', 'thread', 'linked_images', |
|
15 |
'attachments', 'uid', 'url', 'pub_time', 'opening', 'linked_global_id' |
|
|
16 | 'attachments', 'uid', 'url', 'pub_time', 'opening', 'linked_global_id', | |
|
17 | 'version') | |
|
16 | 18 | |
|
17 | 19 | def ban_poster(self, request, queryset): |
|
18 | 20 | bans = 0 |
@@ -54,6 +56,11 b' class PostAdmin(admin.ModelAdmin):' | |||
|
54 | 56 | args=[global_id.id]), str(global_id)) |
|
55 | 57 | linked_global_id.allow_tags = True |
|
56 | 58 | |
|
59 | def save_model(self, request, obj, form, change): | |
|
60 | obj.increment_version() | |
|
61 | obj.save() | |
|
62 | obj.clear_cache() | |
|
63 | ||
|
57 | 64 | actions = ['ban_poster', 'ban_with_hiding'] |
|
58 | 65 | |
|
59 | 66 | |
@@ -96,6 +103,14 b' class ThreadAdmin(admin.ModelAdmin):' | |||
|
96 | 103 | def save_related(self, request, form, formsets, change): |
|
97 | 104 | super().save_related(request, form, formsets, change) |
|
98 | 105 | form.instance.refresh_tags() |
|
106 | ||
|
107 | def save_model(self, request, obj, form, change): | |
|
108 | op = obj.get_opening_post() | |
|
109 | op.increment_version() | |
|
110 | op.save(update_fields=['version']) | |
|
111 | obj.save() | |
|
112 | op.clear_cache() | |
|
113 | ||
|
99 | 114 | list_display = ('id', 'op', 'title', 'reply_count', 'status', 'ip', |
|
100 | 115 | 'display_tags') |
|
101 | 116 | list_filter = ('bump_time', 'status') |
@@ -11,7 +11,7 b' from boards.utils import datetime_to_epo' | |||
|
11 | 11 | from django.core.exceptions import ObjectDoesNotExist |
|
12 | 12 | from django.core.urlresolvers import reverse |
|
13 | 13 | from django.db import models |
|
14 | from django.db.models import TextField, QuerySet | |
|
14 | from django.db.models import TextField, QuerySet, F | |
|
15 | 15 | from django.template.defaultfilters import truncatewords, striptags |
|
16 | 16 | from django.template.loader import render_to_string |
|
17 | 17 | |
@@ -104,6 +104,7 b' class Post(models.Model, Viewable):' | |||
|
104 | 104 | tripcode = models.CharField(max_length=50, blank=True, default='') |
|
105 | 105 | opening = models.BooleanField(db_index=True) |
|
106 | 106 | hidden = models.BooleanField(default=False) |
|
107 | version = models.IntegerField(default=1) | |
|
107 | 108 | |
|
108 | 109 | def __str__(self): |
|
109 | 110 | return 'P#{}/{}'.format(self.id, self.get_title()) |
@@ -379,3 +380,14 b' class Post(models.Model, Viewable):' | |||
|
379 | 380 | |
|
380 | 381 | def set_hidden(self, hidden): |
|
381 | 382 | self.hidden = hidden |
|
383 | ||
|
384 | def increment_version(self): | |
|
385 | self.version = F('version') + 1 | |
|
386 | ||
|
387 | def clear_cache(self): | |
|
388 | global_id = self.global_id | |
|
389 | if global_id is not None and global_id.is_local()\ | |
|
390 | and global_id.content is not None: | |
|
391 | global_id.content = None | |
|
392 | global_id.save() | |
|
393 | global_id.signature_set.all().delete() |
@@ -32,6 +32,7 b" TAG_TAG = 'tag'" | |||
|
32 | 32 | TAG_ATTACHMENT_REFS = 'attachment-refs' |
|
33 | 33 | TAG_ATTACHMENT_REF = 'attachment-ref' |
|
34 | 34 | TAG_TRIPCODE = 'tripcode' |
|
35 | TAG_VERSION = 'version' | |
|
35 | 36 | |
|
36 | 37 | TYPE_GET = 'get' |
|
37 | 38 | |
@@ -126,6 +127,8 b' class SyncManager:' | |||
|
126 | 127 | SyncManager._attachment_to_xml( |
|
127 | 128 | attachments_tag, attachment_refs, file.file.file, |
|
128 | 129 | file.hash, file.file.url) |
|
130 | version_tag = et.SubElement(content_tag, TAG_VERSION) | |
|
131 | version_tag.text = str(post.version) | |
|
129 | 132 | |
|
130 | 133 | global_id.content = et.tostring(content_tag, ENCODING_UNICODE) |
|
131 | 134 | global_id.save() |
General Comments 0
You need to be logged in to leave comments.
Login now