Commits

Viorel Stirbu  committed 559a29b

serving shopmania feed from the right location

  • Participants
  • Parent commits c9b426d

Comments (0)

Files changed (3)

File atexpc/atex_web/management/commands/synchronize.py

 logger = logging.getLogger(__name__)
 
 PRODUCT_DB_FIELDS = ('id', 'model', 'name')
-SHOPMANIA_FEED_FILENAME = os.path.join(settings.PROJECT_ROOT,
-    'atex_web', 'media', 'shopmania.csv')
 
 class Command(BaseCommand):
     helf = "Synchronize Ancora products to local database AND (optionally) to Shopmania feed file"
         writers = [self.create_or_update_products]
 
         if options['shopmania']:
-            temp_feed_filename = SHOPMANIA_FEED_FILENAME + '.tmp'
+            feed_filename = os.path.join(settings.MEDIA_ROOT, settings.SHOPMANIA_FEED_FILE)
+            temp_feed_filename = feed_filename + '.tmp'
             if os.path.exists(temp_feed_filename):
                 os.remove(temp_feed_filename)
             writers.append(partial(self.add_products_to_shopmania_feed, temp_feed_filename))
         self.synchronize(writers)
 
         if options['shopmania']:
-            if os.path.exists(temp_feed_filename) and os.path.exists(SHOPMANIA_FEED_FILENAME):
-                os.remove(SHOPMANIA_FEED_FILENAME)
-                os.rename(temp_feed_filename, SHOPMANIA_FEED_FILENAME)
+            if os.path.exists(temp_feed_filename) and os.path.exists(feed_filename):
+                os.remove(feed_filename)
+                os.rename(temp_feed_filename, feed_filename)
 
         # Assign existing images for new products
         Product.objects.assign_images()

File atexpc/atex_web/urls.py

 from django.conf.urls.static import static
 from django.conf import settings
 from django.shortcuts import render
+from django.views.generic.simple import redirect_to
 from views import GenericView, HomeView, SearchView, ProductView, ContactView
 
 urlpatterns = patterns('',
     url(r'^contact/', ContactView.as_view(), name='contact'),
     url(r'PIE\.htc$',
         lambda request: render(request, "PIE.htc", content_type="text/x-component")),
+    # TODO: remove ledacy redirect sm.ashx to MEDIA_URL + SHOPMANIA_FEED_FILE
+    url(r'^sm.ashx$', redirect_to, {'url': '/media/shopmania.csv'}),
 )
 
 if settings.DEBUG:

File atexpc/settings.py

 DROPBOX_ACCESS_TOKEN = os.environ.get('DROPBOX_ACCESS_TOKEN')
 DROPBOX_ACCESS_TOKEN_SECRET = os.environ.get('DROPBOX_ACCESS_TOKEN_SECRET')
 
+SHOPMANIA_FEED_FILE = 'shopmania.csv' # in media root
+
 if 'test' in sys.argv:
     DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'