Better looking tweets
authorCharles Connell <charles@connells.org>
Fri, 3 Jan 2014 15:18:06 +0000 (10:18 -0500)
committerCharles Connell <charles@connells.org>
Fri, 3 Jan 2014 17:18:54 +0000 (12:18 -0500)
karmaworld/apps/courses/migrations/0004_auto__add_field_school_hashtag.py [new file with mode: 0644]
karmaworld/apps/courses/models.py
karmaworld/apps/notes/tasks.py

diff --git a/karmaworld/apps/courses/migrations/0004_auto__add_field_school_hashtag.py b/karmaworld/apps/courses/migrations/0004_auto__add_field_school_hashtag.py
new file mode 100644 (file)
index 0000000..9981b72
--- /dev/null
@@ -0,0 +1,55 @@
+# -*- 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 'School.hashtag'
+        db.add_column('courses_school', 'hashtag',
+                      self.gf('django.db.models.fields.CharField')(max_length=16, null=True, blank=True),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'School.hashtag'
+        db.delete_column('courses_school', 'hashtag')
+
+
+    models = {
+        'courses.course': {
+            'Meta': {'ordering': "['-file_count', 'school', 'name']", 'unique_together': "(('school', 'name', 'instructor_name'),)", 'object_name': 'Course'},
+            'academic_year': ('django.db.models.fields.IntegerField', [], {'default': '2014', 'null': 'True', 'blank': 'True'}),
+            'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'desc': ('django.db.models.fields.TextField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}),
+            'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'flags': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'instructor_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+            'instructor_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'school': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.School']"}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}),
+            'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'})
+        },
+        'courses.school': {
+            'Meta': {'ordering': "['-file_count', '-priority', 'name']", 'object_name': 'School'},
+            'alias': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'facebook_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'hashtag': ('django.db.models.fields.CharField', [], {'max_length': '16', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'location': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'priority': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'blank': 'True'}),
+            'usde_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['courses']
\ No newline at end of file
index c2ae9531fc105ea333d859ab2f615c1f271ec838..d18e7d65a8ee86572568f560727ea28d3e6a7a59 100644 (file)
@@ -28,6 +28,7 @@ class School(models.Model):
     file_count  = models.IntegerField(default=0)
     priority    = models.BooleanField(default=0)
     alias       = models.CharField(max_length=255, null=True, blank=True)
+    hashtag     = models.CharField(max_length=16, null=True, blank=True, help_text='School abbreviation without #')
 
     class Meta:
         """ Sort School by file_count descending, name abc=> """
index aa631be99feeadf8eb616a6484efc11edc00b70f..64f1548a44bf0e29db262e500dd54ee68ca73e21 100644 (file)
@@ -26,7 +26,7 @@ def tweet_note():
                       access_token_key=secrets.ACCESS_TOKEN_KEY,
                       access_token_secret=secrets.ACCESS_TOKEN_SECRET)
 
-    newest_notes = Note.objects.all()[:100]
+    newest_notes = Note.objects.all().order_by('-uploaded_at')[:100]
     for n in newest_notes:
         if not n.tweeted:
             update = tweet_string(n)
@@ -45,26 +45,21 @@ def tweet_note():
 def tweet_string(note):
     # This url will use 13 or less characters
     shortener = gdshortener.ISGDShortener()
-    url = "https://www.karmanotes.org" + \
+    url = "http://www.karmanotes.org" + \
         note.get_absolute_url()
     short_url = shortener.shorten(url)[0]
 
-    # space character
-
-    # 16 characters
-    school = note.course.school.slug
-    short_school = school[:school.find('-')][:16]
-
-    # space character
-
     # 50 characters
     short_course = note.course.name[:50]
 
-    # space and colon characters
-
     # 57 characters
     short_note = note.name[:57]
 
-    return short_url + " #" + short_school + " " + \
+    if note.course.school.hashtag:
+        return short_url + " #" + note.course.school.hashtag + " " + \
         short_course + ": " + \
         short_note
+    else:
+        return short_url + " " + \
+            short_course + ": " + \
+            short_note