1. Gregory Petukhov
  2. django-article

Commits

Gregory Petukhov  committed 9e456df

Some fix

  • Participants
  • Parent commits 75f08c7
  • Branches default

Comments (0)

Files changed (3)

File article/admin.py

View file
  • Ignore whitespace
             return 'n/a'
     image_thumbnail.allow_tags = True
 
+    def save_model(self, request, obj, *args, **kwargs):
+        if obj.user is None:
+            obj.user = request.user
+        obj.save()
+
+    def get_form(self, request, obj=None, **kwargs):
+        form = super(ArticleAdmin, self).get_form(request, obj=obj, **kwargs)
+        if not form.base_fields['user'].initial:
+            form.base_fields['user'].initial = request.user.pk
+        return form
+
 
 class CategoryAdmin(admin.ModelAdmin):
     list_display = ['name', 'slug']

File article/models.py

View file
  • Ignore whitespace
     title = models.CharField(max_length=255)
     slug = models.SlugField(max_length=255, blank=False, default=None)
     category = models.ForeignKey('article.Category', related_name='articles')
+    teaser = RichTextField(blank=True)
     content = RichTextField()
-    teaser = RichTextField(blank=True)
+    teaser_html = models.TextField(editable=True, blank=True)
     content_html = models.TextField(editable=True, blank=True)
-    teaser_html = models.TextField(editable=True, blank=True)
     image = models.ImageField(blank=True,
             upload_to='upload/article/article_image')
     meta_keywords = models.CharField(max_length=255, blank=True)

File article/signals.py

View file
  • Ignore whitespace
 @receiver(pre_save, sender=Article)
 def article_pre_save(instance, **kwargs):
     if '@CUT@' in instance.content:
-        cut_teaser, cut_content = instance.content.split('@CUT@', 1)
-        if instance.teaser.strip():
+        instance.teaser = ''
+        head, tail = instance.content.split('@CUT@', 1)
+        instance.teaser_html = head.strip()
+        instance.content_html = tail.strip()
+    else:
+        instance.content_html = instance.content
+        if normalize_html(instance.teaser).strip():
             instance.teaser_html = instance.teaser
         else:
-            instance.teaser_html = cut_teaser
-        instance.content_html = cut_content
-    elif not instance.teaser.strip():
-        instance.teaser_html = '<i>Empty Content</i>'
-    instance.content_html = normalize_html(instance.content)
-    instance.teaser_html = normalize_html(instance.teaser)
+            instance.teaser_html = instance.content
+
+    instance.teaser_html = normalize_html(instance.teaser_html)
+    instance.content_html = normalize_html(instance.content_html)