-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from maxicecilia/big_refactor
Big refactor
- Loading branch information
Showing
23 changed files
with
291 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,6 @@ nosetests.xml | |
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# Sqlite3 | ||
*.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: python | ||
install: | ||
- pip install tox | ||
- pip install coveralls | ||
script: | ||
- tox | ||
env: | ||
- TOXENV=django17 | ||
- TOXENV=django18 | ||
- TOXENV=coverage | ||
after_success: coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# file GENERATED by distutils, do NOT edit | ||
setup.py | ||
contact_us/__init__.py | ||
contact_us/admin.py | ||
contact_us/forms.py | ||
contact_us/models.py | ||
contact_us/views.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# coding: utf-8 | ||
from django.forms import ModelForm | ||
from models import SimpleContact | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
<html> | ||
<head> | ||
<title>{{ title }}</title> | ||
</head> | ||
<body> | ||
<h1>{{ title }}</h1> | ||
{% if form %} | ||
<form action="" method="POST"> | ||
{% csrf_token %} | ||
<ul> | ||
{{ form.as_ul }} | ||
</ul> | ||
<input type="submit" value="Enviar" /> | ||
</form> | ||
{% endif %} | ||
</body> | ||
</html> | ||
{% load i18n %} | ||
|
||
{% if form %} | ||
<form action="" method="POST"> | ||
{% csrf_token %} | ||
<ul> | ||
{{ form.as_ul }} | ||
</ul> | ||
<input type="submit" value="{% trans "Enviar" %}" /> | ||
</form> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
# coding: utf-8 | ||
from django.shortcuts import redirect | ||
from django.contrib.sites.shortcuts import get_current_site | ||
from django.shortcuts import render_to_response | ||
from django.template import RequestContext | ||
from django.utils.translation import ugettext as _ | ||
from django.views.generic.edit import FormView | ||
from forms import ContactForm | ||
|
||
from forms import SimpleContactForm | ||
|
||
class ContactUsFormView(FormView): | ||
form_class = ContactForm | ||
success_url = '/thanks/' | ||
template_name = 'contact_us/contact_form.html' | ||
|
||
def contact_us(request, extra_context=None, template=None, redirect_on_success=None): | ||
title = _(u"Contáctese con nosotros") | ||
if request.method == 'POST': | ||
form = SimpleContactForm(request.POST) | ||
if form.is_valid(): | ||
form.save() | ||
form.instance.notify_users() | ||
form = None | ||
title = _(u"Muchas gracias") | ||
if redirect_on_success: | ||
return redirect(redirect_on_success) | ||
else: | ||
form = SimpleContactForm() | ||
def get(self, request, *args, **kwargs): | ||
form_class = self.get_form_class() | ||
form = self.get_form(form_class) | ||
context = self.get_context_data(**kwargs) | ||
context['form'] = form | ||
return self.render_to_response(context) | ||
|
||
context = { | ||
'title': title, | ||
'form': form, | ||
} | ||
context.update(extra_context or {}) | ||
context_instance = RequestContext(request, current_app="contact_us") | ||
return render_to_response(template or 'contact_us/contact_form.html', context, context_instance=context_instance) | ||
def form_valid(self, form): | ||
obj = form.save(commit=False) | ||
obj.site = get_current_site(self.request) | ||
obj.save() | ||
form.instance.notify_users() | ||
return super(ContactUsFormView, self).form_valid(form) | ||
|
||
def get_success_url(self): | ||
next_url = self.request.GET.get('next', None) | ||
if next_url: | ||
return "{}".format(next_url) | ||
return super(ContactUsFormView, self).get_success_url() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Django contact_us's example project | ||
==================== | ||
|
||
Simple project to display how to use django-contact-us. | ||
|
||
### Installation | ||
Install using pip | ||
``` | ||
$ pip install -r requirements.txt | ||
$ python manage.py migrate # Django 1.7+ and sqllite3 by default | ||
$ python manage.py runserver 0.0.0.0:8000 | ||
``` | ||
Go to http://localhost:8000 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# coding: utf-8 | ||
from django.contrib import admin | ||
from contact_us.admin import ContactUsAdmin | ||
from contact_us.models import SimpleContact | ||
|
||
admin.site.register(SimpleContact, ContactUsAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import os | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = 'd+h*!fsihehbe$fh+t6k$h1f(%3d&4nxup=x+)3cz7u_@y7!t!' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
# Application definition | ||
INSTALLED_APPS = ( | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
|
||
'django.contrib.sites', | ||
'contact_us', | ||
'example_project', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
'django.middleware.security.SecurityMiddleware', | ||
) | ||
|
||
ROOT_URLCONF = 'example_project.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [ | ||
'templates' | ||
], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'example_project.wsgi.application' | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
|
||
# Internationalization | ||
LANGUAGE_CODE = 'en-us' | ||
TIME_ZONE = 'UTC' | ||
USE_I18N = True | ||
USE_L10N = True | ||
USE_TZ = True | ||
|
||
STATIC_URL = '/static/' | ||
|
||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' | ||
|
||
SITE_ID = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# coding: utf-8 | ||
from django.conf.urls import include, url | ||
from django.contrib import admin | ||
from django.views.generic import TemplateView | ||
from contact_us.views import ContactUsFormView | ||
from contact_us.forms import SimpleContactForm | ||
|
||
urlpatterns = [ | ||
url(r'^contact_us/', ContactUsFormView.as_view(), name='contact_us'), | ||
url(r'^contact_us_simplified/', ContactUsFormView.as_view( | ||
form_class=SimpleContactForm), name='contact_us_simplified'), | ||
url(r'^admin/', include(admin.site.urls)), | ||
url(r'^thanks/$', TemplateView.as_view(template_name="thanks.html")), | ||
url(r'^(/)*$', TemplateView.as_view(template_name="index.html")), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for example_project project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_project.settings") | ||
|
||
application = get_wsgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_project.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Django==1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Django contact_us's example project</title> | ||
</head> | ||
<body> | ||
<h2>Welcome!</h2> | ||
<p>You can take a look at the different form options here:</p> | ||
<ul> | ||
<li><a href="/contact_us">Go to default form</a></li> | ||
<li><a href="/contact_us_simplified">Go to simplified form</a></li> | ||
<li><a href="/contact_us?next=/">Go to default form that will return to the home</a></li> | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Thanks</title> | ||
</head> | ||
<body> | ||
<p>Thanks for testing django contact_us!!</p> | ||
<p><a href="/">Back to home</a></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
setup(name='django-contact-us', | ||
version='1.0', | ||
description='Generic contact-us application for Django', | ||
long_description=open(os.path.join(os.path.dirname(__file__), 'README.md')).read(), | ||
long_description='Generic contact-us application for Django', | ||
author='Maximiliano Cecilia', | ||
author_email='[email protected]', | ||
url='https://github.com/maxicecilia/django_contact_us/', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.