Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore menu fix - now goes to random country #56

Merged
merged 12 commits into from
Apr 18, 2014
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ django_files/atlas/settings_local.py
media/js/explore/viz_general.js

media/js/explore/viz_general.js

#virtualenv
env/
#editor config data for rope
.ropeproject/
56 changes: 28 additions & 28 deletions django_files/atlas/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,46 @@ def render_to_response(self, context, **kwargs):


urlpatterns = patterns('',

## Exploring new patterns
#(r'^redesign/', include('redesign.urls')),
# (r'^usa/', include('usa.urls')),
# (r'^redesign/', include('redesign.urls')),
####
## Revisiting old patterns
####
# (r'^redesign/', include('redesign.urls')),
####
## Revisiting old patterns
####

# (r'^new_ps/', 'observatory.views.new_ps'),
# internationalization ######################################################
(r'^i18n/', include('django.conf.urls.i18n')),
(r'^set_language/(?P<lang>[a-z-]{2,5})/$', 'observatory.views.set_language'),

# product classification ####################################################
(r'^set_product_classification/(?P<prod_class>[a-z0-9]{3,5})/$', 'observatory.views.set_product_classification'),

# general site ############################################################
(r'^$', 'observatory.views.home'),
(r'^download/$', 'observatory.views.download'),

# about section ###########################################################
(r'^about/$', 'observatory.views.about'),
(r'^about/data/$', RedirectView.as_view(url='/about/data/sitc4/')),
(r'^about/data/$', RedirectView.as_view(url='/about/data/sitc4/')),
(r'^about/data/(?P<data_type>\w+)/$', "observatory.views.about_data"),
(r'^about/permissions/$', "observatory.views.permissions"),
(r'^about/support/$', "observatory.views.support"),
(r'^about/research/$', "observatory.views.research"),
(r'^about/glossary/$', "observatory.views.glossary"),
(r'^about/team/$', "observatory.views.team"),
(r'^about/data/$', "observatory.views.data"),
(r'^about/permissions/$', "observatory.views.permissions"),
(r'^about/privacy/$', "observatory.views.privacy"),
(r'^about/support/$', "observatory.views.support"),
(r'^about/research/$', "observatory.views.research"),
(r'^about/glossary/$', "observatory.views.glossary"),
(r'^about/team/$', "observatory.views.team"),
(r'^about/data/$', "observatory.views.data"),
(r'^about/permissions/$', "observatory.views.permissions"),
(r'^about/privacy/$', "observatory.views.privacy"),
# blog
(r'^about/blog/$', "blog.views.blog_index"),
url(r'^about/blog/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', "blog.views.blog_post_detail", name="blog_post"),

# book ###################################################################
(r'^book/$', 'observatory.views.book'),

# API #######################################################################
(r'^api/$', 'observatory.views.api'),
(r'^api/apps/$', 'observatory.views.api_apps'),
Expand All @@ -90,7 +90,7 @@ def render_to_response(self, context, **kwargs):
(r'^publishstory/$','observatory.views.published'),
(r'^likeCount/$','observatory.views.likeCount'),
(r'^featurestory/$','observatory.views.featured'),
(r'^endbrowsestory/$','observatory.views.endbrowsestory'),
(r'^endbrowsestory/$','observatory.views.endbrowsestory'),
(r'^browsestories/(?P<browseStoryId>\d+)/$','observatory.views.browsestories'),
(r'^stories/$','observatory.views.browseStoryForm'),
(r'^endSaveStory/$','observatory.views.endSaveStory'),
Expand All @@ -101,16 +101,16 @@ def render_to_response(self, context, **kwargs):
# Explore (App) #############################################################
# Legacy app redirect
(r'^app/(?P<app_name>[a-z0-9_]+)/(?P<trade_flow>\w{6,10})/(?P<filter>[a-z0-9\.]+)/(?P<year>[0-9\.]+)/$', 'observatory.views.app_redirect'),

# New app URL structure
(r'^explore/$', RedirectView.as_view(url=HTTP_HOST+'explore/tree_map/export/usa/all/show/2012/')),
(r'^explore/$', 'observatory.views.explore_random'),
(r'^explore/(?P<app_name>[a-z_]+)/(?P<trade_flow>\w{6,10})/(?P<country1>\w{3,4})/(?P<country2>\w{3,4})/(?P<product>\w{3,4})/(?P<year>[0-9\.]+)/$', 'observatory.views.explore'),
(r'^explore/(?P<app_name>[a-z_]+)/(?P<trade_flow>\w{6,10})/(?P<country1>\w{3,4})/(?P<country2>\w{3,4})/(?P<product>\w{3,4})/$', 'observatory.views.explore'),

# Find similar countries
# (r'^similar/(?P<country>\w{2,3})/(?P<year>[0-9\.]+)/$', 'observatory.views.similar'),
(r'^similar_wdi/(?P<country>\w{2,3})/(?P<indicator>\d+)/(?P<year>[0-9\.]+)/$', 'observatory.views.similar_wdi'),

# Embed URL
(r'^embed/(?P<app_name>[a-z_]+)/(?P<trade_flow>\w{6,10})/(?P<country1>\w{3,4})/(?P<country2>\w{3,4})/(?P<product>\w{3,4})/(?P<year>[0-9\.]+)/$', 'observatory.views.embed'),

Expand All @@ -121,15 +121,15 @@ def render_to_response(self, context, **kwargs):
(r'^api/(?P<trade_flow>[a-z_]{6,10})/(?P<country1>\w{3})/(?P<country2>\w{3})/show/(?P<year>[0-9\.]+)/$', 'observatory.views.api_ccsy'),
(r'^api/(?P<trade_flow>[a-z_]{6,10})/(?P<country1>\w{3})/show/(?P<product>\w{4})/(?P<year>[0-9\.]+)/$', 'observatory.views.api_cspy'),
(r'^api/(?P<trade_flow>[a-z_]{6,10})/show/all/(?P<product>\w{4})/(?P<year>[0-9\.]+)/$', 'observatory.views.api_sapy'),

(r'^api/near/(?P<country>\w{3})/(?P<year>[0-9\.]+)/(?P<num_prods>\d+)/$', 'observatory.views_exhibit.api_near'),

# Overview (Countries) ######################################################
(r'^country/(?P<country>\w{2,3})/$', 'observatory.views_overview.country2'),
(r'^hs4/(?P<product>\d{4})/$', 'observatory.views_overview.product'),
(r'^sitc4/(?P<product>\d{4})/$', 'observatory.views_overview.product'),
# (r'^profile/(?P<country>\w{2,3})/(?P<trade_flow>[a-z_]{6})/$', 'observatory.views_overview.country'),

# Overview (Products) ######################################################
(r'^overview/(?P<product>\d{4})/$', 'observatory.views_overview.product'),
(r'^overview/(?P<product>\d{4})/(?P<trade_flow>[a-z_]{6})/$', 'observatory.views_overview.product'),
Expand All @@ -140,7 +140,7 @@ def render_to_response(self, context, **kwargs):
(r'^rankings/(?P<category>\w{7})/(?P<year>[0-9\.]+)/$', 'observatory.views_rankings.index'),
(r'^rankings/(?P<category>\w{7})/download/$', 'observatory.views_rankings.download'),
(r'^rankings/(?P<category>\w{7})/(?P<year>[0-9\.]+)/download/$', 'observatory.views_rankings.download'),

# Exhibit ###################################################################
(r'^exhibit/$', 'observatory.views_exhibit.index'),
(r'^exhibit/country_selection/$', 'observatory.views_exhibit.country_selection'),
Expand Down
66 changes: 34 additions & 32 deletions django_files/observatory/helpers.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
from observatory.models import *
import random

# make sure app name is in the list of possible apps
def get_app_name(app_name):
possible_apps = ["tree_map", "stacked", "product_space", "map"]

# if the app_name requested is not in the list of possibilities
if app_name not in possible_apps:
app_name = None

return app_name


# make sure this is accepted trade_flow
def get_trade_flow(trade_flow):
possible_yoga_flows = ["export", "import", "net_export", "net_import"]

if trade_flow not in possible_yoga_flows:
trade_flow = None
return trade_flow

return trade_flow


def get_years(classification):
# get distince years from db, different for diff product classifications

if classification == "sitc4":
years_available = list(Sitc4_cpy.objects.values_list("year", flat=True).distinct())
elif classification == "hs4":
years_available = list(Hs4_cpy.objects.values_list("year", flat=True).distinct())

return years_available


# Returns app type in CCPY format
# Returns app type in CCPY format
def get_app_type(country1, country2, product, year):

# country / all / show / year
if country2 == "all" and product == "show":
return "casy"

# country / show / all / year
elif country2 == "show" and product == "all":
return "csay"

# show / all / product / year
elif country1 == "show" and country2 == "all":
return "sapy"

# country / country / show / year
elif product == "show":
return "ccsy"

# country / show / product / year
else:
return "cspy"
Expand Down Expand Up @@ -98,56 +99,57 @@ def get_product(product, classification):

# Returns the question to display on the page describing the URL requested
def get_question(app_type, **kwargs):

trade_flow = kwargs["trade_flow"]

if app_type == "casy":
origin = kwargs["origin"]
origin = kwargs["origin"]

if trade_flow in ['net_export','net_import']:
title = "What does %s %s in net terms?" % (origin.name, trade_flow.replace("_", " ").split()[1])
else:
title = "What does %s %s?" % (origin.name, trade_flow.replace("_", " "))

# Country but showing other country trade partners
elif app_type == "csay":
origin = kwargs["origin"]
origin = kwargs["origin"]

article = "to" if trade_flow in ["export","net_export"] else "from"
if trade_flow in ['net_export','net_import']:
title = "Where does %s %s %s in net terms? " % (origin.name, trade_flow.replace("_", " ").split()[1], article)
title = "Where does %s %s %s in net terms? " % (origin.name, trade_flow.replace("_", " ").split()[1], article)
else:
title = "Where does %s %s %s?" % (origin.name, trade_flow.replace("_", " "), article)
title = "Where does %s %s %s?" % (origin.name, trade_flow.replace("_", " "), article)

# Product
elif app_type == "sapy":
product = kwargs["product"]

if trade_flow in ['net_export','net_import']:
title = "Who %ss %s in net terms?" % (trade_flow.replace("_", " ").split()[1], product.name_en)
else:
title = "Who %ss %s in net terms?" % (trade_flow.replace("_", " ").split()[1], product.name_en)
else:
title = "Who %ss %s?" % (trade_flow.replace("_", " "), product.name_en)

# Bilateral Country x Country
elif app_type == "ccsy":
origin = kwargs["origin"]
destination = kwargs["destination"]

article = "to" if trade_flow in ["export","net_export"] else "from"
if trade_flow in ['net_export','net_import']:
title = "What does %s %s %s %s in net terms?" % (origin.name, trade_flow.replace("_", " ").split()[1], article, destination.name)
else:
title = "What does %s %s %s %s?" % (origin.name, trade_flow, article, destination.name)

# Bilateral Country / Show / Product / Year
elif app_type == "cspy":
origin = kwargs["origin"]
origin = kwargs["origin"]
product = kwargs["product"]

article = "to" if trade_flow in ["export","net_export"] else "from"
if trade_flow in ['net_export','net_import']:
title = "Where does %s %s %s %s in net terms?" % (origin.name, trade_flow.replace("_", " ").split()[1], product.name_en, article)
else:
title = "Where does %s %s %s %s?" % (origin.name, trade_flow, product.name_en, article)

return title

Loading