def unregister_from_market(market): marketplace = None try: marketplace = Marketplace.objects.get(name=market) except: raise Exception('Not found') host = marketplace.host if host[-1] != '/': host += '/' marketadaptor = MarketAdaptor(host) try: marketadaptor.delete_store(settings.STORE_NAME) except HTTPError: raise Exception('Bad Gateway') marketplace.delete()
def register_on_market(name, host, site): # Check that the market name is not in use existing = True if host[-1] != '/': host += '/' try: Marketplace.objects.get(name=name) Marketplace.objects.get(host=host) except: existing = False if existing: raise Exception('Marketplace already registered') store_name = settings.STORE_NAME marketadaptor = MarketAdaptor(host) store_info = { 'store_name': store_name, 'store_uri': site, } try: marketadaptor.add_store(store_info) except HTTPError: raise Exception('Bad Gateway') try: Marketplace.objects.create(name=name, host=host) except Exception, e: # If the marketplace model creation fails it is necesary to unregister the store # in order to avoid an inconsistent state marketadaptor.delete_store(store_name) raise e