Show More
@@ -0,0 +1,74 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | from south.utils import datetime_utils as datetime | |
|
3 | from south.db import db | |
|
4 | from south.v2 import SchemaMigration | |
|
5 | from django.db import models | |
|
6 | ||
|
7 | ||
|
8 | class Migration(SchemaMigration): | |
|
9 | ||
|
10 | def forwards(self, orm): | |
|
11 | # Adding field 'Thread.bumpable' | |
|
12 | db.add_column('boards_thread', 'bumpable', | |
|
13 | self.gf('django.db.models.fields.BooleanField')(default=True), | |
|
14 | keep_default=False) | |
|
15 | ||
|
16 | ||
|
17 | def backwards(self, orm): | |
|
18 | # Deleting field 'Thread.bumpable' | |
|
19 | db.delete_column('boards_thread', 'bumpable') | |
|
20 | ||
|
21 | ||
|
22 | models = { | |
|
23 | 'boards.ban': { | |
|
24 | 'Meta': {'object_name': 'Ban'}, | |
|
25 | 'can_read': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), | |
|
26 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
27 | 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), | |
|
28 | 'reason': ('django.db.models.fields.CharField', [], {'max_length': '200', 'default': "'Auto'"}) | |
|
29 | }, | |
|
30 | 'boards.post': { | |
|
31 | 'Meta': {'object_name': 'Post', 'ordering': "('id',)"}, | |
|
32 | '_text_rendered': ('django.db.models.fields.TextField', [], {}), | |
|
33 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
34 | 'images': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'null': 'True', 'db_index': 'True', 'blank': 'True', 'related_name': "'ip+'", 'to': "orm['boards.PostImage']"}), | |
|
35 | 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
36 | 'poster_ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), | |
|
37 | 'poster_user_agent': ('django.db.models.fields.TextField', [], {}), | |
|
38 | 'pub_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
39 | 'referenced_posts': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'null': 'True', 'db_index': 'True', 'blank': 'True', 'related_name': "'rfp+'", 'to': "orm['boards.Post']"}), | |
|
40 | 'refmap': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), | |
|
41 | 'text': ('markupfield.fields.MarkupField', [], {'rendered_field': 'True'}), | |
|
42 | 'text_markup_type': ('django.db.models.fields.CharField', [], {'max_length': '30', 'default': "'bbcode'"}), | |
|
43 | 'thread_new': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'null': 'True', 'to': "orm['boards.Thread']"}), | |
|
44 | 'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}) | |
|
45 | }, | |
|
46 | 'boards.postimage': { | |
|
47 | 'Meta': {'object_name': 'PostImage', 'ordering': "('id',)"}, | |
|
48 | 'hash': ('django.db.models.fields.CharField', [], {'max_length': '36'}), | |
|
49 | 'height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |
|
50 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
51 | 'image': ('boards.thumbs.ImageWithThumbsField', [], {'max_length': '100', 'blank': 'True'}), | |
|
52 | 'pre_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |
|
53 | 'pre_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |
|
54 | 'width': ('django.db.models.fields.IntegerField', [], {'default': '0'}) | |
|
55 | }, | |
|
56 | 'boards.tag': { | |
|
57 | 'Meta': {'object_name': 'Tag', 'ordering': "('name',)"}, | |
|
58 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
59 | 'name': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '100'}), | |
|
60 | 'threads': ('django.db.models.fields.related.ManyToManyField', [], {'null': 'True', 'symmetrical': 'False', 'blank': 'True', 'related_name': "'tag+'", 'to': "orm['boards.Thread']"}) | |
|
61 | }, | |
|
62 | 'boards.thread': { | |
|
63 | 'Meta': {'object_name': 'Thread'}, | |
|
64 | 'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | |
|
65 | 'bump_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
66 | 'bumpable': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), | |
|
67 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
68 | 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
69 | 'replies': ('django.db.models.fields.related.ManyToManyField', [], {'null': 'True', 'symmetrical': 'False', 'blank': 'True', 'related_name': "'tre+'", 'to': "orm['boards.Post']"}), | |
|
70 | 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['boards.Tag']"}) | |
|
71 | } | |
|
72 | } | |
|
73 | ||
|
74 | complete_apps = ['boards'] |
@@ -0,0 +1,81 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | from south.utils import datetime_utils as datetime | |
|
3 | from south.db import db | |
|
4 | from south.v2 import DataMigration | |
|
5 | from django.db import models | |
|
6 | import boards | |
|
7 | ||
|
8 | class Migration(DataMigration): | |
|
9 | ||
|
10 | def forwards(self, orm): | |
|
11 | changed_count = 0 | |
|
12 | ||
|
13 | for thread in orm['boards.Thread'].objects.all(): | |
|
14 | if thread.replies.count() >= boards.settings.MAX_POSTS_PER_THREAD: | |
|
15 | thread.bumpable = False | |
|
16 | print('Disabled bump on thread {}'.format(thread.id)) | |
|
17 | changed_count += 1 | |
|
18 | else: | |
|
19 | thread.bumpable = True | |
|
20 | thread.save(update_fields=['bumpable']) | |
|
21 | ||
|
22 | ||
|
23 | print('Changed {} threads.'.format(changed_count)) | |
|
24 | ||
|
25 | def backwards(self, orm): | |
|
26 | "Write your backwards methods here." | |
|
27 | ||
|
28 | models = { | |
|
29 | 'boards.ban': { | |
|
30 | 'Meta': {'object_name': 'Ban'}, | |
|
31 | 'can_read': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), | |
|
32 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
33 | 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), | |
|
34 | 'reason': ('django.db.models.fields.CharField', [], {'default': "'Auto'", 'max_length': '200'}) | |
|
35 | }, | |
|
36 | 'boards.post': { | |
|
37 | 'Meta': {'object_name': 'Post', 'ordering': "('id',)"}, | |
|
38 | '_text_rendered': ('django.db.models.fields.TextField', [], {}), | |
|
39 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
40 | 'images': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'ip+'", 'null': 'True', 'to': "orm['boards.PostImage']", 'db_index': 'True', 'blank': 'True'}), | |
|
41 | 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
42 | 'poster_ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), | |
|
43 | 'poster_user_agent': ('django.db.models.fields.TextField', [], {}), | |
|
44 | 'pub_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
45 | 'referenced_posts': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'rfp+'", 'null': 'True', 'to': "orm['boards.Post']", 'db_index': 'True', 'blank': 'True'}), | |
|
46 | 'refmap': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}), | |
|
47 | 'text': ('markupfield.fields.MarkupField', [], {'rendered_field': 'True'}), | |
|
48 | 'text_markup_type': ('django.db.models.fields.CharField', [], {'default': "'bbcode'", 'max_length': '30'}), | |
|
49 | 'thread_new': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['boards.Thread']", 'null': 'True'}), | |
|
50 | 'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}) | |
|
51 | }, | |
|
52 | 'boards.postimage': { | |
|
53 | 'Meta': {'object_name': 'PostImage', 'ordering': "('id',)"}, | |
|
54 | 'hash': ('django.db.models.fields.CharField', [], {'max_length': '36'}), | |
|
55 | 'height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |
|
56 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
57 | 'image': ('boards.thumbs.ImageWithThumbsField', [], {'blank': 'True', 'max_length': '100'}), | |
|
58 | 'pre_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |
|
59 | 'pre_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), | |
|
60 | 'width': ('django.db.models.fields.IntegerField', [], {'default': '0'}) | |
|
61 | }, | |
|
62 | 'boards.tag': { | |
|
63 | 'Meta': {'object_name': 'Tag', 'ordering': "('name',)"}, | |
|
64 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
65 | 'name': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '100'}), | |
|
66 | 'threads': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'null': 'True', 'to': "orm['boards.Thread']", 'related_name': "'tag+'", 'blank': 'True'}) | |
|
67 | }, | |
|
68 | 'boards.thread': { | |
|
69 | 'Meta': {'object_name': 'Thread'}, | |
|
70 | 'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | |
|
71 | 'bump_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
72 | 'bumpable': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), | |
|
73 | 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | |
|
74 | 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), | |
|
75 | 'replies': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'null': 'True', 'to': "orm['boards.Post']", 'related_name': "'tre+'", 'blank': 'True'}), | |
|
76 | 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['boards.Tag']"}) | |
|
77 | } | |
|
78 | } | |
|
79 | ||
|
80 | complete_apps = ['boards'] | |
|
81 | symmetrical = True |
@@ -73,7 +73,10 b' class PostManager(models.Manager):' | |||
|
73 | 73 | else: |
|
74 | 74 | thread.bump() |
|
75 | 75 | thread.last_edit_time = posting_time |
|
76 |
thread. |
|
|
76 | if thread.can_bump() and ( | |
|
77 | thread.get_reply_count() >= settings.MAX_POSTS_PER_THREAD): | |
|
78 | thread.bumpable = False | |
|
79 | thread.save(update_fields=['last_edit_time', 'bumpable']) | |
|
77 | 80 | new_thread = False |
|
78 | 81 | |
|
79 | 82 | post = self.create(title=title, |
@@ -101,6 +104,7 b' class PostManager(models.Manager):' | |||
|
101 | 104 | Thread.objects.process_oldest_threads() |
|
102 | 105 | self.connect_replies(post) |
|
103 | 106 | |
|
107 | ||
|
104 | 108 | return post |
|
105 | 109 | |
|
106 | 110 | def delete_post(self, post): |
@@ -414,4 +418,4 b' class Post(models.Model, Viewable):' | |||
|
414 | 418 | post_id = reply_number.group(1) |
|
415 | 419 | ref_post = Post.objects.filter(id=post_id)[0] |
|
416 | 420 | |
|
417 | ref_post.send_to_websocket(request, recursive=False) No newline at end of file | |
|
421 | ref_post.send_to_websocket(request, recursive=False) |
@@ -38,8 +38,9 b' class ThreadManager(models.Manager):' | |||
|
38 | 38 | |
|
39 | 39 | def _archive_thread(self, thread): |
|
40 | 40 | thread.archived = True |
|
41 | thread.bumpable = False | |
|
41 | 42 | thread.last_edit_time = timezone.now() |
|
42 | thread.save(update_fields=['archived', 'last_edit_time']) | |
|
43 | thread.save(update_fields=['archived', 'last_edit_time', 'bumpable']) | |
|
43 | 44 | |
|
44 | 45 | |
|
45 | 46 | class Thread(models.Model): |
@@ -54,6 +55,7 b' class Thread(models.Model):' | |||
|
54 | 55 | replies = models.ManyToManyField('Post', symmetrical=False, null=True, |
|
55 | 56 | blank=True, related_name='tre+') |
|
56 | 57 | archived = models.BooleanField(default=False) |
|
58 | bumpable = models.BooleanField(default=True) | |
|
57 | 59 | |
|
58 | 60 | def get_tags(self): |
|
59 | 61 | """ |
@@ -88,12 +90,7 b' class Thread(models.Model):' | |||
|
88 | 90 | Checks if the thread can be bumped by replying to it. |
|
89 | 91 | """ |
|
90 | 92 | |
|
91 |
|
|
|
92 | return False | |
|
93 | ||
|
94 | post_count = self.get_reply_count() | |
|
95 | ||
|
96 | return post_count < settings.MAX_POSTS_PER_THREAD | |
|
93 | return self.bumpable | |
|
97 | 94 | |
|
98 | 95 | def get_last_replies(self): |
|
99 | 96 | """ |
@@ -185,4 +182,4 b' class Thread(models.Model):' | |||
|
185 | 182 | if self.replies.exists(): |
|
186 | 183 | self.replies.all().delete() |
|
187 | 184 | |
|
188 | super(Thread, self).delete(using) No newline at end of file | |
|
185 | super(Thread, self).delete(using) |
@@ -50,7 +50,8 b' function connectWebsocket() {' | |||
|
50 | 50 | }); |
|
51 | 51 | |
|
52 | 52 | centrifuge.on('error', function(error_message) { |
|
53 |
|
|
|
53 | console.log("Error connecting to websocket server."); | |
|
54 | return false; | |
|
54 | 55 | }); |
|
55 | 56 | |
|
56 | 57 | centrifuge.on('connect', function() { |
@@ -68,6 +69,8 b' function connectWebsocket() {' | |||
|
68 | 69 | }); |
|
69 | 70 | |
|
70 | 71 | centrifuge.connect(); |
|
72 | ||
|
73 | return true; | |
|
71 | 74 | } |
|
72 | 75 | |
|
73 | 76 | function updatePost(postHtml, isAdded) { |
@@ -260,23 +263,23 b' function processNewPost(post) {' | |||
|
260 | 263 | |
|
261 | 264 | $(document).ready(function(){ |
|
262 | 265 | if ('WebSocket' in window) { |
|
263 |
initAutoupdate() |
|
|
266 | if (initAutoupdate()) { | |
|
267 | // Post form data over AJAX | |
|
268 | var threadId = $('div.thread').children('.post').first().attr('id'); | |
|
264 | 269 | |
|
265 | // Post form data over AJAX | |
|
266 | var threadId = $('div.thread').children('.post').first().attr('id'); | |
|
267 | ||
|
268 | var form = $('#form'); | |
|
270 | var form = $('#form'); | |
|
269 | 271 | |
|
270 | var options = { | |
|
271 | beforeSubmit: function(arr, $form, options) { | |
|
272 | showAsErrors($('form'), gettext('Sending message...')); | |
|
273 | }, | |
|
274 | success: updateOnPost, | |
|
275 | url: '/api/add_post/' + threadId + '/' | |
|
276 | }; | |
|
272 | var options = { | |
|
273 | beforeSubmit: function(arr, $form, options) { | |
|
274 | showAsErrors($('form'), gettext('Sending message...')); | |
|
275 | }, | |
|
276 | success: updateOnPost, | |
|
277 | url: '/api/add_post/' + threadId + '/' | |
|
278 | }; | |
|
277 | 279 | |
|
278 | form.ajaxForm(options); | |
|
280 | form.ajaxForm(options); | |
|
279 | 281 | |
|
280 | resetForm(form); | |
|
282 | resetForm(form); | |
|
283 | } | |
|
281 | 284 | } |
|
282 | 285 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now