<s> import datetime , csv <EOL> from django . http import HttpResponseRedirect <EOL> from django . shortcuts import render_to_response , get_object_or_404 <EOL> from django . core . files . base import ContentFile <EOL> from django . template import RequestContext <EOL> from django . contrib . admin . views . decorators import staff_member_required <EOL> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . views . generic . list_detail import object_list , object_detail <EOL> from csvimporter . models import CSV <EOL> from csvimporter . forms import CSVForm , CSVAssociateForm <EOL> @ staff_member_required <EOL> def csv_list ( request ) : <EOL> return object_list ( request , queryset = CSV . objects . all ( ) , template_name = '<STR_LIT>' , template_object_name = '<STR_LIT>' ) <EOL> @ staff_member_required <EOL> def associate ( request , object_id ) : <EOL> instance = get_object_or_404 ( CSV , pk = object_id ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = CSVAssociateForm ( instance , request . POST ) <EOL> if form . is_valid ( ) : <EOL> form . save ( request ) <EOL> request . user . message_set . create ( message = '<STR_LIT>' ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> else : <EOL> form = CSVAssociateForm ( instance ) <EOL> return object_detail ( request , <EOL> queryset = CSV . objects . all ( ) , <EOL> object_id = object_id , <EOL> template_name = '<STR_LIT>' , <EOL> template_object_name = '<STR_LIT>' , <EOL> extra_context = { <EOL> '<STR_LIT>' : form , <EOL> } ) <EOL> @ staff_member_required <EOL> def new ( request ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = CSVForm ( request . POST , request . FILES ) <EOL> if form . is_valid ( ) : <EOL> instance = form . save ( ) <EOL> request . user . message_set . create ( message = '<STR_LIT>' ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ instance . id ] ) ) <EOL> else : <EOL> form = CSVForm ( ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : form } , context_instance = RequestContext ( request ) ) </s>
