diff --git a/.gitignore b/.gitignore index 846ce65..0c83afa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ .gondor +.vagrant *.pyc +ansible/vagrant.retry pythonkc_site/pythonkc.sqlite pythonkc_site/local_settings.py pythonkc_site/private_settings.py +pythonkc_site/.env diff --git a/AUTHORS b/AUTHORS index ba1816e..624364f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,4 +2,6 @@ Steven Cummings Julia Elman Matthew Irish Mark Ransom +Jon Smajda Jeff Triplett +Chip Warden diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..89ba317 --- /dev/null +++ b/README.markdown @@ -0,0 +1,86 @@ +# `pythonkc.com` website + +[![Join the chat at https://gitter.im/pythonkc/pythonkc.com](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pythonkc/pythonkc.com?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +Files for the `pythonkc.com` website. + +## Development Quickstart Option 1 (vagrant) + +We're going to use Vagrant and Virtualbox to run pythonkc.com inside a Debian +VM. We're using the [shell provisioner][shell] to install Ansible inside our VM and +then using Ansible to manage the environment from there. (Note: we're *not* +using the [ansible provisioner][ansible].) + +First you need to install [Vagrant][vagrant] and [VirtualBox][virtualbox] and clone [our +repository][repo] from github. + +Now copy `pythonkc_site/.env.example` to `pythonkc_site/.env` and add +your own [meetup api key][meetup] and a unique [django secret key][django] (`.env` will +be ignored by git) + +Then you have to install some vagrant plugins and build your vagrant box: + +``` +vagrant plugin install vagrant-vbguest +vagrant plugin install vagrant-hostmanager +vagrant plugin install vagrant-hostsupdater +vagrant up +``` + +`vagrant up` will run `provision.sh` which runs ansible on the VM. + +We've done this so you don't have to install ansible on your local machine. + +If you'd prefer you can always ssh in and run/re-run the provisioner manually +(the output is a little nicer this way): + +``` +vagrant ssh +cd ~/vagrant/ansible +ansible-playbook vagrant.yml +``` + +To run the Django development server: + +``` +vagrant ssh +django-admin runserver 192.168.100.101:8000 +``` + +Now go to `http://192.168.100.101:8000` in your browser. You can edit the files +on your local machine and the server should reload automatically. + +For now, this is a Python 2 project. If you want to start using Python 3 +and help us fix our problems, set Ansible's `python_version` variable to 3 +and it will build the virtualenv using Python 3: + +``` +ansible-playbook vagrant.yml -e python_version=3 +``` + + +## Development Quickstart Option 2 (virtualenv) + +``` +mkvirtualenv pythonkc +git clone git@github.com:pythonkc/pythonkc-com.git +cd pythonkc.com/pythonkc_site +pip install -r requirements/project.txt +python manage.py runserver +``` + +Profit! $$$ + +## More Detailed Instructions + +See: docs/local_development + + + +[ansible]: http://docs.vagrantup.com/v2/provisioning/ansible.html +[django]: http://www.miniwebtool.com/django-secret-key-generator/ +[meetup]: https://secure.meetup.com/meetup_api/key/ +[repo]: https://github.com/pythonkc/pythonkc-com +[shell]: http://docs.vagrantup.com/v2/provisioning/shell.html +[vagrant]: https://www.vagrantup.com/downloads.html +[virtualbox]: https://www.virtualbox.org diff --git a/README.rst b/README.rst deleted file mode 100644 index acc6f07..0000000 --- a/README.rst +++ /dev/null @@ -1,4 +0,0 @@ -PYTHONKC.COM WEBSITE -==================== - -Files for the PythonKC.com website. diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..faf70a9 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,63 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +VAGRANTFILE_API_VERSION = "2" + +# Allow host platform checks +# http://stackoverflow.com/questions/26811089/vagrant-how-to-have-host-platform-specific-provisioning-steps +module OS + def OS.windows? + (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil + end + + def OS.mac? + (/darwin/ =~ RUBY_PLATFORM) != nil + end + + def OS.unix? + !OS.windows? + end + + def OS.linux? + OS.unix? and not OS.mac? + end +end + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + + # vagrant-hostmanager plugin is required + unless Vagrant.has_plugin?("vagrant-hostmanager") + raise 'vagrant-hostmanager is not installed. run: vagrant plugin install vagrant-hostmanager' + end + + # vagrant-hostsupdater plugin is required + unless Vagrant.has_plugin?("vagrant-hostsupdater") + raise 'vagrant-hostsupdater is not installed. run: vagrant plugin install vagrant-hostsupdater' + end + + # vagrant-vbguest plugin is required + unless Vagrant.has_plugin?("vagrant-vbguest") + raise 'vagrant-vbguest is not installed. run: vagrant plugin install vagrant-vbguest' + end + + config.vm.define "pykcdevel" do |pykcdevel| + pykcdevel.vm.box = "debian/jessie64" + pykcdevel.vm.hostname = "pythonkc.devel" + pykcdevel.vm.network "private_network", type: "dhcp" + if OS.unix? + pykcdevel.vm.synced_folder "./", "/vagrant/", type: "nfs" + elsif OS.windows? + pykcdevel.vm.synced_folder "./", "/vagrant/", type: "smb" + else + raise 'Unknown host operating system. Cannot continue.' + end + + pykcdevel.vm.provider "virtualbox" do |vb| + vb.name = "pykcdevel" + vb.memory = 512 + vb.cpus = 2 + vb.customize ["modifyvm", :id, "--cpuexecutioncap", "80"] + end + pykcdevel.vm.provision :shell, :path => "provision.sh" + end +end diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..0b186f5 --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +hostfile = ./hosts +transport = ssh diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml new file mode 100644 index 0000000..a7c25ae --- /dev/null +++ b/ansible/group_vars/all.yml @@ -0,0 +1,2 @@ +--- +virtualenv: ~/virtualenvs/pythonkc diff --git a/ansible/group_vars/production.yml b/ansible/group_vars/production.yml new file mode 100644 index 0000000..dd9c76e --- /dev/null +++ b/ansible/group_vars/production.yml @@ -0,0 +1,4 @@ +--- +user: pythonkc +pythonpath: /TODO +project_root: /TODO/pythonkc_site diff --git a/ansible/group_vars/vagrant.yml b/ansible/group_vars/vagrant.yml new file mode 100644 index 0000000..61df658 --- /dev/null +++ b/ansible/group_vars/vagrant.yml @@ -0,0 +1,4 @@ +--- +user: vagrant +pythonpath: /home/vagrant/vagrant +project_root: /home/vagrant/vagrant/pythonkc_site diff --git a/ansible/hosts b/ansible/hosts new file mode 100644 index 0000000..f163a81 --- /dev/null +++ b/ansible/hosts @@ -0,0 +1,6 @@ +[vagrant] +localhost ansible_connection=local + +# TODO +#[production] +#pythonkc.com diff --git a/ansible/roles/pythonkc/defaults/main.yml b/ansible/roles/pythonkc/defaults/main.yml new file mode 100644 index 0000000..cef7389 --- /dev/null +++ b/ansible/roles/pythonkc/defaults/main.yml @@ -0,0 +1,2 @@ +--- +python_version: 2 diff --git a/ansible/roles/pythonkc/tasks/django.yml b/ansible/roles/pythonkc/tasks/django.yml new file mode 100644 index 0000000..168c1ff --- /dev/null +++ b/ansible/roles/pythonkc/tasks/django.yml @@ -0,0 +1,47 @@ +--- +- name: Create virtualenvs directory + file: dest=~/virtualenvs state=directory owner={{ user }} group={{ user }} + + +- name: Install requirements into Python 2.7 virtualenv + pip: + requirements: "{{ project_root }}/requirements/project.txt" + virtualenv: "{{ virtualenv }}" + virtualenv_command: /usr/bin/virtualenv -p python2.7 + when: python_version == 2 + + +- name: Install requirements into Python 3 virtualenv + pip: + requirements: "{{ project_root }}/requirements/project.txt" + virtualenv: "{{ virtualenv }}" + virtualenv_command: python3 /usr/lib/python3/dist-packages/virtualenv.py -p python3 + when: python_version == 3 + + +- name: Set some env vars when activating virtualenv + lineinfile: + dest: "{{ virtualenv }}/bin/activate" + regexp: "^export {{ item.name }}=" + line: "export {{ item.name }}={{ item.value }}" + state: present + insertafter: EOF + with_items: + - {name: DJANGO_SETTINGS_MODULE, value: pythonkc_site.settings} + - {name: PYTHONPATH, value: "{{ pythonpath }}"} + + +- name: Automatically activate the virtualenv in bashrc + lineinfile: + dest: ~/.bashrc + line: "source {{ virtualenv }}/bin/activate" + state: present + insertafter: EOF + + +- name: Run migrations + django_manage: + command: migrate + app_path: "{{ project_root }}" + pythonpath: "{{ pythonpath }}" + virtualenv: "{{ virtualenv }}" diff --git a/ansible/roles/pythonkc/tasks/main.yml b/ansible/roles/pythonkc/tasks/main.yml new file mode 100644 index 0000000..580670f --- /dev/null +++ b/ansible/roles/pythonkc/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- {include: python2.yml, tags: python, when: python_version == 2} +- {include: python3.yml, tags: python, when: python_version == 3} +- include: tools.yml tags=tools +- include: django.yml tags=django + +# TODO +# vim + vim configuration for python? +# postgres? (for now just using sqlite for development) diff --git a/ansible/roles/pythonkc/tasks/python2.yml b/ansible/roles/pythonkc/tasks/python2.yml new file mode 100644 index 0000000..3acaf12 --- /dev/null +++ b/ansible/roles/pythonkc/tasks/python2.yml @@ -0,0 +1,17 @@ +--- +- name: Update apt + apt: update_cache=yes cache_valid_time=3600 + become: yes + tags: apt + +- name: Install some base packages + apt: pkg="{{item}}" state=latest + become: yes + tags: apt + with_items: + - build-essential + - libpq-dev + - python-dev + - python-pip + - python-software-properties + - python-virtualenv diff --git a/ansible/roles/pythonkc/tasks/python3.yml b/ansible/roles/pythonkc/tasks/python3.yml new file mode 100644 index 0000000..536f083 --- /dev/null +++ b/ansible/roles/pythonkc/tasks/python3.yml @@ -0,0 +1,18 @@ +--- +- name: Update apt + apt: update_cache=yes cache_valid_time=3600 + become: yes + tags: apt + +- name: Install some base packages + apt: pkg="{{item}}" state=latest + become: yes + tags: apt + with_items: + - build-essential + - libpq-dev + - python3 + - python3-dev + - python3-pip + - python3-software-properties + - python3-virtualenv diff --git a/ansible/roles/pythonkc/tasks/tools.yml b/ansible/roles/pythonkc/tasks/tools.yml new file mode 100644 index 0000000..e975012 --- /dev/null +++ b/ansible/roles/pythonkc/tasks/tools.yml @@ -0,0 +1,16 @@ +--- +- name: Update apt + apt: update_cache=yes cache_valid_time=3600 + become: yes + tags: apt + + +- name: Install some dev tools packages + apt: pkg="{{item}}" state=latest + become: yes + tags: apt + with_items: + - vim-nox + - htop + +# TODO basic vimrc with python plugins? diff --git a/ansible/vagrant.yml b/ansible/vagrant.yml new file mode 100644 index 0000000..b03563c --- /dev/null +++ b/ansible/vagrant.yml @@ -0,0 +1,5 @@ +--- +- hosts: vagrant + roles: + - pythonkc + diff --git a/docs/local_development.rst b/docs/local_development.rst index 183fc59..6b484bc 100644 --- a/docs/local_development.rst +++ b/docs/local_development.rst @@ -10,8 +10,6 @@ Running PythonKC.com Locally #. ``pip install -r requirements/project.txt`` -#. ``python manage.py syncdb`` - #. Create ``local_settings.py``, with:: DEBUG = TEMPLATE_DEBUG = True @@ -20,23 +18,22 @@ Running PythonKC.com Locally # Otherwise, you probably want emails you test with to come to you: CONTACT_EMAIL_TO = ['me@gmail.com'] -#. Create ``private_settings.py`` with: +#. Create a `.env` file with:: - #. Meetup.com API key:: + #!/bin/sh + export MEETUP_API_KEY="" + export DJANGO_SECRET_KEY="" + + # if you're not using console.EmailBackend: + export EMAIL_HOST_USER="" + export EMAIL_HOST_PASSWORD="" - MEETUP_API_KEY = "" +#. Source your .env file: ``source .env``. - #. SMTP settings (if you kept the default email backend of SMTP above):: - - # For example.... - EMAIL_HOST = "smtp.gmail.com" - EMAIL_PORT = 587 - EMAIL_USE_TLS = True - EMAIL_HOST_USER = "contact@pythonkc.com" - EMAIL_HOST_PASSWORD = "*******************" +#. ``python manage.py syncdb`` #. ``python manage.py runserver`` #. Profit!!! -Note that both ``local_settings.py`` and ``private_settings.py`` are in our ``.gitignore``, so you don't commit what you do there. +Note that both ``local_settings.py`` and ``.env`` are in our ``.gitignore``, so you don't commit what you do there. diff --git a/provision.sh b/provision.sh new file mode 100644 index 0000000..62d57d4 --- /dev/null +++ b/provision.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +export DEBIAN_FRONTEND=noninteractive + +aptitude update +aptitude purge -y chef chef-zero puppet puppet-common +aptitude dist-upgrade -y +ln -sf /vagrant /home/vagrant/ +mkdir -p /var/www +ln -sf /vagrant/pythonkc_site /var/www/pythonkc_site + +if [[ -z "$(which ansible)" ]]; then + echo "Installing pip and Ansible..." + aptitude install -y python-dev python-pip + pip2 install ansible +fi + +cd /home/vagrant/vagrant/ansible +sudo -H -u vagrant ansible-playbook vagrant.yml diff --git a/pythonkc_site/.env.example b/pythonkc_site/.env.example new file mode 100644 index 0000000..6c2df8c --- /dev/null +++ b/pythonkc_site/.env.example @@ -0,0 +1,2 @@ +MEETUP_API_KEY='your-meetup-api-key-here' +DJANGO_SECRET_KEY='django-secret-key-here' diff --git a/pythonkc_site/manage.py b/pythonkc_site/manage.py old mode 100644 new mode 100755 index 3e4eedc..085cc5a --- a/pythonkc_site/manage.py +++ b/pythonkc_site/manage.py @@ -1,14 +1,11 @@ #!/usr/bin/env python -from django.core.management import execute_manager -import imp -try: - imp.find_module('settings') # Assumed to be in the same directory. -except ImportError: - import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) - sys.exit(1) +import os +import sys -import settings if __name__ == "__main__": - execute_manager(settings) + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pythonkc_site.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/pythonkc_site/meetups/events.py b/pythonkc_site/meetups/events.py index f89e22d..e6ca379 100644 --- a/pythonkc_site/meetups/events.py +++ b/pythonkc_site/meetups/events.py @@ -22,8 +22,8 @@ raise ImproperlyConfigured('MEETUP_API_KEY is required in settings') -meetups = PythonKCMeetups(api_key, http_timeout=6) num_past_events = getattr(settings, 'MEETUP_SHOW_PAST_EVENTS', 3) +meetups = PythonKCMeetups(api_key, num_past_events=num_past_events, http_timeout=6) def memoize_in_cache(cache_key, cache_timeout_seconds=None): @@ -38,8 +38,8 @@ def memoize_in_cache(cache_key, cache_timeout_seconds=None): """ backup_cache_key = cache_key + '_backup' - backup_cache_timeout_seconds = (cache_timeout_seconds * 100 - if cache_timeout_seconds else + backup_cache_timeout_seconds = (cache_timeout_seconds * 10000 + if cache_timeout_seconds else 60 * 60 * 24) def decorator(func): @@ -50,7 +50,7 @@ def decorated(): try: value = func() cache.set(cache_key, value, cache_timeout_seconds) - cache.set(backup_cache_key, value, + cache.set(backup_cache_key, value, backup_cache_timeout_seconds) except: value = cache.get(backup_cache_key) diff --git a/pythonkc_site/requirements/gondor.txt b/pythonkc_site/requirements/gondor.txt new file mode 100644 index 0000000..5124d33 --- /dev/null +++ b/pythonkc_site/requirements/gondor.txt @@ -0,0 +1,2 @@ +gondor==1.0.5 +wsgiref==0.1.2 diff --git a/pythonkc_site/requirements/project.txt b/pythonkc_site/requirements/project.txt index 2efc7bd..f109233 100644 --- a/pythonkc_site/requirements/project.txt +++ b/pythonkc_site/requirements/project.txt @@ -1,6 +1,9 @@ -Django==1.3.1 -gondor==1.0 -psycopg2==2.4.2 -South==0.7.3 -pythonkc-meetups==0.0.5 +Django==4.2.30 +django-dotenv==1.3.0 django-redis-cache==0.9.2 +mimeparse==0.1.3 +psycopg2==2.6.1 +python-dateutil==1.5 +pythonkc-meetups==0.1.0 +redis==2.10.3 +requests==2.32.4 diff --git a/pythonkc_site/settings.py b/pythonkc_site/settings.py index 244225a..2b12fef 100644 --- a/pythonkc_site/settings.py +++ b/pythonkc_site/settings.py @@ -1,6 +1,11 @@ # Django settings for pythonkc_site project. import os +from os.path import abspath, dirname, join + +import dotenv +dotenv.read_dotenv(abspath(join(dirname(__file__), '.env'))) + PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) @@ -12,6 +17,8 @@ MANAGERS = ADMINS +SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY') + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. @@ -23,6 +30,8 @@ } } +ALLOWED_HOSTS = ['pythonkc.com', 'www.pythonkc.com'] + # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. @@ -117,7 +126,6 @@ #'django.contrib.admin', # Uncomment the next line to enable admin documentation: #'django.contrib.admindocs', - 'south', 'pythonkc_site.contact', ) @@ -158,6 +166,13 @@ CONTACT_EMAIL_FROM = 'noreply@pythonkc.com' CONTACT_EMAIL_TO = ['pythonkc@gmail.com'] +EMAIL_HOST = "smtp.gmail.com" +EMAIL_PORT = 587 +EMAIL_USE_TLS = True +EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER") +EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD") +MEETUP_API_KEY = os.environ.get("MEETUP_API_KEY") + try: from local_settings import * except ImportError: @@ -165,7 +180,7 @@ try: - # NOTE The GONDOR_REDIS_* settings are placed in local_settings by the + # NOTE The GONDOR_REDIS_* settings are placed in local_settings by the # Gondor runtime. CACHES = { 'default': { @@ -183,9 +198,3 @@ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', } } - - -try: - from private_settings import * -except ImportError: - pass diff --git a/pythonkc_site/static/screen.css b/pythonkc_site/static/screen.css index 3ea2e68..ea6d780 100644 --- a/pythonkc_site/static/screen.css +++ b/pythonkc_site/static/screen.css @@ -125,6 +125,9 @@ h3{ width: 400px; float: left; } +.past-event.no-photo .details { + width: 910px; +} .past-event .event-photo { float: left; width: 500px; @@ -321,17 +324,14 @@ section.resources{ } .contact-form *:-moz-placeholder { - background-color: #1B82B3; - color: #87CDED; + color: #219cd7; } /* Combining these as *::-webkit-input-placeholder didn't seem to work...*/ .contact-form input::-webkit-input-placeholder { - background-color: #1B82B3; - color: #87CDED; + color: #219cd7; } .contact-form textarea::-webkit-input-placeholder { - background-color: #1B82B3; - color: #87CDED; + color: #219cd7; } .contact-sent { diff --git a/pythonkc_site/templates/index.html b/pythonkc_site/templates/index.html index 2cba288..55d3939 100644 --- a/pythonkc_site/templates/index.html +++ b/pythonkc_site/templates/index.html @@ -14,8 +14,7 @@
- - Fork me on GitHub + Fork me on GitHub {% if request.GET.contact_sent == 'yes' %} Thanks for dropping us a note! We look forward to getting in touch @@ -44,6 +43,13 @@

{{ next_event.name|safe }}

+
+
+

Join us on IRC!

+

#pythonkc on freenode

+
+
+

Past Events

@@ -53,7 +59,7 @@

Past Events

{% for event in past_events %} -
+

@@ -136,7 +142,7 @@

FOLLOW US

-
{% csrf_token %} diff --git a/pythonkc_site/urls.py b/pythonkc_site/urls.py index 9b998ce..19fc176 100644 --- a/pythonkc_site/urls.py +++ b/pythonkc_site/urls.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -from django.conf.urls.defaults import include -from django.conf.urls.defaults import patterns -from django.conf.urls.defaults import url +from django.conf.urls import include +from django.conf.urls import patterns +from django.conf.urls import url +from django.views.decorators.cache import cache_page from pythonkc_site.views import PythonKCHome # Uncomment the next two lines to enable the admin: @@ -11,7 +12,7 @@ # admin.autodiscover() urlpatterns = patterns('', - url(r'^/?$', PythonKCHome.as_view(), name='home'), + url(r'^/?$', cache_page(60 * 5)(PythonKCHome.as_view()), name='home'), # Examples: # url(r'^$', 'pythonkc_site.views.home', name='home'),