Django -> Flask.
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
ianonavy/passwords.txt
|
||||
conf/passwords.txt
|
||||
database.db
|
||||
|
@ -1,64 +0,0 @@
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.mail import send_mail
|
||||
from django.template import loader
|
||||
from django.template import RequestContext
|
||||
from django.contrib.sites.models import Site
|
||||
|
||||
|
||||
attrs_dict = { 'class': 'required' }
|
||||
|
||||
|
||||
class ContactForm(forms.Form):
|
||||
|
||||
def __init__(self, data=None, files=None, request=None, *args, **kwargs):
|
||||
if request is None:
|
||||
raise TypeError("Keyword argument 'request' must be supplied")
|
||||
super(ContactForm, self).__init__(data=data, files=files, *args, **kwargs)
|
||||
self.request = request
|
||||
|
||||
name = forms.CharField(max_length=100,
|
||||
widget=forms.TextInput(attrs=attrs_dict),
|
||||
label=u'Name',
|
||||
error_messages={'required': 'Name is required.'})
|
||||
email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict,
|
||||
maxlength=200)),
|
||||
label=u'Email Address',
|
||||
error_messages={'required': 'Email is required.'})
|
||||
body = forms.CharField(widget=forms.Textarea(attrs=attrs_dict),
|
||||
label=u'Message',
|
||||
error_messages={'required': 'Message is blank.'})
|
||||
|
||||
from_email = settings.DEFAULT_FROM_EMAIL
|
||||
recipient_list = [mail_tuple[1] for mail_tuple in settings.MANAGERS]
|
||||
subject_template_name = "contact_form_subject.txt"
|
||||
template_name = 'contact_form.txt'
|
||||
|
||||
def message(self):
|
||||
if callable(self.template_name):
|
||||
template_name = self.template_name()
|
||||
else:
|
||||
template_name = self.template_name
|
||||
return loader.render_to_string(template_name, self.get_context())
|
||||
|
||||
def subject(self):
|
||||
subject = loader.render_to_string(self.subject_template_name,
|
||||
self.get_context())
|
||||
return ''.join(subject.splitlines())
|
||||
|
||||
def get_context(self):
|
||||
if not self.is_valid():
|
||||
raise ValueError("Cannot generate Context from invalid contact form")
|
||||
return RequestContext(self.request, dict(self.cleaned_data))
|
||||
|
||||
def get_message_dict(self):
|
||||
if not self.is_valid():
|
||||
raise ValueError("Message cannot be sent from invalid contact form")
|
||||
message_dict = {}
|
||||
for message_part in ('from_email', 'message', 'recipient_list', 'subject'):
|
||||
attr = getattr(self, message_part)
|
||||
message_dict[message_part] = callable(attr) and attr() or attr
|
||||
return message_dict
|
||||
|
||||
def save(self, fail_silently=False):
|
||||
send_mail(fail_silently=fail_silently, **self.get_message_dict())
|
@ -1,3 +0,0 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
@ -1,36 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %} | Contact{% endblock %}
|
||||
{% block nav-contact %} class="selected" {% endblock %}
|
||||
{% block extrastyle %}<link rel="stylesheet" href="{{ STATIC_URL }}css/contact.css" type="text/css" media="screen" />{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<section id="contact">
|
||||
{% if success %}
|
||||
<span class="">Thank you for contacting me! Your message was sent successfully.</span>
|
||||
{% else %}
|
||||
<form id="contact_form" action="/newdesign/contact/" method="post">{% csrf_token %}
|
||||
{{ contact_form.name.errors }}
|
||||
{{ contact_form.name.label_tag }}
|
||||
{{ contact_form.name }}
|
||||
{{ contact_form.email.errors }}
|
||||
{{ contact_form.email.label_tag }}
|
||||
{{ contact_form.email }}
|
||||
{{ contact_form.body.errors }}
|
||||
{{ contact_form.body.label_tag }}
|
||||
{{ contact_form.body }}
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
{% endif %}
|
||||
<p>Hablo español.</p>
|
||||
</section>
|
||||
<section id="internet">
|
||||
<h3>Find me on the Internet</h3>
|
||||
<p id="social_links">
|
||||
<a href="http://www.github.com/ianonavy"><img src="{{ STATIC_URL }}img/icons/32/github.png" alt="GitHub" /></a>
|
||||
<a href="http://forr.st/-ianonavy"><img src="{{ STATIC_URL }}img/icons/32/forrst.png" alt="Forrst" /></a>
|
||||
<a href="skype:ianonavy?userinfo"><img src="{{ STATIC_URL }}img/icons/32/skype.png" alt="Skype" /></a>
|
||||
<a href="http://stackoverflow.com/users/765439/ianonavy"><img src="{{ STATIC_URL }}img/icons/32/stackoverflow.png" alt="Stackoverflow" /></a>
|
||||
</p>
|
||||
</section>
|
||||
{% endblock main %}
|
@ -1,16 +0,0 @@
|
||||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
@ -1,151 +0,0 @@
|
||||
# Django settings for ianonavy project.
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
try:
|
||||
RUNNING_DEVSERVER = (sys.argv[1] == 'runserver')
|
||||
except:
|
||||
RUNNING_DEVSERVER = False
|
||||
|
||||
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
|
||||
password_file = open(os.path.join(SITE_ROOT, 'passwords.txt'))
|
||||
|
||||
|
||||
def next_password():
|
||||
return password_file.readline().strip()
|
||||
|
||||
DEBUG = RUNNING_DEVSERVER
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (
|
||||
('Ian Adam Naval', 'ian@ianonavy.com'),
|
||||
)
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': 'database.db',
|
||||
}
|
||||
}
|
||||
|
||||
TIME_ZONE = 'America/Los_Angeles'
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
USE_I18N = True
|
||||
USE_L10N = True
|
||||
USE_TZ = True
|
||||
|
||||
# Absolute filesystem path to the directory that will hold user-uploaded files.
|
||||
# Example: "/home/media/media.lawrence.com/media/"
|
||||
MEDIA_ROOT = ''
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash.
|
||||
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
|
||||
MEDIA_URL = ''
|
||||
|
||||
# Absolute path to the directory static files should be collected to.
|
||||
# Don't put anything in this directory yourself; store your static files
|
||||
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
||||
# Example: "/home/media/media.lawrence.com/static/"
|
||||
STATIC_ROOT = '/home/ubuntu/ianonavy/static/'
|
||||
|
||||
# URL prefix for static files.
|
||||
# Example: "http://media.lawrence.com/static/"
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# Additional locations of static files
|
||||
STATICFILES_DIRS = (
|
||||
)
|
||||
|
||||
# List of finder classes that know how to find static files in
|
||||
# various locations.
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||
)
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
SECRET_KEY = 'x^arqv*tp^q8g2=y^(x$2q6a@^6f#$j62$#)50a1=d+(dfg@+5'
|
||||
|
||||
# List of callables that know how to import templates from various sources.
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
# 'django.template.loaders.eggs.Loader',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
# Uncomment the next line for simple clickjacking protection:
|
||||
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'ianonavy.urls'
|
||||
|
||||
# Python dotted path to the WSGI application used by Django's runserver.
|
||||
WSGI_APPLICATION = 'ianonavy.wsgi.application'
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
||||
# Always use forward slashes, even on Windows.
|
||||
# Don't forget to use absolute paths, not relative paths.
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.admin',
|
||||
'ianonavy.core',
|
||||
)
|
||||
|
||||
# A sample logging configuration. The only tangible logging
|
||||
# performed by this configuration is to send an email to
|
||||
# the site admins on every HTTP 500 error when DEBUG=False.
|
||||
# See http://docs.djangoproject.com/en/dev/topics/logging for
|
||||
# more details on how to customize your logging configuration.
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'filters': {
|
||||
'require_debug_false': {
|
||||
'()': 'django.utils.log.RequireDebugFalse'
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
'filters': ['require_debug_false'],
|
||||
'class': 'django.utils.log.AdminEmailHandler'
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'django.request': {
|
||||
'handlers': ['mail_admins'],
|
||||
'level': 'ERROR',
|
||||
'propagate': True,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
PREPEND_WWW = False
|
||||
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST = 'smtp.gmail.com'
|
||||
EMAIL_HOST_USER = 'ian@ianonavy.com'
|
||||
EMAIL_HOST_PASSWORD = next_password()
|
||||
EMAIL_PORT = 587
|
@ -1,9 +0,0 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.contrib import admin
|
||||
|
||||
#admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'', include('ianonavy.core.urls')),
|
||||
#url(r'^admin/', include(admin.site.urls)),
|
||||
)
|
@ -1,44 +0,0 @@
|
||||
"""
|
||||
WSGI config for ianonavy project.
|
||||
|
||||
This module contains the WSGI application used by Django's development server
|
||||
and any production WSGI deployments. It should expose a module-level variable
|
||||
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
|
||||
this application via the ``WSGI_APPLICATION`` setting.
|
||||
|
||||
Usually you will have the standard Django WSGI application here, but it also
|
||||
might make sense to replace the whole Django WSGI application with a custom one
|
||||
that later delegates to the Django one. For example, you could introduce WSGI
|
||||
middleware here, or combine a Django application with an application of another
|
||||
framework.
|
||||
|
||||
"""
|
||||
import os
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ianonavy.settings")
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
|
||||
if settings.DEBUG:
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
application = get_wsgi_application()
|
||||
|
||||
else:
|
||||
|
||||
import django.core.handlers.wsgi
|
||||
_application = django.core.handlers.wsgi.WSGIHandler()
|
||||
|
||||
def application(environ, start_response):
|
||||
if environ['HTTP_HOST'] != 'ianonavy.com':
|
||||
start_response('301 Redirect', [('Location', 'http://ianonavy.com%s' % environ['REQUEST_URI']),])
|
||||
return []
|
||||
return _application(environ, start_response)
|
||||
|
||||
# Apply WSGI middleware here.
|
||||
# from helloworld.wsgi import HelloWorldApplication
|
||||
# application = HelloWorldApplication(application)
|
10
manage.py
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ianonavy.settings")
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
execute_from_command_line(sys.argv)
|
30
src/server.py
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from flask import Flask, render_template
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def home():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@app.route('/contact')
|
||||
def contact():
|
||||
return render_template('contact.html')
|
||||
|
||||
|
||||
|
||||
@app.route('/about')
|
||||
def about():
|
||||
return render_template('about.html')
|
||||
|
||||
|
||||
@app.route('/labs')
|
||||
def labs():
|
||||
return render_template('labs.html')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 505 B After Width: | Height: | Size: 505 B |
Before Width: | Height: | Size: 762 B After Width: | Height: | Size: 762 B |
Before Width: | Height: | Size: 766 B After Width: | Height: | Size: 766 B |
Before Width: | Height: | Size: 843 B After Width: | Height: | Size: 843 B |
Before Width: | Height: | Size: 736 B After Width: | Height: | Size: 736 B |
Before Width: | Height: | Size: 624 B After Width: | Height: | Size: 624 B |
Before Width: | Height: | Size: 656 B After Width: | Height: | Size: 656 B |
Before Width: | Height: | Size: 653 B After Width: | Height: | Size: 653 B |
Before Width: | Height: | Size: 832 B After Width: | Height: | Size: 832 B |
Before Width: | Height: | Size: 631 B After Width: | Height: | Size: 631 B |
Before Width: | Height: | Size: 415 B After Width: | Height: | Size: 415 B |
Before Width: | Height: | Size: 418 B After Width: | Height: | Size: 418 B |
Before Width: | Height: | Size: 382 B After Width: | Height: | Size: 382 B |
Before Width: | Height: | Size: 404 B After Width: | Height: | Size: 404 B |
Before Width: | Height: | Size: 422 B After Width: | Height: | Size: 422 B |
Before Width: | Height: | Size: 381 B After Width: | Height: | Size: 381 B |
Before Width: | Height: | Size: 388 B After Width: | Height: | Size: 388 B |
Before Width: | Height: | Size: 768 B After Width: | Height: | Size: 768 B |
Before Width: | Height: | Size: 561 B After Width: | Height: | Size: 561 B |
Before Width: | Height: | Size: 602 B After Width: | Height: | Size: 602 B |
Before Width: | Height: | Size: 780 B After Width: | Height: | Size: 780 B |
Before Width: | Height: | Size: 769 B After Width: | Height: | Size: 769 B |
Before Width: | Height: | Size: 592 B After Width: | Height: | Size: 592 B |
Before Width: | Height: | Size: 889 B After Width: | Height: | Size: 889 B |
Before Width: | Height: | Size: 768 B After Width: | Height: | Size: 768 B |
Before Width: | Height: | Size: 737 B After Width: | Height: | Size: 737 B |
Before Width: | Height: | Size: 767 B After Width: | Height: | Size: 767 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 554 B After Width: | Height: | Size: 554 B |
Before Width: | Height: | Size: 755 B After Width: | Height: | Size: 755 B |
Before Width: | Height: | Size: 600 B After Width: | Height: | Size: 600 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 632 B After Width: | Height: | Size: 632 B |
Before Width: | Height: | Size: 836 B After Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 626 B After Width: | Height: | Size: 626 B |
Before Width: | Height: | Size: 747 B After Width: | Height: | Size: 747 B |
Before Width: | Height: | Size: 624 B After Width: | Height: | Size: 624 B |
Before Width: | Height: | Size: 688 B After Width: | Height: | Size: 688 B |
Before Width: | Height: | Size: 833 B After Width: | Height: | Size: 833 B |
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 520 B |
Before Width: | Height: | Size: 546 B After Width: | Height: | Size: 546 B |
Before Width: | Height: | Size: 780 B After Width: | Height: | Size: 780 B |
Before Width: | Height: | Size: 917 B After Width: | Height: | Size: 917 B |
Before Width: | Height: | Size: 810 B After Width: | Height: | Size: 810 B |
Before Width: | Height: | Size: 657 B After Width: | Height: | Size: 657 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 654 B After Width: | Height: | Size: 654 B |
Before Width: | Height: | Size: 694 B After Width: | Height: | Size: 694 B |
Before Width: | Height: | Size: 706 B After Width: | Height: | Size: 706 B |
Before Width: | Height: | Size: 869 B After Width: | Height: | Size: 869 B |
Before Width: | Height: | Size: 702 B After Width: | Height: | Size: 702 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 866 B After Width: | Height: | Size: 866 B |
Before Width: | Height: | Size: 741 B After Width: | Height: | Size: 741 B |
Before Width: | Height: | Size: 631 B After Width: | Height: | Size: 631 B |
Before Width: | Height: | Size: 538 B After Width: | Height: | Size: 538 B |
Before Width: | Height: | Size: 698 B After Width: | Height: | Size: 698 B |
Before Width: | Height: | Size: 833 B After Width: | Height: | Size: 833 B |
Before Width: | Height: | Size: 897 B After Width: | Height: | Size: 897 B |
Before Width: | Height: | Size: 802 B After Width: | Height: | Size: 802 B |
Before Width: | Height: | Size: 606 B After Width: | Height: | Size: 606 B |
Before Width: | Height: | Size: 809 B After Width: | Height: | Size: 809 B |
Before Width: | Height: | Size: 728 B After Width: | Height: | Size: 728 B |
Before Width: | Height: | Size: 569 B After Width: | Height: | Size: 569 B |
Before Width: | Height: | Size: 779 B After Width: | Height: | Size: 779 B |
Before Width: | Height: | Size: 655 B After Width: | Height: | Size: 655 B |
Before Width: | Height: | Size: 688 B After Width: | Height: | Size: 688 B |