diff --git a/deploy/media/css/spc-extend.css b/deploy/media/css/spc-extend.css index 0790a2c..5ce540b 100644 --- a/deploy/media/css/spc-extend.css +++ b/deploy/media/css/spc-extend.css @@ -17,6 +17,9 @@ body { .pointer { cursor: pointer; } +.block-inline { + display: inline-block; +} .header { padding-top: 15px; padding-bottom: 15px; @@ -32,6 +35,9 @@ body { .pointer { cursor: pointer; } +.block-inline { + display: inline-block; +} .tags .btn { border: none; font-size: 9.5px; @@ -85,6 +91,54 @@ body { #spc-comment-edit-modal .tab-content { min-height: 228px; } +.up-arrow { + width: 0; + height: 0; + color: #999999; + border-top: 0px solid; + border-bottom: 15px solid; + border-left: 18px solid transparent; + border-right: 18px solid transparent; + marign: 0 auto; + margin-bottom: 3px; +} +.up-arrow.active { + color: #f59d18; +} +.up-arrow-comment { + width: 0; + height: 0; + color: #999999; + border-top: 0px solid; + border-bottom: 8px solid; + border-left: 6px solid transparent; + border-right: 6px solid transparent; +} +.up-arrow-comment.active { + color: #f59d18; +} +.down-arrow { + width: 0; + height: 0; + color: #999999; + border-top: 15px solid; + border-bottom: 0px solid; + border-left: 18px solid transparent; + border-right: 18px solid transparent; + marign: 0 auto; + margin-top: 3px; +} +.down-arrow.active { + color: #f59d18; +} +#spc-comment-list .vote-count { + font-size: 11px; +} +.reputation { + font-weight: bold; + font-size: 18px; + color: #555555; +} .spc-rightsidebar { color: #555555; padding: 2px 10px; diff --git a/deploy/media/js/spc-extend.js b/deploy/media/js/spc-extend.js new file mode 100644 index 0000000..27f02c6 --- /dev/null +++ b/deploy/media/js/spc-extend.js @@ -0,0 +1,9 @@ +$('body').on('click', function (e) { + $('.spc-popover').each(function () { + //the 'is' for buttons that triggers popups + //the 'has' for icons within a button that triggers a popup + if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) { + $(this).popover('hide'); + } + }); +}); diff --git a/deploy/media/less/spc-content.less b/deploy/media/less/spc-content.less index 269d868..bfa3159 100644 --- a/deploy/media/less/spc-content.less +++ b/deploy/media/less/spc-content.less @@ -78,3 +78,52 @@ min-height: 228px; } } + +// thumbs (reputation) arrows +.arrow (@top, @bottom, @left, @right) { + width: 0; + height:0; + color: @grayLight; + border-top: @top solid; + border-bottom: @bottom solid; + border-left: @left solid transparent; + border-right: @right solid transparent; +} + +.up-arrow { + .arrow(0px, 15px, 18px, 18px); + marign: 0 auto; + margin-bottom: 3px; + &.active { + color: rgb(245, 157, 24); + } +} + + +.up-arrow-comment { + .arrow(0px, 8px, 6px, 6px); + &.active { + color: rgb(245, 157, 24); + } +} + +.down-arrow { + .arrow(15px, 0px, 18px, 18px); + marign: 0 auto; + margin-top: 3px; + &.active { + color: rgb(245, 157, 24); + } +} + +#spc-comment-list { + .vote-count { + font-size: 11px; + } +} + +.reputation { + font-weight: bold; + font-size: 18px; + color: @gray; +} diff --git a/deploy/media/less/spc-utils.less b/deploy/media/less/spc-utils.less index 5c05dfa..67ad22a 100644 --- a/deploy/media/less/spc-utils.less +++ b/deploy/media/less/spc-utils.less @@ -26,3 +26,7 @@ .pointer { cursor: pointer; } + +.block-inline { + display: inline-block; +} diff --git a/deploy/settings.py b/deploy/settings.py index 1d47e5b..c769b70 100644 --- a/deploy/settings.py +++ b/deploy/settings.py @@ -159,6 +159,7 @@ 'scipy_central.screenshot', 'scipy_central.pagehit', 'scipy_central.feeds', + 'scipy_central.thumbs', ) # Custom comments App diff --git a/deploy/templates/base.html b/deploy/templates/base.html index 8d3e42c..9322eb1 100644 --- a/deploy/templates/base.html +++ b/deploy/templates/base.html @@ -98,6 +98,7 @@ {% include "base-includes/footer-outside.html" %} + diff --git a/deploy/templates/search/includes/one-search-result.html b/deploy/templates/search/includes/one-search-result.html index 1f18d37..b2a9250 100644 --- a/deploy/templates/search/includes/one-search-result.html +++ b/deploy/templates/search/includes/one-search-result.html @@ -2,18 +2,20 @@ {% if entry %} {% load comments %} -
  • - +
    +

    {{ entry.title}} @@ -36,6 +38,6 @@

  • on {{ entry.date_created|date:"d F Y"}}
  • -
  • +
    {% endif %} diff --git a/scipy_central/comments/admin.py b/scipy_central/comments/admin.py index 65d262d..d202dc7 100644 --- a/scipy_central/comments/admin.py +++ b/scipy_central/comments/admin.py @@ -16,7 +16,8 @@ class SpcCommentAdmin(CommentsAdmin): {'fields': ('content_type', 'object_pk', 'site')} ), (_('Content'), - {'fields': ('user', 'user_name', 'user_email', 'user_url', 'comment', 'rest_comment')} + {'fields': ('user', 'user_name', 'user_email', 'user_url', 'comment', + 'rest_comment', 'reputation',)} ), (_('Metadata'), {'fields': ('submit_date', 'ip_address', 'is_public', 'is_removed')} diff --git a/scipy_central/comments/migrations/0001_initial.py b/scipy_central/comments/migrations/0001_initial.py new file mode 100644 index 0000000..210c435 --- /dev/null +++ b/scipy_central/comments/migrations/0001_initial.py @@ -0,0 +1,150 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding model 'Comment' + db.create_table('django_comments', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('content_type', self.gf('django.db.models.fields.related.ForeignKey')(related_name='content_type_set_for_comment', to=orm['contenttypes.ContentType'])), + ('object_pk', self.gf('django.db.models.fields.TextField')()), + ('site', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['sites.Site'])), + ('user', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='comment_comments', null=True, to=orm['auth.User'])), + ('user_name', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)), + ('user_email', self.gf('django.db.models.fields.EmailField')(max_length=75, blank=True)), + ('user_url', self.gf('django.db.models.fields.URLField')(max_length=200, blank=True)), + ('comment', self.gf('django.db.models.fields.TextField')(max_length=3000)), + ('submit_date', self.gf('django.db.models.fields.DateTimeField')(default=None)), + ('ip_address', self.gf('django.db.models.fields.IPAddressField')(max_length=15, null=True, blank=True)), + ('is_public', self.gf('django.db.models.fields.BooleanField')(default=True)), + ('is_removed', self.gf('django.db.models.fields.BooleanField')(default=False)), + )) + db.send_create_signal('comments', ['Comment']) + + # Adding model 'CommentFlag' + db.create_table('django_comment_flags', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='comment_flags', to=orm['auth.User'])), + ('comment', self.gf('django.db.models.fields.related.ForeignKey')(related_name='flags', to=orm['comments.Comment'])), + ('flag', self.gf('django.db.models.fields.CharField')(max_length=30, db_index=True)), + ('flag_date', self.gf('django.db.models.fields.DateTimeField')(default=None)), + )) + db.send_create_signal('comments', ['CommentFlag']) + + # Adding unique constraint on 'CommentFlag', fields ['user', 'comment', 'flag'] + db.create_unique('django_comment_flags', ['user_id', 'comment_id', 'flag']) + + # Adding model 'SpcComment' + db.create_table('comments_spccomment', ( + ('comment_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['comments.Comment'], unique=True, primary_key=True)), + ('rest_comment', self.gf('django.db.models.fields.TextField')(max_length=3000, null=True)), + )) + db.send_create_signal('comments', ['SpcComment']) + + + def backwards(self, orm): + # Removing unique constraint on 'CommentFlag', fields ['user', 'comment', 'flag'] + db.delete_unique('django_comment_flags', ['user_id', 'comment_id', 'flag']) + + # Deleting model 'Comment' + db.delete_table('django_comments') + + # Deleting model 'CommentFlag' + db.delete_table('django_comment_flags') + + # Deleting model 'SpcComment' + db.delete_table('comments_spccomment') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'comments.comment': { + 'Meta': {'ordering': "('submit_date',)", 'object_name': 'Comment', 'db_table': "'django_comments'"}, + 'comment': ('django.db.models.fields.TextField', [], {'max_length': '3000'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'content_type_set_for_comment'", 'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}), + 'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_removed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'object_pk': ('django.db.models.fields.TextField', [], {}), + 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}), + 'submit_date': ('django.db.models.fields.DateTimeField', [], {'default': 'None'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'comment_comments'", 'null': 'True', 'to': "orm['auth.User']"}), + 'user_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'user_name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}), + 'user_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) + }, + 'comments.commentflag': { + 'Meta': {'unique_together': "[('user', 'comment', 'flag')]", 'object_name': 'CommentFlag', 'db_table': "'django_comment_flags'"}, + 'comment': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'flags'", 'to': "orm['comments.Comment']"}), + 'flag': ('django.db.models.fields.CharField', [], {'max_length': '30', 'db_index': 'True'}), + 'flag_date': ('django.db.models.fields.DateTimeField', [], {'default': 'None'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'comment_flags'", 'to': "orm['auth.User']"}) + }, + 'comments.spccomment': { + 'Meta': {'ordering': "('submit_date',)", 'object_name': 'SpcComment', '_ormbases': ['comments.Comment']}, + 'comment_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['comments.Comment']", 'unique': 'True', 'primary_key': 'True'}), + 'rest_comment': ('django.db.models.fields.TextField', [], {'max_length': '3000', 'null': 'True'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'sites.site': { + 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"}, + 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'thumbs.thumbs': { + 'Meta': {'unique_together': "(('person', 'content_type', 'object_pk'),)", 'object_name': 'Thumbs'}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'content_type_set_for_thumbs'", 'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}), + 'is_valid': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'object_pk': ('django.db.models.fields.TextField', [], {}), + 'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'submit_date': ('django.db.models.fields.DateField', [], {'auto_now': 'True', 'blank': 'True'}), + 'user_agent': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'vote': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['comments'] \ No newline at end of file diff --git a/scipy_central/comments/migrations/0002_auto__add_field_spccomment_reputation.py b/scipy_central/comments/migrations/0002_auto__add_field_spccomment_reputation.py new file mode 100644 index 0000000..687eb6f --- /dev/null +++ b/scipy_central/comments/migrations/0002_auto__add_field_spccomment_reputation.py @@ -0,0 +1,109 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'SpcComment.reputation' + db.add_column('comments_spccomment', 'reputation', + self.gf('django.db.models.fields.IntegerField')(default=0), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'SpcComment.reputation' + db.delete_column('comments_spccomment', 'reputation') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'comments.comment': { + 'Meta': {'ordering': "('submit_date',)", 'object_name': 'Comment', 'db_table': "'django_comments'"}, + 'comment': ('django.db.models.fields.TextField', [], {'max_length': '3000'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'content_type_set_for_comment'", 'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}), + 'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_removed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'object_pk': ('django.db.models.fields.TextField', [], {}), + 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}), + 'submit_date': ('django.db.models.fields.DateTimeField', [], {'default': 'None'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'comment_comments'", 'null': 'True', 'to': "orm['auth.User']"}), + 'user_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'user_name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}), + 'user_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) + }, + 'comments.commentflag': { + 'Meta': {'unique_together': "[('user', 'comment', 'flag')]", 'object_name': 'CommentFlag', 'db_table': "'django_comment_flags'"}, + 'comment': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'flags'", 'to': "orm['comments.Comment']"}), + 'flag': ('django.db.models.fields.CharField', [], {'max_length': '30', 'db_index': 'True'}), + 'flag_date': ('django.db.models.fields.DateTimeField', [], {'default': 'None'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'comment_flags'", 'to': "orm['auth.User']"}) + }, + 'comments.spccomment': { + 'Meta': {'ordering': "('submit_date',)", 'object_name': 'SpcComment', '_ormbases': ['comments.Comment']}, + 'comment_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['comments.Comment']", 'unique': 'True', 'primary_key': 'True'}), + 'reputation': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'rest_comment': ('django.db.models.fields.TextField', [], {'max_length': '3000', 'null': 'True'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'sites.site': { + 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"}, + 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'thumbs.thumbs': { + 'Meta': {'unique_together': "(('person', 'content_type', 'object_pk'),)", 'object_name': 'Thumbs'}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'content_type_set_for_thumbs'", 'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}), + 'is_valid': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'object_pk': ('django.db.models.fields.TextField', [], {}), + 'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'submit_date': ('django.db.models.fields.DateField', [], {'auto_now': 'True', 'blank': 'True'}), + 'user_agent': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'vote': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['comments'] \ No newline at end of file diff --git a/scipy_central/comments/migrations/0003_auto__add_field_spccomment_enable_reputation.py b/scipy_central/comments/migrations/0003_auto__add_field_spccomment_enable_reputation.py new file mode 100644 index 0000000..a2bbe40 --- /dev/null +++ b/scipy_central/comments/migrations/0003_auto__add_field_spccomment_enable_reputation.py @@ -0,0 +1,110 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'SpcComment.enable_reputation' + db.add_column('comments_spccomment', 'enable_reputation', + self.gf('django.db.models.fields.BooleanField')(default=True), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'SpcComment.enable_reputation' + db.delete_column('comments_spccomment', 'enable_reputation') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + 'comments.comment': { + 'Meta': {'ordering': "('submit_date',)", 'object_name': 'Comment', 'db_table': "'django_comments'"}, + 'comment': ('django.db.models.fields.TextField', [], {'max_length': '3000'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'content_type_set_for_comment'", 'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}), + 'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_removed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'object_pk': ('django.db.models.fields.TextField', [], {}), + 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}), + 'submit_date': ('django.db.models.fields.DateTimeField', [], {'default': 'None'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'comment_comments'", 'null': 'True', 'to': "orm['auth.User']"}), + 'user_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'user_name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}), + 'user_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) + }, + 'comments.commentflag': { + 'Meta': {'unique_together': "[('user', 'comment', 'flag')]", 'object_name': 'CommentFlag', 'db_table': "'django_comment_flags'"}, + 'comment': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'flags'", 'to': "orm['comments.Comment']"}), + 'flag': ('django.db.models.fields.CharField', [], {'max_length': '30', 'db_index': 'True'}), + 'flag_date': ('django.db.models.fields.DateTimeField', [], {'default': 'None'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'comment_flags'", 'to': "orm['auth.User']"}) + }, + 'comments.spccomment': { + 'Meta': {'ordering': "('submit_date',)", 'object_name': 'SpcComment', '_ormbases': ['comments.Comment']}, + 'comment_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['comments.Comment']", 'unique': 'True', 'primary_key': 'True'}), + 'enable_reputation': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'reputation': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'rest_comment': ('django.db.models.fields.TextField', [], {'max_length': '3000', 'null': 'True'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'sites.site': { + 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"}, + 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'thumbs.thumbs': { + 'Meta': {'unique_together': "(('person', 'content_type', 'object_pk'),)", 'object_name': 'Thumbs'}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'content_type_set_for_thumbs'", 'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip_address': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}), + 'is_valid': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'object_pk': ('django.db.models.fields.TextField', [], {}), + 'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'submit_date': ('django.db.models.fields.DateField', [], {'auto_now': 'True', 'blank': 'True'}), + 'user_agent': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'vote': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['comments'] \ No newline at end of file diff --git a/scipy_central/comments/migrations/__init__.py b/scipy_central/comments/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scipy_central/comments/models.py b/scipy_central/comments/models.py index 5f68a1f..abdc546 100644 --- a/scipy_central/comments/models.py +++ b/scipy_central/comments/models.py @@ -1,9 +1,13 @@ from django.db import models from django.contrib.comments.models import Comment +from django.contrib.contenttypes import generic from django.utils.translation import ugettext_lazy as _ from django.conf import settings +from scipy_central.thumbs.models import Thumbs +from scipy_central.thumbs import scale + COMMENT_MAX_LENGTH = getattr(settings, 'COMMENT_MAX_LENGTH', 3000) class SpcComment(Comment): @@ -14,3 +18,43 @@ class SpcComment(Comment): rest_comment = models.TextField(_('rest_comment'), max_length=COMMENT_MAX_LENGTH, null = True) + + thumbs = generic.GenericRelation(Thumbs, + content_type_field='content_type', + object_id_field='object_pk') + + # aggregate reputation of `thumbs` + reputation = models.IntegerField(default=0) + + # users can vote if set to True + enable_reputation = models.BooleanField(default=True) + + def set_reputation(self): + """ + Calculate total reputation for the object. + Only needed when `scale` is changed + """ + score = 0 + for aThumb in self.thumbs.all().filter(is_valid=True).exclude(vote=None): + score += scale.COMMENT_VOTE['thumb']['up'] + return score + + def calculate_reputation(self, vote, prev_vote): + """ + Please refer to `scipy_central.submission.models.Revision` + `calculate_reputation` method doc string + + Arguments: + `vote`: True or None + (comments does not have down-voting. `False` is thus not taken) + `prev_vote`: True or None + (This argument is not really requied but helps to validate) + Returns: + updated reputation value (int) + """ + rept = self.reputation + if vote == True and prev_vote == None: + rept += scale.COMMENT_VOTE['thumb']['up'] + elif vote == None and prev_vote == True: + rept -= scale.COMMENT_VOTE['thumb']['up'] + return rept diff --git a/scipy_central/comments/templates/comments/comment.html b/scipy_central/comments/templates/comments/comment.html index 7ce06be..0083a0d 100644 --- a/scipy_central/comments/templates/comments/comment.html +++ b/scipy_central/comments/templates/comments/comment.html @@ -11,6 +11,7 @@