<s> import logging <EOL> from abc import ABCMeta , abstractmethod , abstractproperty <EOL> import six as six <EOL> from couchdbkit import ResourceNotFound <EOL> from dimagi . utils . decorators . memoized import memoized <EOL> from couchforms import const <EOL> class AbstractXFormInstance ( object ) : <EOL> user_id = None <EOL> @ property <EOL> def attachments ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> @ property <EOL> def form_data ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def metadata ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def is_normal ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def is_archived ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def is_deprecated ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def is_duplicate ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def is_error ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def is_submission_error_log ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def is_deleted ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def auth_context ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def get_data ( self , xpath ) : <EOL> raise NotImplementedError ( ) <EOL> def get_attachment ( self , attachment_name ) : <EOL> raise NotImplementedError ( ) <EOL> def archive ( self , user_id = None ) : <EOL> raise NotImplementedError ( ) <EOL> def unarchive ( self , user_id = None ) : <EOL> raise NotImplementedError ( ) <EOL> def get_xml_element ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def get_xml ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> raise NotImplementedError ( ) <EOL> def set_submission_properties ( self , submission_post ) : <EOL> raise NotImplementedError ( ) <EOL> def soft_delete ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def to_json ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ classmethod <EOL> def get ( self , xform_id ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def xml_md5 ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def version ( self ) : <EOL> return self . form_data . get ( const . TAG_VERSION , "<STR_LIT>" ) <EOL> @ property <EOL> def uiversion ( self ) : <EOL> return self . form_data . get ( const . TAG_UIVERSION , "<STR_LIT>" ) <EOL> @ property <EOL> def type ( self ) : <EOL> return self . form_data . get ( const . TAG_TYPE , "<STR_LIT>" ) <EOL> @ memoized <EOL> def get_sync_token ( self ) : <EOL> from casexml . apps . phone . models import get_properly_wrapped_sync_log <EOL> if self . last_sync_token : <EOL> try : <EOL> return get_properly_wrapped_sync_log ( self . last_sync_token ) <EOL> except ResourceNotFound : <EOL> logging . exception ( '<STR_LIT>' . format ( <EOL> self . last_sync_token , self . form_id , self . domain , <EOL> ) ) <EOL> raise <EOL> return None <EOL> class AbstractCommCareCase ( object ) : <EOL> @ property <EOL> def case_name ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def parent ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def soft_delete ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def get_attachment ( self , attachment_name ) : <EOL> raise NotImplementedError ( ) <EOL> def is_deleted ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def dynamic_case_properties ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def get_actions_for_form ( self , xform ) : <EOL> raise NotImplementedError <EOL> def modified_since_sync ( self , sync_log ) : <EOL> raise NotImplementedError <EOL> def get_subcases ( self ) : <EOL> raise NotImplementedError <EOL> def get_case_property ( self , property ) : <EOL> raise NotImplementedError <EOL> def to_json ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def to_api_json ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ memoized <EOL> def get_index_map ( self , reversed = False ) : <EOL> return dict ( [ <EOL> ( index . identifier , { <EOL> "<STR_LIT>" : index . referenced_type , <EOL> "<STR_LIT>" : index . referenced_id , <EOL> "<STR_LIT>" : index . relationship , <EOL> } ) for index in ( self . indices if not reversed else self . reverse_indices ) <EOL> ] ) <EOL> def get_properties_in_api_format ( self ) : <EOL> return dict ( self . dynamic_case_properties ( ) . items ( ) + { <EOL> "<STR_LIT>" : self . external_id , <EOL> "<STR_LIT>" : self . owner_id , <EOL> "<STR_LIT>" : self . name , <EOL> "<STR_LIT>" : self . type , <EOL> "<STR_LIT>" : self . opened_on , <EOL> } . items ( ) ) <EOL> @ memoized <EOL> def get_attachment_map ( self ) : <EOL> return dict ( [ <EOL> ( name , { <EOL> '<STR_LIT:url>' : self . get_attachment_server_url ( att . identifier ) , <EOL> '<STR_LIT>' : att . attachment_from <EOL> } ) for name , att in self . case_attachments . items ( ) <EOL> ] ) <EOL> def to_xml ( self , version , include_case_on_closed = False ) : <EOL> from xml . etree import ElementTree <EOL> from casexml . apps . phone . xml import get_case_element <EOL> if self . closed : <EOL> if include_case_on_closed : <EOL> elem = get_case_element ( self , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , version ) <EOL> else : <EOL> elem = get_case_element ( self , ( '<STR_LIT>' ) , version ) <EOL> else : <EOL> elem = get_case_element ( self , ( '<STR_LIT>' , '<STR_LIT>' ) , version ) <EOL> return ElementTree . tostring ( elem ) <EOL> def get_attachment_server_url ( self , identifier ) : <EOL> """<STR_LIT>""" <EOL> if identifier in self . case_attachments : <EOL> from dimagi . utils import web <EOL> from django . core . urlresolvers import reverse <EOL> return "<STR_LIT>" % ( web . get_url_base ( ) , <EOL> reverse ( "<STR_LIT>" , kwargs = { <EOL> "<STR_LIT>" : self . domain , <EOL> "<STR_LIT>" : self . case_id , <EOL> "<STR_LIT>" : identifier , <EOL> } ) <EOL> ) <EOL> else : <EOL> return None <EOL> class AbstractSupplyInterface ( six . with_metaclass ( ABCMeta ) ) : <EOL> @ classmethod <EOL> @ abstractmethod <EOL> def get_by_location ( cls , location ) : <EOL> raise NotImplementedError <EOL> @ classmethod <EOL> @ abstractmethod <EOL> def get_or_create_by_location ( cls , location ) : <EOL> raise NotImplementedError <EOL> class IsImageMixin ( object ) : <EOL> @ property <EOL> def is_image ( self ) : <EOL> if self . content_type is None : <EOL> return None <EOL> return True if self . content_type . startswith ( '<STR_LIT>' ) else False <EOL> class CaseAttachmentMixin ( IsImageMixin ) : <EOL> @ property <EOL> def is_present ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . identifier and ( self . attachment_src == self . attachment_from is None ) : <EOL> return False <EOL> else : <EOL> return True </s>
