<s> from models import PushNotification <EOL> from pushy . tasks import send_single_push_notification <EOL> from tasks import create_push_notification_groups <EOL> def send_push_notification ( title , payload , device = None , <EOL> filter_user = None , filter_type = None ) : <EOL> notification = PushNotification . objects . create ( <EOL> title = title , <EOL> payload = payload , <EOL> active = PushNotification . PUSH_ACTIVE , <EOL> sent = PushNotification . PUSH_NOT_SENT <EOL> ) <EOL> if device : <EOL> send_single_push_notification . apply_async ( kwargs = { <EOL> '<STR_LIT>' : device . id , <EOL> '<STR_LIT>' : notification . payload <EOL> } ) <EOL> return <EOL> if filter_type or filter_user : <EOL> if filter_user : <EOL> notification . filter_user = filter_user . id <EOL> if filter_type : <EOL> notification . filter_type = filter_type <EOL> notification . save ( ) <EOL> create_push_notification_groups . delay ( notification_id = notification . id ) </s>
