<s> from core . models import Follow , Pin <EOL> from django import forms <EOL> from core . feed_managers import manager <EOL> from core . models import Board <EOL> from django . template . defaultfilters import slugify <EOL> class PinForm ( forms . ModelForm ) : <EOL> board_name = forms . CharField ( ) <EOL> remove = forms . IntegerField ( required = False ) <EOL> class Meta : <EOL> model = Pin <EOL> exclude = [ '<STR_LIT>' ] <EOL> def save ( self , * args , ** kwargs ) : <EOL> board_name = self . cleaned_data [ '<STR_LIT>' ] <EOL> user = self . cleaned_data [ '<STR_LIT:user>' ] <EOL> remove = bool ( int ( self . cleaned_data . get ( '<STR_LIT>' , <NUM_LIT:0> ) or <NUM_LIT:0> ) ) <EOL> if remove : <EOL> pins = Pin . objects . filter ( <EOL> user = user , item = self . cleaned_data [ '<STR_LIT>' ] ) <EOL> for pin in pins : <EOL> manager . remove_pin ( pin ) <EOL> pin . delete ( ) <EOL> return <EOL> defaults = dict ( slug = slugify ( board_name ) ) <EOL> board , created = Board . objects . get_or_create ( <EOL> user = user , name = board_name , defaults = defaults ) <EOL> pin = forms . ModelForm . save ( self , commit = False ) <EOL> pin . board = board <EOL> pin . save ( ) <EOL> manager . add_pin ( pin ) <EOL> return pin <EOL> class FollowForm ( forms . Form ) : <EOL> user = forms . IntegerField ( ) <EOL> target = forms . IntegerField ( ) <EOL> remove = forms . IntegerField ( required = False ) <EOL> def save ( self ) : <EOL> user = self . cleaned_data [ '<STR_LIT:user>' ] <EOL> target = self . cleaned_data [ '<STR_LIT:target>' ] <EOL> remove = bool ( int ( self . cleaned_data . get ( '<STR_LIT>' , <NUM_LIT:0> ) or <NUM_LIT:0> ) ) <EOL> if remove : <EOL> follows = Follow . objects . filter ( user = user , target = target ) <EOL> for follow in follows : <EOL> manager . unfollow_user ( follow . user_id , follow . target_id ) <EOL> follow . delete ( ) <EOL> return <EOL> follow = Follow . objects . create ( user_id = user , target_id = target ) <EOL> manager . follow_user ( follow . user_id , follow . target_id ) <EOL> return follow </s>
