<s> import json <EOL> from django . db import models <EOL> from django . template . defaultfilters import linebreaks_filter <EOL> from django . utils . six import python_2_unicode_compatible <EOL> from channels import Group <EOL> @ python_2_unicode_compatible <EOL> class Liveblog ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> title = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> slug = models . SlugField ( ) <EOL> def __str__ ( self ) : <EOL> return self . title <EOL> def get_absolute_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % self . slug <EOL> @ property <EOL> def group_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % self . id <EOL> @ python_2_unicode_compatible <EOL> class Post ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> liveblog = models . ForeignKey ( Liveblog , related_name = "<STR_LIT>" ) <EOL> body = models . TextField ( ) <EOL> created = models . DateTimeField ( auto_now_add = True ) <EOL> updated = models . DateTimeField ( auto_now = True ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . id , self . body_intro ( ) ) <EOL> def body_intro ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . body [ : <NUM_LIT:50> ] <EOL> def html_body ( self ) : <EOL> """<STR_LIT>""" <EOL> return linebreaks_filter ( self . body ) <EOL> def send_notification ( self ) : <EOL> """<STR_LIT>""" <EOL> notification = { <EOL> "<STR_LIT:id>" : self . id , <EOL> "<STR_LIT:html>" : self . html_body ( ) , <EOL> "<STR_LIT>" : self . created . strftime ( "<STR_LIT>" ) , <EOL> } <EOL> Group ( self . liveblog . group_name ) . send ( { <EOL> "<STR_LIT:text>" : json . dumps ( notification ) , <EOL> } ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> result = super ( Post , self ) . save ( * args , ** kwargs ) <EOL> self . send_notification ( ) <EOL> return result </s>
