
    @Wj
                         S SK r S SKJr  S SKJrJrJr  S SKJr  S SK	J
r
Jr  SSKJr  SSKJrJr  SS	KJr  SS
KJr  \ R*                  " \5      r " S S\R0                  5      rg)    N)RequestException)genericsserializersstatus)Response)APIKeyAuthenticationDashboardTokenAuthentication   )analyzeProduct)AliExpressUpstreamErrorimportProduct)saveProduct)(ImportAndAnalyzeProductRequestSerializerc                   .    \ rS rSrSr\\/r\r	/ r
S rSrg)$ImportAndAnalyzeProductDashboardView   zBImport an AliExpress product, analyze it, and return the analysis.c                 *   SnU Vs/ s HB  nUR                   R                  U5      b!  UR                   R                  U5      S:X  d  M@  UPMD     nnU(       a  [        SUS.SS9$ U R                  UR                   S9nUR	                  SS	9   UR
                  R                  5       nS
 V	s0 s H  n	XR                  U	5      _M     n
n	[        S0 UD6n[        U5      nSUS'   UR                  S5      S;   a   [        U40 U
D6  SUS'   [        U5      $ s  snf s  sn	f ! [        [        4 a.  n[        S[        U5      S.[        R                  S9s S nA$ S nAff = f! [          a&    ["        R%                  SUR
                  S   5         Nf = f)N)shipToCountry	productIdtargetCurrencytargetLanguage
currencyId
languageIdcollectionId zMissing required fields.)errormissingFieldsi  )r   )dataT)raise_exception)r   r   r   zAliExpress request failed.)r   detailFisProductSavedecision)SELLCONSIDERz-Failed to save analyzed AliExpress product %sr    )r   getr   get_serializeris_validvalidated_datacopypopr   r   r   r   strr   HTTP_502_BAD_GATEWAYr   	Exceptionlogger	exception)selfrequestargskwargsrequired_fieldsfieldmissing_fields
serializerimport_datakeysave_idsimported_productanalysisr   s                 x/Users/waleedhassanin/Documents/snowflake_co_dev_github/snow_flake_back_end_deploy/mama_care_api/ali_express_ds/views.pypost)ImportAndAnalyzeProductDashboardView.post   s   
 )
(||&.',,2B2B52IR2O ( 	 

 7%3   ((gll(;
D1	$3388:K HGC __S))G    -;{;%&67H %*!<<
#';;,99,0) !![
& ()9: 	9!%j 22 	    C--k:sM   ?D
DD! -DD! ;E" D! !E1#EEE"-FFr%   N)__name__
__module____qualname____firstlineno____doc__r   r	   authentication_classesr   serializer_classquerysetr?   __static_attributes__r%       r>   r   r      s!    L24PQ?H7"rJ   r   )loggingrequests.exceptionsr   rest_frameworkr   r   r   rest_framework.responser   common.viewsr   r	   pms.analyze_productr   pms.import_productr   r   pms.save_productr   
searlizersr   	getLoggerrA   r/   GenericAPIViewr   r%   rJ   r>   <module>rV      sE     0 8 8 , K / F ) @			8	$>"8+B+B >"rJ   