TODO: collect all of these together into leaf styles

css for carrot theme

have edited some of w-main.css for carrot theme.

experimental attempts to override ol's colors

/* attempt at carrot colors:
 * https://www.w3schools.com/colors/colors_picker.asp
 *
 * orange variants:
 * #f90;  rgb(255, 153, 0)    dark orange
 * #fc6;  rgb(255, 204, 102)  not-as-dark orange
 *
 * green variants:
 * #0f0  rgb(0,255,0)         solid green
 */

w3 color picker: https://www.w3schools.com/colors/colors_picker.asp

.

#f90: dark-ish orange
.
#fc6: not-as-dark orange
.
orange (text): orange
.
#0f0: solid green
.
#690: dark green
.
#9f6: light green
.
#aaff80: another light green
.

old (spring 2018 or so):

duh!

ModuleNotFoundError: No module named 'leaflet'

> pip3.6 install django-leaflet
Collecting django-leaflet
  Downloading https://files.pythonhosted.org/packages/f5/f1/373e6adc1402fc0dc1db109fa81e9802367d58df620fd2df0a6e486943fa/django-leaflet-0.23.0.tar.gz (274kB)
    100% |...| 276kB 2.2MB/s
Collecting Django (from django-leaflet)
  Downloading https://files.pythonhosted.org/packages/23/91/2245462e57798e9251de87c88b2b8f996d10ddcb68206a8a020561ef7bd3/Django-2.0.5-py3-none-any.whl (7.1MB)
    100% |...| 7.1MB 144kB/s
Requirement already satisfied: pytz in ./lib/python3.6 (from Django->django-leaflet)
Installing collected packages: Django, django-leaflet
  Running setup.py install for django-leaflet ... done
Successfully installed Django-2.0.5 django-leaflet-0.23.0
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

and un-comment 'maps',

in settings.py

Invalid HTTP_HOST header: 'leaf.ilikecarrots.com'. You may need to add 'leaf.ilikecarrots.com' to ALLOWED_HOSTS.

eventually:

added staticleaf app on /static to djleaf website

revisit djleaf issue on 11/21/2018:

webfaction control panel shows:

    Name djleaf
    Label Django 2.0.5 (mod_wsgi 4.6.4/Python 3.6)
    Description This creates an Apache server with mod_wsgi 4.6.4 and Python 3.6 installed running Django 2.0.5.

    The Django libraries are installed in the ~/webapps/<app_name>/lib/python3.6/django directory.

and it seems that that version of python does have the library:

    > /usr/local/bin/python3.6
    Python 3.6.7 (default, Oct 27 2018, 05:30:20)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import vectorformats
    >>>

Historical: don't remember exactly why djleaf was abandonded...

thought it was vectorformats; will revisit that issue here...

in urls.py:

    urlpatterns = [
       path('', views.map_page ),

in views.py:

    def map_page(request):
        foo = render_to_response('leaf.html' )
        return foo

however:

    > find . -name leaf.html
    ./staticmaps/leaf_old/leaf.html
    ./staticmaps/leaf.html

Hmm..., where is leaf.html coming from ???

PROBLEM, in settings.py:

    TEMPLATES = [
        ...
        'DIRS': [ '/home/wendell/webapps/staticmaps/', ],

will reset:

YES, template error now (which is good)

    ~/webapps/staticleaf
    cp ../staticmaps/leaf.html .

    ~/webapps
    mv staticmaps/leaf staticleaf/
    cp ../../staticmaps/b4_ol5_theirs/annyang.min.js .

then:

     ============== my_places_q
     .my_places:bbq
     qs
     Internal Server Error: /my_places_q/bbq
     Traceback (most recent call last):
       File "/home/wendell/webapps/djleaf/lib/python3.6/Django-2.0.5-py3.6.egg/django/db/backends/utils.py", line 85, in _execute
         return self.cursor.execute(sql, params)
     psycopg2.ProgrammingError: relation "leafproj_mylocations" does not exist
     LINE 1: ...n", "leafproj_mylocations"."geometry"::bytea FROM "leafproj_...
                                                                  ^
     django.db.utils.ProgrammingError: relation "leafproj_mylocations" does not exist
     LINE 1: ...n", "leafproj_mylocations"."geometry"::bytea FROM "leafproj_...

PROBLEM: each Django project needs its own database; it seems challenging to get project=leafproj to use project=maps's database

and

     from vectorformats.Feature import Feature
    File "/home/wendell/lib/python3.6/vectorformats-0.1-py3.6.egg/vectorformats/Feature.py", line 77
     except Exception, E:

NOPE, still a problem:

> python3.6
Python 3.6.7 (default, Oct 27 2018, 05:30:20)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from vectorformats.Feature import Feature
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wendell/lib/python3.6/vectorformats-0.1-py3.6.egg/vectorformats/Feature.py", line 77
    except Exception, E:
                    ^
SyntaxError: invalid syntax
>>>

and with

        print(sys.executable)
        print(sys.path)
        from vectorformats.Formats import Django, GeoJSON
        print ("imported vf!!!")

shows

        /usr/bin/python3

        ['/home/wendell/webapps/djleaf',
        '/home/wendell/webapps/djleaf/leafproj',
        '/home/wendell/webapps/djleaf/lib/python3.6',
        '/home/wendell/webapps/djleaf/lib/python3.6/Django-2.0.5-py3.6.egg',
        '/home/wendell/lib/python3.6',
        '/home/wendell/lib/python3.6/vectorformats-0.1-py3.6.egg',
        '/usr/local/lib/python36.zip',
        '/usr/local/lib/python3.6',
        '/usr/local/lib/python3.6/lib-dynload',
        '/usr/local/lib/python3.6/site-packages']

Q: how to install into ~/lib/python3.6 when using /usr/bin/python3 ???

a possible fix:

        cd ~/lib/python3.6/vectorformats-0.1-py3.6.egg/vectorformats
        vim Feature.py
                #wt: except Exception, E:
                except (Exception) as E:
        cd Formats
        vim GeoJSON.py
                #wt: except Exception, E:
                except (Exception) as E:

now:

    > python3.6
    Python 3.6.7 (default, Oct 27 2018, 05:30:20)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from vectorformats.Formats import Django, GeoJSON
    >>>

Yes, that fixed the vectorformats problem!

Now for the

    django.db.utils.ProgrammingError: relation "leafproj_mylocations" does not exist

hmm..., how to copy a table?

PostgreSQL + phpPgAdmin:

    -> Export
    * Structure and data
    Format: SQL
    Format: SQL (twice?)
    * Show
    -> Export

shows an SQL database dump as text...

--
-- PostgreSQL database dump
--

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET client_min_messages = warning;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: maps_mylocations; Type: TABLE; Schema: public; Owner: adminw; Tablespace:
--

CREATE TABLE public.maps_mylocations (
    id integer NOT NULL,
    pid text NOT NULL,
    name text NOT NULL,
    addr text NOT NULL,
    atype text NOT NULL,
    symbol text NOT NULL,
    description text NOT NULL,
    geometry public.geometry NOT NULL,
    CONSTRAINT enforce_dims_geometry CHECK ((public.st_ndims(geometry) = 2)),
    CONSTRAINT enforce_geotype_geometry CHECK (((public.geometrytype(geometry) = 'POINT'::text) OR (geometry IS NULL))),
    CONSTRAINT enforce_srid_geometry CHECK ((public.st_srid(geometry) = 4326))
);

djleaf's database tables

Q: now what about:

    sed 's/maps_/leafproj_/g'

???

1) using phpAdmin, create dump file:

2) rename dump.sql, then:

    sed 's/maps_/leafproj_/g' maps_dump.sql  > leafproj_dump.sql

3) use cmd line to insert:

psql -h localhost -U adminw sqlcarrots
Password for user adminw:
psql (9.4.20)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

sqlcarrots=> \dt
                    List of relations
 Schema |            Name             | Type  |  Owner
--------+-----------------------------+-------+----------
 ...
 public | maps_airports               | table | adminw
 public | maps_cdr                    | table | adminw
 public | maps_fixes                  | table | adminw
 public | maps_mylocations            | table | adminw
 public | maps_navaids                | table | adminw
 public | maps_plays                  | table | adminw
 ...
 sqlcarrots=> \q

seems good, here goes:

> psql -h localhost -U adminw sqlcarrots < leafproj_dump.sql
Password for user adminw:
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
ERROR:  relation "public.leafproj_mylocations" does not exist
ERROR:  syntax error at or near "4240"
LINE 1: 4240 Cheseapeake & Allegheny Live Steamers Cheseapeake & All...
<and lots more>

oops, use phpAdmin + Export + Structure Only to create a create file:

> psql -h localhost -U adminw sqlcarrots < leafproj_create.sql
Password for user adminw:
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE SEQUENCE
ALTER TABLE
ALTER SEQUENCE
ALTER TABLE
ALTER TABLE
CREATE INDEX

looks, good...

> psql -h localhost -U adminw sqlcarrots < leafproj_dump.sql
Password for user adminw:
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
COPY 1132
 setval
--------
   4551
(1 row)

seems ok!

restarted apache2, reloaded page, then:

127.0.0.1:51084] ============== my_places_q
127.0.0.1:51084] .my_places:bbq
127.0.0.1:51084] qs
127.0.0.1:51084] 192
127.0.0.1:51084] ################ calling serialize
127.0.0.1:51084] Internal Server Error: /my_places_q/bbq
127.0.0.1:51084] Traceback (most recent call last):
...
127.0.0.1:51084]     json.dump(self.get_dump_object(obj), self.stream, **self.json_kwargs)
127.0.0.1:51084]   File "/usr/local/lib/python3.6/json/__init__.py", line 176, in dump
127.0.0.1:51084]     default=default, sort_keys=sort_keys, **kw).iterencode(obj)
127.0.0.1:51084] TypeError: __init__() got an unexpected keyword argument 'properties'

properties is not fields, so:

... and with other misc edits,

and now djleaf / leafproj / Django2 / Python3 / PostGIS works!!!

yipee!!!

now for what this is all about...

geopy

testing:

> pip3.6 install geopy
> python3.6

# geopy.geocoders.GoogleV3()
# geopy.geocoders.GeocodeFarm()
# geopy.geocoders.TomTom()
# geopy.geocoders.GeoNames()
# geopy.geocoders.Bing( bing_key )

>>> import geopy
yipee!

>>> geopy.geocoders.GoogleV3(1)
<geopy.geocoders.googlev3.GoogleV3 object at 0x7fdf2d3ea550>

>>> geopy.geocoders.GeocodeFarm()
<geopy.geocoders.geocodefarm.GeocodeFarm object at 0x7fdf2d3ea588>

>>> geopy.geocoders.TomTom(1)
<geopy.geocoders.tomtom.TomTom object at 0x7fdf2d3ea550>

>>> geopy.geocoders.GeoNames(username="a")
<geopy.geocoders.geonames.GeoNames object at 0x7fdf27ee1f98>

>>> geopy.geocoders.Bing(1)
<geopy.geocoders.bing.Bing object at 0x7fdf27ee1c50>

>>>

various edits to:

    views.py
    urls.py

py2:
    https://maps.ilikecarrots.com/get_address?addr=3701+Connecticut+Ave.+NW,+Washington,+DC+20008

py3:
    https://leaf.ilikecarrots.com/get_address?addr=3701+Connecticut+Ave.+NW,+Washington,+DC+20008

warning, for whatever reason, them leaf url is:

    https://leaf.ilikecarrots.com/my_places_q/bbq

works:
    https://leaf.ilikecarrots.com/get_address/addr=3701+Connecticut+Avenue+NW,+Washington,+DC+20008

DON'T know why DJ2 doesn't want the '?' part, but it works anyway!

    response  "good"
    place     "Connecticut Ave NW, Washington, DC 20008, United States"
    lng       -77.0517832998698
    lat       38.9239988791332

how django processes urls

with '?' separating parameters

url:

    https://leaf.ilikecarrots.com/get_address?addr=3701+Connecticut+Ave.+NW,+Washington,+D.C.

in urls.py:

    from django.urls import path, re_path
        re_path('get_address?',  views.get_address ),

in views.py

    def get_address(request ):
        addr = request.GET["addr"]

with '/' separating parameters

NOTE: this url format is non-standard!!!

url:

    https://leaf.ilikecarrots.com/my_places_q/bbq

in urls.py:

    from django.urls import path, re_path
        path('my_places_q/<symbol>', views.my_places_q ),

in views.py

    def my_places_q(request, symbol ):
        print ("my_places_q:", symbol)

11/24/2018: move maps from djmaps

for djleaf:

* vectorformats works
* geopy works
* leafproj_mylocations is table in PostgreSQL (a COPY of maps_mylocations)
* figured out difference in django's processing of '?' and '/' in urls
* http://leaf.ilc redirects to https://ilc and certificate works
* can use setting.py MULTIURL_CONIFG to split maps and leaf when using one Django

here goes...

make backups

    > ./back.sh maps
    filename is: map_files_24-Nov-2018_170158.tgz

    > ./back.sh leaf
    filename is: leaf_files_24-Nov-2018_170228.tgz

leafproj/settings.py ( https://libraries.io/pypi/django-multiple-domains )

    ROOT_URLCONF = 'leafproj.urls_leaf'

    MULTIURL_CONFIG = {
        'maps.ilikecarrots.com' : 'leafproj.urls_maps',
        'leaf.ilikecarrots.com' : 'leafproj.urls_leaf',
        'pos.ilikecarrots.com'  : 'leafproj.urls_pos',
    }

    ALLOWED_HOSTS = [ 'leaf.ilikecarrots.com',
                      'maps.ilikecarrots.com',
                      'pos.ilikecarrots.com' ]

    INSTALLED_APPS = [
        ...
        # django-multiple-domain
        'multipledomain',    # Q: multi or multiple ???


    MIDDLEWARE = [
        ...
        'multipledomain.middleware.MultipleDomainMiddleware',   # 11/24/2018


    > pip3.6 install django-multiple-domains
      Running setup.py install for django-multiple-domains ... done
      Successfully installed django-multiple-domains-0.0.1
    > mv urls.py urls_leaf.py

Control Panel -> Domains / Websites -> Websites

good so far, now http://maps.ilc redirects to https://maps.ilc, BUT it shows the leaflet page...

urls_leaf.py:

    import urls_common
    urlpatterns += urls_common.common_urlpatterns

urls_common.py:

    common_urlpatterns = [...]

good...

urls_leaf:

    path('', views.leaf_map_page ),

urls_map:

    path('', views.ol5_map_page ),

views.py

    def ol5_map_page(request):
        foo = render_to_response('map.html' )
        return foo

    def leaf_map_page(request):
        foo = render_to_response('leaf.html' )
        return foo

and copy over the source tree:

    wendell@webfaction:~/webapps/staticleaf
    > cp ~/webapps/staticmaps/map.html .
    > cp -r ~/webapps/staticmaps/ol5 .

PROBLEM: maybe django-multiple-domains is the Dj1 version and doesn't work for dj2. ???

resequence

references:

considerations:

Sites Framework

NEVERMIND, here it is:

https://docs.djangoproject.com/en/1.11/ref/contrib/sites/#site-middleware and https://docs.djangoproject.com/en/2.0/ref/contrib/sites/ says:

Add django.contrib.sites.middleware.CurrentSiteMiddleware to MIDDLEWARE. The middleware sets the site attribute on every request object, so you can use request.site to get the current site.

settings.py:

    ROOT_URLCONF = 'leafproj.urls'

    MIDDLEWARE = [
        ...
        'django.contrib.sites.middleware.CurrentSiteMiddleware', #11/24/2018

urls.py:

    urlpatterns = [
        path('', views.both_map_page ),

views.py:

    def both_map_page(request):

        if (str(request.site) == "maps.ilikecarrots.com"):
            foo = render_to_response('map.html' )

        if (str(request.site) == "leaf.ilikecarrots.com"):
            foo = render_to_response('leaf.html' )

        return foo

YIPEE! Both seem to work now!!!

SUCCESS, both maps (ol5) and leaf (leaflet) are now on Django2 + Python 3!

geopy

which was the driving issue behind all of this...

TODO: other address finders in geopy