Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Created basic template tag and improved docs

  • Loading branch information...
commit 03784847c629798b094e1d09d8f56cf93d97eab4 1 parent b4fd90f
@overshard authored
View
1  MANIFEST.in
@@ -2,3 +2,4 @@ include README.md
recursive-include locator/static *
recursive-include locator/templates *
recursive-include locator/fixtures *
+recursive-include locator/templatetags *.py
View
69 README.md
@@ -11,6 +11,65 @@ An easy to integrate store locator plugin for Django.
4. Run `manage.py syncdb`.
+## Using the template tag
+
+django-locator is easy to include in your templates, you just need to do two
+things:
+
+ 1. Include the CSS and JS files on the page you're wanting to use django-locator.
+ 2. Load the django-locator template tag and insert it where you want it to show up.
+
+### Including the CSS and JS files
+
+There is one CSS file, place this line in your HTML header with the rest of your
+CSS imports:
+
+ <link rel="stylesheet" href="{{ STATIC_URL }}locator/css/map.css" />
+
+The JS is slightly more complex, first, make sure you don't already have jQuery,
+if you don't have jQuery then add this to the bottom of your HTML file but still
+inside your `<body></body>` tag:
+
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+
+Once you have jQuery you now need the Google Maps API JS files:
+
+ <script src="//maps.google.com/maps/api/js?sensor=false"></script>
+
+Close to the end! Now include the store locator JS file below both of these
+imports:
+
+ <script src="{{ STATIC_URL }}locator/js/jquery.storelocator.js"></script>
+
+Lastly we need to initialize the store locator script by putting this at the
+very bottom below the imports we just made:
+
+ <script>
+ $(function() {
+ $('#map-container').storeLocator({
+ 'jsonData': true,
+ 'dataLocation': '{% url locator:locations %}',
+ });
+ });
+ </script>
+
+### Loading the template tag
+
+Once you have the CSS and JS included the template tag is easy, add
+`{% load locator %}` to the top of your template and then put `{% locator %}`
+where you want the locator to show up on your page.
+
+
+## Customizing
+
+You can of course override everything in my CSS file easily by importing your
+own CSS file below it or copying my CSS file, making changes to it and then
+importing your changed CSS file instead of my own.
+
+Along with the basic CSS customizing see [Bjorn's blog post][0] about how you can
+modify our JavaScript initilizer to further customize your experience.
+
+
## Notes
I include an `initial_data.json` fixture to load in a few example items, you can
@@ -21,6 +80,12 @@ the locations are pulled via JSON from the URL `/locator/locations/` if you want
to use this data for anything else.
+## Credits
+
+Give all your thanks to [Bjorn][1] who created the [jQuery plugin][0] we make extensive
+use of in this app.
+
+
## License (Simplified BSD)
Copyright (c) Isaac Bythewood
@@ -46,3 +111,7 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+[0]: http://www.bjornblog.com/web/jquery-store-locator-plugin
+[1]: http://www.bjornblog.com/
View
18 locator/templates/locator/templatetags/locator.html
@@ -0,0 +1,18 @@
+<div id="form-container">
+ <form id="user-location" method="post" action="#">
+ <div id="form-input">
+ <label for="address">Enter Address or Zip Code:</label>
+ <input type="text" id="address" name="address" />
+ </div>
+
+ <div id="submit-btn"><input type="submit" id="submit" name="submit" value="Submit" /></div>
+ </form>
+</div>
+
+<div id="map-container">
+ <div id="loc-list">
+ <ul id="list"></ul>
+ </div>
+
+ <div id="map"></div>
+</div>
View
0  locator/templatetags/__init__.py
No changes.
View
11 locator/templatetags/locator.py
@@ -0,0 +1,11 @@
+from django.template.loader import render_to_string
+from django.template import Library
+from django.template import RequestContext
+
+
+register = Library()
+
+
+@register.simple_tag
+def locator():
+ return render_to_string('locator/templatetags/locator.html')
Please sign in to comment.
Something went wrong with that request. Please try again.