diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-06-20 23:15:55 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-06-20 23:15:55 -0400 |
commit | 946d4f5fdabfe5bf74e33dae072085444c2c47d2 (patch) | |
tree | 4c6931d0e3945841040fc0bf19b5d7a5fb0799e2 | |
parent | 7134a8a516bdee8100572327c49771eec30bd256 (diff) | |
download | askbot-946d4f5fdabfe5bf74e33dae072085444c2c47d2.tar.gz askbot-946d4f5fdabfe5bf74e33dae072085444c2c47d2.tar.bz2 askbot-946d4f5fdabfe5bf74e33dae072085444c2c47d2.zip |
made loading of front page a little faster, commented out buggy code in models/__init__.py
-rw-r--r-- | askbot/bin/show_profile_stats.py | 14 | ||||
-rw-r--r-- | askbot/doc/source/index.rst | 2 | ||||
-rw-r--r-- | askbot/migrations/0016_auto__del_validationhash.py | 308 | ||||
-rw-r--r-- | askbot/models/__init__.py | 25 | ||||
-rw-r--r-- | askbot/models/question.py | 7 | ||||
-rw-r--r-- | askbot/models/user.py | 77 | ||||
-rw-r--r-- | askbot/utils/decorators.py | 49 | ||||
-rw-r--r-- | askbot/utils/time.py | 4 | ||||
-rw-r--r-- | askbot/views/readers.py | 1 |
9 files changed, 388 insertions, 99 deletions
diff --git a/askbot/bin/show_profile_stats.py b/askbot/bin/show_profile_stats.py new file mode 100644 index 00000000..ae31d49a --- /dev/null +++ b/askbot/bin/show_profile_stats.py @@ -0,0 +1,14 @@ +#!python +"""script for digesting profiling output +to profile functions, wrap them into decorator @profile('file_name.prof') + +source: http://code.djangoproject.com/wiki/ProfilingDjango +""" + +import hotshot.stats +import sys + +stats = hotshot.stats.load(sys.argv[1]) +#stats.strip_dirs() +stats.sort_stats('time', 'calls') +stats.print_stats(20) diff --git a/askbot/doc/source/index.rst b/askbot/doc/source/index.rst index 35b147fc..78ae333c 100644 --- a/askbot/doc/source/index.rst +++ b/askbot/doc/source/index.rst @@ -6,7 +6,7 @@ Code of Askbot grew out of CNPROG_ project originally written by `Mike Chen <http://cn.linkedin.com/in/mikegangchen>`_ and Sailing Cai. If you have any questions installing or tweaking askbot - please do not hesitate to ask -at the forum_ or email to admin@askbot.org. +at the forum_ or by email at admin@askbot.org. Prerequisites ====================== diff --git a/askbot/migrations/0016_auto__del_validationhash.py b/askbot/migrations/0016_auto__del_validationhash.py new file mode 100644 index 00000000..d0039688 --- /dev/null +++ b/askbot/migrations/0016_auto__del_validationhash.py @@ -0,0 +1,308 @@ +# encoding: 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): + + # Deleting model 'ValidationHash' + db.delete_table('askbot_validationhash') + + + def backwards(self, orm): + + # Adding model 'ValidationHash' + db.create_table('askbot_validationhash', ( + ('hash_code', self.gf('django.db.models.fields.CharField')(max_length=255, unique=True)), + ('seed', self.gf('django.db.models.fields.CharField')(max_length=12)), + ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])), + ('type', self.gf('django.db.models.fields.CharField')(max_length=12)), + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('expiration', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime(2010, 6, 13, 23, 48, 5, 784060))), + )) + db.send_create_signal('askbot', ['ValidationHash']) + + + models = { + 'askbot.activity': { + 'Meta': {'object_name': 'Activity', 'db_table': "u'activity'"}, + 'active_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'activity_type': ('django.db.models.fields.SmallIntegerField', [], {}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_auditted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'receiving_users': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'received_activity'", 'to': "orm['auth.User']"}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) + }, + 'askbot.anonymousanswer': { + 'Meta': {'object_name': 'AnonymousAnswer'}, + 'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip_addr': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}), + 'question': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'anonymous_answers'", 'to': "orm['askbot.Question']"}), + 'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40'}), + 'summary': ('django.db.models.fields.CharField', [], {'max_length': '180'}), + 'text': ('django.db.models.fields.TextField', [], {}), + 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}) + }, + 'askbot.anonymousquestion': { + 'Meta': {'object_name': 'AnonymousQuestion'}, + 'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip_addr': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}), + 'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40'}), + 'summary': ('django.db.models.fields.CharField', [], {'max_length': '180'}), + 'tagnames': ('django.db.models.fields.CharField', [], {'max_length': '125'}), + 'text': ('django.db.models.fields.TextField', [], {}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '300'}), + 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}) + }, + 'askbot.answer': { + 'Meta': {'object_name': 'Answer', 'db_table': "u'answer'"}, + 'accepted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'accepted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'answers'", 'to': "orm['auth.User']"}), + 'comment_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'deleted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'deleted_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'deleted_answers'", 'null': 'True', 'to': "orm['auth.User']"}), + 'html': ('django.db.models.fields.TextField', [], {'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_edited_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'last_edited_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'last_edited_answers'", 'null': 'True', 'to': "orm['auth.User']"}), + 'locked': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'locked_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'locked_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locked_answers'", 'null': 'True', 'to': "orm['auth.User']"}), + 'offensive_flag_count': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'question': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'answers'", 'to': "orm['askbot.Question']"}), + 'score': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'text': ('django.db.models.fields.TextField', [], {'null': 'True'}), + 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + }, + 'askbot.answerrevision': { + 'Meta': {'object_name': 'AnswerRevision', 'db_table': "u'answer_revision'"}, + 'answer': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'revisions'", 'to': "orm['askbot.Answer']"}), + 'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'answerrevisions'", 'to': "orm['auth.User']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'revised_at': ('django.db.models.fields.DateTimeField', [], {}), + 'revision': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'summary': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), + 'text': ('django.db.models.fields.TextField', [], {}) + }, + 'askbot.award': { + 'Meta': {'object_name': 'Award', 'db_table': "u'award'"}, + 'awarded_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'badge': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'award_badge'", 'to': "orm['askbot.Badge']"}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'notified': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'award_user'", 'to': "orm['auth.User']"}) + }, + 'askbot.badge': { + 'Meta': {'unique_together': "(('name', 'type'),)", 'object_name': 'Badge', 'db_table': "u'badge'"}, + 'awarded_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), + 'awarded_to': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'badges'", 'through': "'Award'", 'to': "orm['auth.User']"}), + 'description': ('django.db.models.fields.CharField', [], {'max_length': '300'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'multiple': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}), + 'slug': ('django.db.models.fields.SlugField', [], {'db_index': 'True', 'max_length': '50', 'blank': 'True'}), + 'type': ('django.db.models.fields.SmallIntegerField', [], {}) + }, + 'askbot.comment': { + 'Meta': {'object_name': 'Comment', 'db_table': "u'comment'"}, + 'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'comment': ('django.db.models.fields.CharField', [], {'max_length': '2048'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'html': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '2048'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'comments'", 'to': "orm['auth.User']"}) + }, + 'askbot.emailfeedsetting': { + 'Meta': {'object_name': 'EmailFeedSetting'}, + 'added_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'feed_type': ('django.db.models.fields.CharField', [], {'max_length': '16'}), + 'frequency': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '8'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'reported_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), + 'subscriber': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'notification_subscriptions'", 'to': "orm['auth.User']"}) + }, + 'askbot.favoritequestion': { + 'Meta': {'object_name': 'FavoriteQuestion', 'db_table': "u'favorite_question'"}, + 'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'question': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Question']"}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'user_favorite_questions'", 'to': "orm['auth.User']"}) + }, + 'askbot.flaggeditem': { + 'Meta': {'unique_together': "(('content_type', 'object_id', 'user'),)", 'object_name': 'FlaggedItem', 'db_table': "u'flagged_item'"}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'flagged_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'flaggeditems'", 'to': "orm['auth.User']"}) + }, + 'askbot.markedtag': { + 'Meta': {'object_name': 'MarkedTag'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'reason': ('django.db.models.fields.CharField', [], {'max_length': '16'}), + 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'user_selections'", 'to': "orm['askbot.Tag']"}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'tag_selections'", 'to': "orm['auth.User']"}) + }, + 'askbot.question': { + 'Meta': {'object_name': 'Question', 'db_table': "u'question'"}, + 'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'answer_accepted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'answer_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), + 'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'questions'", 'to': "orm['auth.User']"}), + 'close_reason': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'closed': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'closed_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'closed_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'closed_questions'", 'null': 'True', 'to': "orm['auth.User']"}), + 'comment_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'deleted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'deleted_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'deleted_questions'", 'null': 'True', 'to': "orm['auth.User']"}), + 'favorited_by': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'favorite_questions'", 'through': "'FavoriteQuestion'", 'to': "orm['auth.User']"}), + 'favourite_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), + 'followed_by': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'followed_questions'", 'to': "orm['auth.User']"}), + 'html': ('django.db.models.fields.TextField', [], {'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_activity_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_activity_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'last_active_in_questions'", 'to': "orm['auth.User']"}), + 'last_edited_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'last_edited_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'last_edited_questions'", 'null': 'True', 'to': "orm['auth.User']"}), + 'locked': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'locked_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'locked_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locked_questions'", 'null': 'True', 'to': "orm['auth.User']"}), + 'offensive_flag_count': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'score': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'summary': ('django.db.models.fields.CharField', [], {'max_length': '180'}), + 'tagnames': ('django.db.models.fields.CharField', [], {'max_length': '125'}), + 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'questions'", 'to': "orm['askbot.Tag']"}), + 'text': ('django.db.models.fields.TextField', [], {'null': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '300'}), + 'view_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), + 'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + }, + 'askbot.questionrevision': { + 'Meta': {'object_name': 'QuestionRevision', 'db_table': "u'question_revision'"}, + 'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'questionrevisions'", 'to': "orm['auth.User']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'question': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'revisions'", 'to': "orm['askbot.Question']"}), + 'revised_at': ('django.db.models.fields.DateTimeField', [], {}), + 'revision': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'summary': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), + 'tagnames': ('django.db.models.fields.CharField', [], {'max_length': '125'}), + 'text': ('django.db.models.fields.TextField', [], {}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '300'}) + }, + 'askbot.questionview': { + 'Meta': {'object_name': 'QuestionView'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'question': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'viewed'", 'to': "orm['askbot.Question']"}), + 'when': ('django.db.models.fields.DateTimeField', [], {}), + 'who': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'question_views'", 'to': "orm['auth.User']"}) + }, + 'askbot.repute': { + 'Meta': {'object_name': 'Repute', 'db_table': "u'repute'"}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'negative': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'positive': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'question': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Question']"}), + 'reputation': ('django.db.models.fields.IntegerField', [], {'default': '1'}), + 'reputation_type': ('django.db.models.fields.SmallIntegerField', [], {}), + 'reputed_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) + }, + 'askbot.tag': { + 'Meta': {'object_name': 'Tag', 'db_table': "u'tag'"}, + 'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'created_tags'", 'to': "orm['auth.User']"}), + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'deleted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'deleted_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'deleted_tags'", 'null': 'True', 'to': "orm['auth.User']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), + 'used_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}) + }, + 'askbot.vote': { + 'Meta': {'unique_together': "(('content_type', 'object_id', 'user'),)", 'object_name': 'Vote', 'db_table': "u'vote'"}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'votes'", 'to': "orm['auth.User']"}), + 'vote': ('django.db.models.fields.SmallIntegerField', [], {}), + 'voted_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}) + }, + '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']", 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'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'}, + 'about': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'bronze': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'email_isvalid': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'email_key': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'gold': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'gravatar': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'blank': 'True'}), + 'hide_ignored_questions': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}), + 'is_approved': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'last_seen': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'questions_per_page': ('django.db.models.fields.SmallIntegerField', [], {'default': '10'}), + 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'reputation': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}), + 'response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'silver': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'tag_filter_setting': ('django.db.models.fields.CharField', [], {'default': "'ignored'", 'max_length': '16'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}), + 'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'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'}) + } + } + + complete_apps = ['askbot'] diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 3f3a8b07..bbda9773 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -22,7 +22,7 @@ from askbot.models.question import FavoriteQuestion from askbot.models.answer import Answer, AnonymousAnswer, AnswerRevision from askbot.models.tag import Tag, MarkedTag from askbot.models.meta import Vote, Comment, FlaggedItem -from askbot.models.user import Activity, ValidationHash, EmailFeedSetting +from askbot.models.user import Activity, EmailFeedSetting from askbot.models import signals #from user import AuthKeyUserAssociation from askbot.models.repute import Badge, Award, Repute @@ -383,18 +383,19 @@ def record_post_update_activity( user.save() #todo: weird thing is that only comments need the receiving_users + #todo: debug these calls and then uncomment in the repo #argument to this call - notification_subscribers = post.get_instant_notification_subscribers( - potential_subscribers = receiving_users, - mentioned_users = newly_mentioned_users, - exclude_list = [updated_by, ] - ) + #notification_subscribers = post.get_instant_notification_subscribers( + # potential_subscribers = receiving_users, + # mentioned_users = newly_mentioned_users, + # exclude_list = [updated_by, ] + # ) - send_instant_notifications_about_activity_in_post( - update_activity = update_activity, - post = post, - receiving_users = notification_subscribers, - ) + #send_instant_notifications_about_activity_in_post( + # update_activity = update_activity, + # post = post, + # receiving_users = notification_subscribers, + # ) def record_award_event(instance, created, **kwargs): @@ -661,7 +662,6 @@ Repute = Repute Activity = Activity EmailFeedSetting = EmailFeedSetting -ValidationHash = ValidationHash #AuthKeyUserAssociation = AuthKeyUserAssociation __all__ = [ @@ -689,7 +689,6 @@ __all__ = [ 'Activity', 'EmailFeedSetting', - 'ValidationHash', #'AuthKeyUserAssociation', 'User', diff --git a/askbot/models/question.py b/askbot/models/question.py index 31a82e0f..f75b87b6 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -172,7 +172,7 @@ class QuestionManager(models.Manager): meta_data['interesting_tag_names'] = pt.filter(reason='good').values_list('tag__name', flat=True) meta_data['ignored_tag_names'] = pt.filter(reason='bad').values_list('tag__name', flat=True) - qs = qs.select_related(depth=1) + #qs = qs.select_related(depth=1) #todo: fix orderby here orderby = QUESTION_ORDER_BY_MAP[sort_method] if orderby: @@ -187,9 +187,8 @@ class QuestionManager(models.Manager): def get_question_and_answer_contributors(self, question_list): answer_list = [] question_list = list(question_list)#important for MySQL, b/c it does not support - #the query in return statement below - for q in question_list: - answer_list.extend(list(q.answers.all())) + from askbot.models.answer import Answer + answer_list = Answer.objects.filter(question__in = question_list) contributors = User.objects.filter( models.Q(questions__in=question_list) \ | models.Q(answers__in=answer_list) diff --git a/askbot/models/user.py b/askbot/models/user.py index d06c4ed2..5fe18858 100644 --- a/askbot/models/user.py +++ b/askbot/models/user.py @@ -253,83 +253,6 @@ class EmailFeedSetting(models.Model): class Meta: app_label = 'askbot' -from askbot.utils.time import one_day_from_now - -class ValidationHashManager(models.Manager): - def _generate_md5_hash(self, user, type, hash_data, seed): - return md5( - "%s%s%s%s" % ( - seed, - "".join(map(str, hash_data)), - user.id, - type - ) - ).hexdigest() - - def create_new(self, user, type, hash_data=[], expiration=None): - seed = ''.join(Random().sample(string.letters+string.digits, 12)) - hash = self._generate_md5_hash(user, type, hash_data, seed) - - obj = ValidationHash(hash_code=hash, seed=seed, user=user, type=type) - - if expiration is not None: - obj.expiration = expiration - - try: - obj.save() - except: - return None - - return obj - - def validate(self, hash, user, type, hash_data=[]): - try: - obj = self.get(hash_code=hash) - except: - return False - - if obj.type != type: - return False - - if obj.user != user: - return False - - valid = (obj.hash_code == self._generate_md5_hash( - obj.user, - type, - hash_data, - obj.seed - ) - ) - - if valid: - if obj.expiration < datetime.datetime.now(): - obj.delete() - return False - else: - obj.delete() - return True - - return False - -class ValidationHash(models.Model): - #todo: was 256 chars - is that important? - #on mysql 255 is max for unique=True - hash_code = models.CharField(max_length=255,unique=True) - seed = models.CharField(max_length=12) - expiration = models.DateTimeField(default=one_day_from_now) - type = models.CharField(max_length=12) - user = models.ForeignKey(User) - - objects = ValidationHashManager() - - class Meta: - unique_together = ('user', 'type') - app_label = 'askbot' - - def __str__(self): - return self.hash_code - #class AuthKeyUserAssociation(models.Model): # key = models.CharField(max_length=255,null=False,unique=True) # provider = models.CharField(max_length=64)#string 'yahoo', 'google', etc. diff --git a/askbot/utils/decorators.py b/askbot/utils/decorators.py index 440e8312..0ecf24e8 100644 --- a/askbot/utils/decorators.py +++ b/askbot/utils/decorators.py @@ -1,6 +1,11 @@ +import hotshot +import time +import os +from django.conf import settings from django.http import HttpResponse, HttpResponseForbidden, Http404 from django.utils import simplejson + def ajax_login_required(view_func): def wrap(request,*args,**kwargs): if request.user.is_authenticated(): @@ -10,6 +15,7 @@ def ajax_login_required(view_func): return HttpResponseForbidden(json,mimetype='application/json') return wrap + def ajax_method(view_func): def wrap(request,*args,**kwargs): if not request.is_ajax(): @@ -22,3 +28,46 @@ def ajax_method(view_func): json = simplejson.dumps(retval) return HttpResponse(json,mimetype='application/json') return wrap + +try: + PROFILE_LOG_BASE = settings.PROFILE_LOG_BASE +except: + PROFILE_LOG_BASE = "/tmp" + + +def profile(log_file): + """Profile some callable. + + This decorator uses the hotshot profiler to profile some callable (like + a view function or method) and dumps the profile data somewhere sensible + for later processing and examination. + + It takes one argument, the profile log name. If it's a relative path, it + places it under the PROFILE_LOG_BASE. It also inserts a time stamp into the + file name, such that 'my_view.prof' become 'my_view-20100211T170321.prof', + where the time stamp is in UTC. This makes it easy to run and compare + multiple trials. + + http://code.djangoproject.com/wiki/ProfilingDjango + """ + + if not os.path.isabs(log_file): + log_file = os.path.join(PROFILE_LOG_BASE, log_file) + + def _outer(f): + def _inner(*args, **kwargs): + # Add a timestamp to the profile output when the callable + # is actually called. + (base, ext) = os.path.splitext(log_file) + base = base + "-" + time.strftime("%Y%m%dT%H%M%S", time.gmtime()) + final_log_file = base + ext + + prof = hotshot.Profile(final_log_file) + try: + ret = prof.runcall(f, *args, **kwargs) + finally: + prof.close() + return ret + + return _inner + return _outer diff --git a/askbot/utils/time.py b/askbot/utils/time.py deleted file mode 100644 index 39e01d0f..00000000 --- a/askbot/utils/time.py +++ /dev/null @@ -1,4 +0,0 @@ -import datetime - -def one_day_from_now(): - return datetime.datetime.now() + datetime.timedelta(days=1) diff --git a/askbot/views/readers.py b/askbot/views/readers.py index f719fd4f..07390289 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -25,6 +25,7 @@ from askbot import const from askbot import auth from askbot.utils.forms import get_next_url from askbot.utils.functions import not_a_robot_request +from askbot.utils.decorators import profile from askbot.search.state_manager import SearchState # used in index page |