Skip to content

Commit

Permalink
Rename DB field from tweet to socials
Browse files Browse the repository at this point in the history
Django is happier when you do this in a separate step
  • Loading branch information
knatten committed Sep 22, 2024
1 parent 1ff89d6 commit 73ba950
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions quiz/management/commands/auto_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def handle(self, *args, **options):
print(f"Publishing question {q}")
q.state = 'PUB'
q.save()
if (q.tweet_text):
if (q.socials_text):
if skip_socials:
print("Skipping posting to social media!")
else:
self.post_to_x(q.tweet_text)
self.post_to_x(q.socials_text)

def post_to_x(self, content):
print(f"Posting to X: '{content}'")
Expand Down
18 changes: 18 additions & 0 deletions quiz/migrations/0023_rename_tweet_text_question_socials_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.15 on 2024-09-22 14:19

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('quiz', '0022_alter_question_result_alter_usersanswer_result'),
]

operations = [
migrations.RenameField(
model_name='question',
old_name='tweet_text',
new_name='socials_text',
),
]
4 changes: 2 additions & 2 deletions quiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Question(models.Model):
help_text='This question is reserved for an event, do not publish yet')
reservation_message = models.CharField(blank=True, max_length=100,
help_text='Which event the question is reserved for')
tweet_text = models.CharField(blank=True, max_length=280,
socials_text = models.CharField(blank=True, max_length=280,
help_text='What to tweet when question gets posted on Twitter')

def __str__(self):
Expand All @@ -69,7 +69,7 @@ def clean(self):
raise ValidationError(f'Cannot {verbs[self.state]} a question without a difficulty setting')
if self.state in ('PUB', 'SCH') and self.reserved:
raise ValidationError(f'Cannot {verbs[self.state]} a reserved question')
if self.tweet_text and not re.search("https?://", self.tweet_text):
if self.socials_text and not re.search("https?://", self.socials_text):
raise ValidationError('Tweets must contain a url!')

def save(self, *args, **kwargs):
Expand Down
8 changes: 4 additions & 4 deletions quiz/tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def test_questions_get_a_random_preview_key(self):
q2 = Question.objects.create()
self.assertNotEqual(q.preview_key, q2.preview_key)

def test_requires_url_in_tweet_text(self):
q = Question(state="SCH", hint='hint', tweet_text="hi", difficulty=1)
def test_requires_url_in_socials_text(self):
q = Question(state="SCH", hint='hint', socials_text="hi", difficulty=1)
with self.assertRaises(ValidationError) as cm:
q.save()
self.assertIn('Tweets must contain a url!', str(cm.exception))
Question(state="SCH", hint='hint', tweet_text="See http://example.com", difficulty=1).save()
Question(state="SCH", hint='hint', tweet_text="See https://example.com", difficulty=1).save()
Question(state="SCH", hint='hint', socials_text="See http://example.com", difficulty=1).save()
Question(state="SCH", hint='hint', socials_text="See https://example.com", difficulty=1).save()

0 comments on commit 73ba950

Please sign in to comment.