<s> from django . db import transaction <EOL> from django . core . exceptions import ValidationError <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . shortcuts import render <EOL> from django . http import HttpResponse <EOL> from core . search . compiler . django_compile import search_type <EOL> from core . service . models import Service <EOL> from core . service . forms import ServiceForm <EOL> from core . views import ( <EOL> CoreListView , CoreCreateView , CoreUpdateView , <EOL> CoreDeleteView <EOL> ) <EOL> from systems . models import System <EOL> import simplejson as json <EOL> class ServiceView ( object ) : <EOL> model = Service <EOL> queryset = Service . objects . all ( ) <EOL> form_class = ServiceForm <EOL> class ServiceDeleteView ( ServiceView , CoreDeleteView ) : <EOL> pass <EOL> class ServiceListView ( ServiceView , CoreListView ) : <EOL> template_name = '<STR_LIT>' <EOL> class ServiceUpdateView ( ServiceView , CoreUpdateView ) : <EOL> template_name = '<STR_LIT>' <EOL> class ServiceCreateView ( ServiceView , CoreCreateView ) : <EOL> template_name = '<STR_LIT>' <EOL> def service_detail ( request , pk ) : <EOL> service = get_object_or_404 ( Service , pk = pk ) <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT>' : service <EOL> } ) <EOL> def service_export ( request ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> search = request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not search : <EOL> return HttpResponse ( <EOL> { '<STR_LIT>' : "<STR_LIT>" } , <EOL> status = <NUM_LIT> <EOL> ) <EOL> services , error = search_type ( search , '<STR_LIT>' ) <EOL> if error : <EOL> return HttpResponse ( <EOL> json . dumps ( { '<STR_LIT>' : str ( error ) } ) , status = <NUM_LIT> <EOL> ) <EOL> return HttpResponse ( json . dumps ( { <EOL> '<STR_LIT>' : Service . export_services ( services ) <EOL> } ) ) <EOL> def service_import ( request ) : <EOL> if request . method == '<STR_LIT:GET>' : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> try : <EOL> services_data = json . loads ( request . raw_post_data ) <EOL> except ValueError , e : <EOL> return HttpResponse ( json . dumps ( { '<STR_LIT>' : str ( e ) } ) , status = <NUM_LIT> ) <EOL> if '<STR_LIT>' not in services_data : <EOL> return HttpResponse ( json . dumps ( { <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } ) , status = <NUM_LIT> ) <EOL> with transaction . commit_manually ( ) : <EOL> try : <EOL> Service . import_services ( services_data [ '<STR_LIT>' ] ) <EOL> except ( <EOL> ValidationError , <EOL> ValueError , <EOL> System . DoesNotExist , <EOL> Service . DoesNotExist <EOL> ) , e : <EOL> transaction . rollback ( ) <EOL> return HttpResponse ( json . dumps ( { '<STR_LIT>' : str ( e ) } ) , status = <NUM_LIT> ) <EOL> except Exception , e : <EOL> transaction . rollback ( ) <EOL> return HttpResponse ( json . dumps ( { '<STR_LIT>' : str ( e ) } ) , status = <NUM_LIT> ) <EOL> transaction . commit ( ) <EOL> return HttpResponse ( '<STR_LIT:{}>' ) </s>
