<s> import logging <EOL> from django . conf import settings <EOL> from django . utils . datastructures import SortedDict <EOL> from django . utils . translation import ugettext_lazy as _lazy <EOL> from statsd import statsd <EOL> from zendesk import Zendesk , ZendeskError <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> MARKETPLACE_CATEGORIES = SortedDict ( [ <EOL> ( '<STR_LIT>' , _lazy ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _lazy ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _lazy ( '<STR_LIT>' ) ) , <EOL> ] ) <EOL> class ZendeskSettingsError ( ZendeskError ) : <EOL> """<STR_LIT>""" <EOL> def get_zendesk ( ) : <EOL> """<STR_LIT>""" <EOL> zendesk_url = settings . ZENDESK_URL <EOL> zendesk_email = settings . ZENDESK_USER_EMAIL <EOL> zendesk_password = settings . ZENDESK_USER_PASSWORD <EOL> if not zendesk_url or not zendesk_email or not zendesk_password : <EOL> log . error ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> statsd . incr ( '<STR_LIT>' ) <EOL> raise ZendeskSettingsError ( '<STR_LIT>' ) <EOL> return Zendesk ( <EOL> zendesk_url , zendesk_email , zendesk_password , api_version = <NUM_LIT:2> ) <EOL> def submit_ticket ( email , category , subject , body , tags ) : <EOL> """<STR_LIT>""" <EOL> zendesk = get_zendesk ( ) <EOL> new_ticket = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : email , <EOL> '<STR_LIT>' : settings . ZENDESK_SUBJECT_PREFIX + subject , <EOL> '<STR_LIT:description>' : body , <EOL> '<STR_LIT>' : category , <EOL> '<STR_LIT>' : tags , <EOL> } <EOL> } <EOL> try : <EOL> ticket_url = zendesk . create_ticket ( data = new_ticket ) <EOL> statsd . incr ( '<STR_LIT>' ) <EOL> except ZendeskError as e : <EOL> log . error ( '<STR_LIT>' % e . msg ) <EOL> statsd . incr ( '<STR_LIT>' ) <EOL> raise <EOL> return ticket_url </s>
