<s> from django . shortcuts import get_object_or_404 <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . decorators import login_required <EOL> from basic . groups . decorators import * <EOL> from basic . groups . models import * <EOL> from basic . groups . forms import * <EOL> from basic . tools . shortcuts import render , redirect <EOL> def group_list ( request , username = None , <EOL> template_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> group_list = Group . objects . filter ( is_active = True ) <EOL> if request . user . is_authenticated ( ) : <EOL> membership_list = group_list . filter ( members__user = request . user ) <EOL> else : <EOL> membership_list = [ ] <EOL> return render ( request , template_name , { <EOL> '<STR_LIT>' : group_list , <EOL> '<STR_LIT>' : membership_list <EOL> } ) <EOL> @ login_required <EOL> def group_create ( request , template_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = GroupForm ( request . POST , request . FILES ) <EOL> if form . is_valid ( ) : <EOL> group = form . save ( commit = False ) <EOL> group . creator = request . user <EOL> group . save ( ) <EOL> creator = GroupMember . objects . create ( user = request . user , group = group , status = <NUM_LIT:0> ) <EOL> return redirect ( request , group ) <EOL> else : <EOL> form = GroupForm ( ) <EOL> return render ( request , template_name , { '<STR_LIT>' : form } ) <EOL> def group_detail ( request , slug , template_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> group = get_object_or_404 ( Group , slug = slug , is_active = True ) <EOL> if group . invite_only and not GroupMember . objects . is_member ( group , request . user ) : <EOL> return redirect ( request , reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : group . slug } ) ) <EOL> return render ( request , template_name , { <EOL> '<STR_LIT>' : group , <EOL> '<STR_LIT>' : group . topics . all ( ) , <EOL> } ) <EOL> @ ownership_required <EOL> def group_edit ( request , slug , template_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> group = get_object_or_404 ( Group , slug = slug , creator = request . user ) <EOL> form = GroupForm ( instance = group ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = GroupForm ( request . POST , request . FILES , instance = group ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> return redirect ( request , group ) <EOL> return render ( request , template_name , { <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : group <EOL> } ) <EOL> @ ownership_required <EOL> def group_remove ( request , slug , template_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> group = get_object_or_404 ( Group , slug = slug , creator = request . user ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> group . is_active = False <EOL> group . save ( ) <EOL> return redirect ( request , reverse ( '<STR_LIT>' ) ) <EOL> return render ( request , template_name , { '<STR_LIT>' : group } ) <EOL> def group_members ( request , slug , template_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> group = get_object_or_404 ( Group , slug = slug , is_active = True ) <EOL> member_list = group . members . all ( ) <EOL> return render ( request , template_name , { <EOL> '<STR_LIT>' : group , <EOL> '<STR_LIT>' : member_list <EOL> } ) <EOL> @ login_required <EOL> def group_join ( request , slug , template_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> group = get_object_or_404 ( Group , slug = slug , is_active = True ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> membership = GroupMember ( group = group , user = request . user ) <EOL> membership . save ( ) <EOL> return redirect ( request , group ) <EOL> return render ( request , template_name , { '<STR_LIT>' : group } ) <EOL> @ membership_required <EOL> def group_invite ( request , slug , template_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> group = get_object_or_404 ( Group , slug = slug , is_active = True ) <EOL> form = GroupInviteForm ( initial = { '<STR_LIT>' : group . pk , '<STR_LIT:user>' : request . user . pk } ) <EOL> return render ( request , template_name , { <EOL> '<STR_LIT>' : group , <EOL> '<STR_LIT>' : form <EOL> } ) </s>
