<s> """<STR_LIT>""" <EOL> from treeio . identities . identicon import render_identicon <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . template import RequestContext <EOL> from django . http import HttpResponse , HttpResponseRedirect <EOL> from django . core . urlresolvers import reverse <EOL> from django . views . decorators . cache import cache_control <EOL> from django . db . models import Q <EOL> from treeio . core . rendering import render_to_response <EOL> from treeio . core . forms import LocationForm <EOL> from treeio . core . models import User , Group , Object , Location , AccessEntity <EOL> from treeio . core . views import user_denied <EOL> from treeio . core . decorators import treeio_login_required , handle_response_format <EOL> from treeio . identities . csvapi import ProcessContacts <EOL> from treeio . identities . models import Contact , ContactType , ContactField <EOL> from treeio . identities . forms import ContactForm , FilterForm , ContactTypeForm , ContactFieldForm , MassActionForm <EOL> from treeio . identities . objects import get_contact_objects <EOL> def _get_filter_query ( args ) : <EOL> "<STR_LIT>" <EOL> query = Q ( ) <EOL> for arg in args : <EOL> if hasattr ( Contact , arg ) and args [ arg ] : <EOL> kwargs = { str ( arg + '<STR_LIT>' ) : long ( args [ arg ] ) } <EOL> query = query & Q ( ** kwargs ) <EOL> return query <EOL> def _get_default_context ( request ) : <EOL> "<STR_LIT>" <EOL> context = { } <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> massform = MassActionForm ( request . user . profile ) <EOL> context . update ( { '<STR_LIT>' : types , <EOL> '<STR_LIT>' : massform } ) <EOL> return context <EOL> def _process_mass_form ( f ) : <EOL> "<STR_LIT>" <EOL> def wrap ( request , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> user = request . user . profile <EOL> if '<STR_LIT>' in request . POST : <EOL> for key in request . POST : <EOL> if '<STR_LIT>' in key : <EOL> try : <EOL> contact = Contact . objects . get ( pk = request . POST [ key ] ) <EOL> form = MassActionForm ( <EOL> user , request . POST , instance = contact ) <EOL> if form . is_valid ( ) and user . has_permission ( contact , mode = '<STR_LIT:w>' ) : <EOL> form . save ( ) <EOL> except Exception : <EOL> pass <EOL> return f ( request , * args , ** kwargs ) <EOL> wrap . __doc__ = f . __doc__ <EOL> wrap . __name__ = f . __name__ <EOL> return wrap <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> @ _process_mass_form <EOL> def index ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> if request . GET : <EOL> query = _get_filter_query ( request . GET ) <EOL> contacts = Object . filter_by_request ( <EOL> request , Contact . objects . filter ( query ) . order_by ( '<STR_LIT:name>' ) ) <EOL> else : <EOL> contacts = Object . filter_by_request ( <EOL> request , Contact . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> filters = FilterForm ( request . user . profile , '<STR_LIT:name>' , request . GET ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : contacts , <EOL> '<STR_LIT>' : filters } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> @ _process_mass_form <EOL> def type_view ( request , type_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> contact_type = get_object_or_404 ( ContactType , pk = type_id ) <EOL> if not request . user . profile . has_permission ( contact_type ) : <EOL> return user_denied ( request , message = "<STR_LIT>" ) <EOL> contacts = Object . filter_by_request ( <EOL> request , Contact . objects . filter ( contact_type = contact_type ) ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : contacts , <EOL> '<STR_LIT:type>' : contact_type } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ treeio_login_required <EOL> @ handle_response_format <EOL> def type_edit ( request , type_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> contact_type = get_object_or_404 ( ContactType , pk = type_id ) <EOL> if not request . user . profile . has_permission ( contact_type , mode = '<STR_LIT:w>' ) : <EOL> return user_denied ( request , message = "<STR_LIT>" , <EOL> response_format = response_format ) <EOL> identities = Object . filter_by_request ( request , <EOL> Contact . objects . filter ( contact_type = contact_type ) . order_by ( '<STR_LIT:name>' ) ) <EOL> if request . POST : <EOL> if '<STR_LIT>' not in request . POST : <EOL> form = ContactTypeForm ( <EOL> request . user . profile , request . POST , instance = contact_type ) <EOL> if form . is_valid ( ) : <EOL> contact_type = form . save ( request ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ contact_type . id ] ) ) <EOL> else : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ contact_type . id ] ) ) <EOL> else : <EOL> form = ContactTypeForm ( <EOL> request . user . profile , instance = contact_type ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : identities , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT:type>' : contact_type } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ treeio_login_required <EOL> @ handle_response_format <EOL> def type_add ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> if not request . user . profile . is_admin ( '<STR_LIT>' ) : <EOL> return user_denied ( request , <EOL> message = "<STR_LIT>" , <EOL> response_format = response_format ) <EOL> if request . POST : <EOL> if '<STR_LIT>' not in request . POST : <EOL> contact_type = ContactType ( ) <EOL> form = ContactTypeForm ( <EOL> request . user . profile , request . POST , instance = contact_type ) <EOL> if form . is_valid ( ) : <EOL> contact_type = form . save ( request ) <EOL> contact_type . set_user_from_request ( request ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ contact_type . id ] ) ) <EOL> else : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> else : <EOL> form = ContactTypeForm ( request . user . profile ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : form } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def type_delete ( request , type_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> type = get_object_or_404 ( ContactType , pk = type_id ) <EOL> if not request . user . profile . has_permission ( type , mode = "<STR_LIT:w>" ) : <EOL> return user_denied ( request , message = "<STR_LIT>" ) <EOL> if request . POST : <EOL> if '<STR_LIT>' in request . POST : <EOL> if '<STR_LIT>' in request . POST : <EOL> type . trash = True <EOL> type . save ( ) <EOL> else : <EOL> type . delete ( ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> elif '<STR_LIT>' in request . POST : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ type . id ] ) ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT:type>' : type } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def field_view ( request , field_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> field = get_object_or_404 ( ContactField , pk = field_id ) <EOL> if not request . user . profile . has_permission ( field ) : <EOL> return user_denied ( request , message = "<STR_LIT>" , <EOL> response_format = response_format ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : field } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def field_edit ( request , field_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> field = get_object_or_404 ( ContactField , pk = field_id ) <EOL> if not request . user . profile . has_permission ( field , mode = '<STR_LIT:w>' ) : <EOL> return user_denied ( request , message = "<STR_LIT>" , <EOL> response_format = response_format ) <EOL> if request . POST : <EOL> if '<STR_LIT>' not in request . POST : <EOL> form = ContactFieldForm ( request . POST , instance = field ) <EOL> if form . is_valid ( ) : <EOL> field = form . save ( request ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ field . id ] ) ) <EOL> else : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ field . id ] ) ) <EOL> else : <EOL> form = ContactFieldForm ( instance = field ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : form , <EOL> '<STR_LIT>' : field } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def field_add ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> if not request . user . profile . is_admin ( '<STR_LIT>' ) : <EOL> return user_denied ( request , <EOL> message = "<STR_LIT>" , <EOL> response_format = response_format ) <EOL> if request . POST : <EOL> if '<STR_LIT>' not in request . POST : <EOL> field = ContactField ( ) <EOL> form = ContactFieldForm ( request . POST , instance = field ) <EOL> if form . is_valid ( ) : <EOL> field = form . save ( request ) <EOL> field . set_user_from_request ( request ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ field . id ] ) ) <EOL> else : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> else : <EOL> form = ContactFieldForm ( ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : form } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def field_delete ( request , field_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> field = get_object_or_404 ( ContactField , pk = field_id ) <EOL> if not request . user . profile . has_permission ( field , mode = "<STR_LIT:w>" ) : <EOL> return user_denied ( request , message = "<STR_LIT>" ) <EOL> if request . POST : <EOL> if '<STR_LIT>' in request . POST : <EOL> if '<STR_LIT>' in request . POST : <EOL> field . trash = True <EOL> field . save ( ) <EOL> else : <EOL> field . delete ( ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> elif '<STR_LIT>' in request . POST : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ field . id ] ) ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : field } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def contact_add ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : types } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def contact_add_typed ( request , type_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> contact_type = get_object_or_404 ( ContactType , pk = type_id ) <EOL> if not request . user . profile . has_permission ( contact_type , mode = '<STR_LIT:x>' ) : <EOL> return user_denied ( request , message = "<STR_LIT>" + unicode ( contact_type ) ) <EOL> if request . POST : <EOL> if '<STR_LIT>' not in request . POST : <EOL> form = ContactForm ( <EOL> request . user . profile , contact_type , request . POST , files = request . FILES ) <EOL> if form . is_valid ( ) : <EOL> contact = form . save ( request , contact_type ) <EOL> contact . set_user_from_request ( request ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ contact . id ] ) ) <EOL> else : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> else : <EOL> form = ContactForm ( request . user . profile , contact_type ) <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT:type>' : contact_type , <EOL> '<STR_LIT>' : types , '<STR_LIT>' : form } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def contact_view ( request , contact_id , attribute = '<STR_LIT>' , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> contact = get_object_or_404 ( Contact , pk = contact_id ) <EOL> if not request . user . profile . has_permission ( contact ) : <EOL> return user_denied ( request , message = "<STR_LIT>" ) <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> subcontacts = Object . filter_by_request ( request , contact . child_set ) <EOL> contact_values = contact . contactvalue_set . order_by ( '<STR_LIT>' ) <EOL> objects = get_contact_objects ( <EOL> request . user . profile , contact , preformat = True ) <EOL> module = None <EOL> for key in objects : <EOL> if not attribute : <EOL> if objects [ key ] [ '<STR_LIT:count>' ] : <EOL> module = objects [ key ] [ '<STR_LIT>' ] <EOL> else : <EOL> if attribute in objects [ key ] [ '<STR_LIT>' ] . keys ( ) : <EOL> module = objects [ key ] [ '<STR_LIT>' ] <EOL> break <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : contact , <EOL> '<STR_LIT>' : subcontacts , <EOL> '<STR_LIT>' : objects , <EOL> '<STR_LIT>' : module , <EOL> '<STR_LIT>' : attribute , <EOL> '<STR_LIT>' : types , <EOL> '<STR_LIT>' : contact_values } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def contact_me ( request , attribute = '<STR_LIT>' , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> contact = request . user . profile . get_contact ( ) <EOL> if not request . user . profile . has_permission ( contact ) : <EOL> return user_denied ( request , message = "<STR_LIT>" ) <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> if not contact : <EOL> return render_to_response ( '<STR_LIT>' , { '<STR_LIT>' : types } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> subcontacts = Object . filter_by_request ( request , contact . child_set ) <EOL> contact_values = contact . contactvalue_set . order_by ( '<STR_LIT>' ) <EOL> objects = get_contact_objects ( <EOL> request . user . profile , contact , preformat = True ) <EOL> module = None <EOL> for key in objects : <EOL> if not attribute : <EOL> if objects [ key ] [ '<STR_LIT:count>' ] : <EOL> module = objects [ key ] [ '<STR_LIT>' ] <EOL> else : <EOL> if attribute in objects [ key ] [ '<STR_LIT>' ] . keys ( ) : <EOL> module = objects [ key ] [ '<STR_LIT>' ] <EOL> break <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : contact , <EOL> '<STR_LIT>' : subcontacts , <EOL> '<STR_LIT>' : objects , <EOL> '<STR_LIT>' : module , <EOL> '<STR_LIT>' : attribute , <EOL> '<STR_LIT>' : types , <EOL> '<STR_LIT>' : contact_values } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ treeio_login_required <EOL> @ cache_control ( private = True , max_age = <NUM_LIT> ) <EOL> def contact_view_picture ( request , contact_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> response = HttpResponse ( content_type = "<STR_LIT>" ) <EOL> render_identicon ( contact_id * <NUM_LIT> ) . save ( response , "<STR_LIT>" ) <EOL> return response <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def contact_edit ( request , contact_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> contact = get_object_or_404 ( Contact , pk = contact_id ) <EOL> if not request . user . profile . has_permission ( contact , mode = '<STR_LIT:w>' ) : <EOL> return user_denied ( request , message = "<STR_LIT>" ) <EOL> if request . POST : <EOL> if '<STR_LIT>' not in request . POST : <EOL> form = ContactForm ( request . user . profile , contact . contact_type , request . POST , <EOL> files = request . FILES , instance = contact ) <EOL> if form . is_valid ( ) : <EOL> contact = form . save ( request ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ contact . id ] ) ) <EOL> else : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ contact . id ] ) ) <EOL> else : <EOL> form = ContactForm ( <EOL> request . user . profile , contact . contact_type , instance = contact ) <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : contact , <EOL> '<STR_LIT>' : types , <EOL> '<STR_LIT>' : form } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def contact_delete ( request , contact_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> contact = get_object_or_404 ( Contact , pk = contact_id ) <EOL> if not request . user . profile . has_permission ( contact , mode = '<STR_LIT:w>' ) : <EOL> return user_denied ( request , message = "<STR_LIT>" ) <EOL> if request . POST : <EOL> if '<STR_LIT>' in request . POST : <EOL> if '<STR_LIT>' in request . POST : <EOL> contact . trash = True <EOL> contact . save ( ) <EOL> else : <EOL> contact . delete ( ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> elif '<STR_LIT>' in request . POST : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ contact . id ] ) ) <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : contact , '<STR_LIT>' : types } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def index_users ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> users = User . objects . exclude ( disabled = True ) . order_by ( '<STR_LIT>' ) <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : users , '<STR_LIT>' : types } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def index_groups ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> groups = Group . objects . order_by ( '<STR_LIT>' , '<STR_LIT:name>' ) <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : groups , '<STR_LIT>' : types } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ treeio_login_required <EOL> def user_view ( request , user_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> user = get_object_or_404 ( User , pk = user_id ) <EOL> contact_id = Contact . objects . filter ( related_user = user ) [ <NUM_LIT:0> ] . id <EOL> return contact_view ( request , contact_id , attribute = '<STR_LIT>' , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def group_view ( request , group_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> group = get_object_or_404 ( Group , pk = group_id ) <EOL> contacts = Object . filter_by_request ( <EOL> request , Contact . objects . filter ( related_user = group ) . order_by ( '<STR_LIT:name>' ) ) <EOL> members = User . objects . filter ( <EOL> Q ( default_group = group ) | Q ( other_groups = group ) ) . distinct ( ) <EOL> subgroups = Group . objects . filter ( parent = group ) <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : group , <EOL> '<STR_LIT>' : subgroups , <EOL> '<STR_LIT>' : members , <EOL> '<STR_LIT>' : contacts , <EOL> '<STR_LIT>' : types } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ treeio_login_required <EOL> @ handle_response_format <EOL> def location_index ( request , location_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> locations = Object . filter_permitted ( request . user . profile , <EOL> Location . objects ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { <EOL> '<STR_LIT>' : locations , <EOL> } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ treeio_login_required <EOL> @ handle_response_format <EOL> def location_add ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> if request . POST : <EOL> if '<STR_LIT>' not in request . POST : <EOL> location = Location ( ) <EOL> form = LocationForm ( <EOL> request . user . profile , None , request . POST , instance = location ) <EOL> if form . is_valid ( ) : <EOL> location = form . save ( ) <EOL> location . set_user_from_request ( request ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ location . id ] ) ) <EOL> else : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> else : <EOL> form = LocationForm ( request . user . profile , None ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : form } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ treeio_login_required <EOL> @ handle_response_format <EOL> def location_view ( request , location_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> location = get_object_or_404 ( Location , pk = location_id ) <EOL> if not request . user . profile . has_permission ( location ) : <EOL> return user_denied ( request , message = "<STR_LIT>" , <EOL> response_format = response_format ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { <EOL> '<STR_LIT:location>' : location , <EOL> } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ treeio_login_required <EOL> @ handle_response_format <EOL> def location_edit ( request , location_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> location = get_object_or_404 ( Location , pk = location_id ) <EOL> if not request . user . profile . has_permission ( location , mode = "<STR_LIT:w>" ) : <EOL> return user_denied ( request , message = "<STR_LIT>" , <EOL> response_format = response_format ) <EOL> if request . POST : <EOL> if '<STR_LIT>' not in request . POST : <EOL> form = LocationForm ( <EOL> request . user . profile , None , request . POST , instance = location ) <EOL> if form . is_valid ( ) : <EOL> location = form . save ( request ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ location . id ] ) ) <EOL> else : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ location . id ] ) ) <EOL> else : <EOL> form = LocationForm ( <EOL> request . user . profile , None , instance = location ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT:location>' : location , <EOL> '<STR_LIT>' : form } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def location_delete ( request , location_id , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> location = get_object_or_404 ( Location , pk = location_id ) <EOL> if not request . user . profile . has_permission ( location , mode = "<STR_LIT:w>" ) : <EOL> return user_denied ( request , message = "<STR_LIT>" ) <EOL> if request . POST : <EOL> if '<STR_LIT>' in request . POST : <EOL> if '<STR_LIT>' in request . POST : <EOL> location . trash = True <EOL> location . save ( ) <EOL> else : <EOL> location . delete ( ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> elif '<STR_LIT>' in request . POST : <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = [ location . id ] ) ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT:location>' : location } ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def settings_view ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> if not request . user . profile . is_admin ( '<STR_LIT>' ) : <EOL> return user_denied ( request , message = "<STR_LIT>" , <EOL> response_format = response_format ) <EOL> contact_types = ContactType . objects . all ( ) . filter ( trash = False ) <EOL> contact_fields = ContactField . objects . all ( ) . filter ( trash = False ) <EOL> contacts = Object . filter_by_request ( <EOL> request , Contact . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> context = _get_default_context ( request ) <EOL> context . update ( { '<STR_LIT>' : contact_types , <EOL> '<STR_LIT>' : contact_fields , <EOL> '<STR_LIT>' : contacts } ) <EOL> if request . POST : <EOL> if '<STR_LIT:file>' in request . FILES : <EOL> csv_file = request . FILES [ '<STR_LIT:file>' ] <EOL> content = csv_file . read ( ) <EOL> import_c = ProcessContacts ( ) <EOL> import_c . import_contacts ( content ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> return render_to_response ( '<STR_LIT>' , context , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> @ treeio_login_required <EOL> def ajax_access_lookup ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> entities = [ ] <EOL> if request . GET and '<STR_LIT>' in request . GET : <EOL> entities = AccessEntity . objects . filter ( Q ( user__name__icontains = request . GET [ '<STR_LIT>' ] ) | <EOL> Q ( user__contact__name__icontains = request . GET [ '<STR_LIT>' ] ) | <EOL> Q ( group__name__icontains = request . GET [ '<STR_LIT>' ] ) ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : entities } , <EOL> context_instance = RequestContext ( request ) , <EOL> response_format = response_format ) <EOL> @ treeio_login_required <EOL> def ajax_user_lookup ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> users = [ ] <EOL> if request . GET and '<STR_LIT>' in request . GET : <EOL> users = User . objects . filter ( Q ( name__icontains = request . GET [ '<STR_LIT>' ] ) | <EOL> Q ( contact__name__icontains = request . GET [ '<STR_LIT>' ] ) ) <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : users } , <EOL> context_instance = RequestContext ( request ) , <EOL> response_format = response_format ) <EOL> @ treeio_login_required <EOL> def ajax_contact_lookup ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> contacts = [ ] <EOL> if request . GET and '<STR_LIT>' in request . GET : <EOL> user = request . user . profile <EOL> contacts = Object . filter_permitted ( user , Contact . objects , <EOL> mode = '<STR_LIT:x>' ) . filter ( Q ( name__icontains = request . GET [ '<STR_LIT>' ] ) ) [ : <NUM_LIT:10> ] <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : contacts } , <EOL> context_instance = RequestContext ( request ) , <EOL> response_format = response_format ) <EOL> @ treeio_login_required <EOL> def ajax_location_lookup ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> locations = [ ] <EOL> if request . GET and '<STR_LIT>' in request . GET : <EOL> user = request . user . profile <EOL> locations = Object . filter_permitted ( user , Location . objects , <EOL> mode = '<STR_LIT:x>' ) . filter ( <EOL> Q ( name__icontains = request . GET [ '<STR_LIT>' ] ) <EOL> ) [ : <NUM_LIT:10> ] <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : locations } , <EOL> context_instance = RequestContext ( request ) , <EOL> response_format = response_format ) <EOL> @ handle_response_format <EOL> @ treeio_login_required <EOL> def widget_contact_me ( request , response_format = '<STR_LIT:html>' ) : <EOL> "<STR_LIT>" <EOL> contact = request . user . profile . get_contact ( ) <EOL> if not request . user . profile . has_permission ( contact ) : <EOL> return user_denied ( request , message = "<STR_LIT>" ) <EOL> types = Object . filter_by_request ( <EOL> request , ContactType . objects . order_by ( '<STR_LIT:name>' ) ) <EOL> if contact : <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : contact , '<STR_LIT>' : types } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) <EOL> else : <EOL> return render_to_response ( '<STR_LIT>' , { '<STR_LIT>' : types } , <EOL> context_instance = RequestContext ( request ) , response_format = response_format ) </s>
