Commit 2522c504 authored by Timothée Mazzucotelli's avatar Timothée Mazzucotelli

Merge branch '2-move-code-from-cookiecutter' into 'master'

Resolve "Move code from cookiecutter / hope" (#2)

See merge request !2
parents 79dbee85 80589339
Pipeline #1583 passed with stages
in 6 minutes and 3 seconds
......@@ -4,172 +4,61 @@ stages:
- build
- deploy
py27-django18:
image: python:2.7
stage: test
before_script:
- pip install tox
script: tox -e py27-django18
py34-django18:
image: python:3.4
stage: test
before_script:
- pip install tox
script: tox -e py34-django18
py35-django18:
image: python:3.5
stage: test
before_script:
- pip install tox
script: tox -e py35-django18
py36-django18:
image: python:3.6
stage: test
before_script:
- pip install tox
script: tox -e py36-django18
py37-django18:
image: python:3.7-rc-stretch
stage: test
before_script:
- pip install tox
script: tox -e py37-dev-django18
py27-django19:
image: python:2.7
stage: test
before_script:
- pip install tox
script: tox -e py27-django19
py34-django19:
image: python:3.4
stage: test
before_script:
- pip install tox
script: tox -e py34-django19
py35-django19:
image: python:3.5
stage: test
before_script:
- pip install tox
script: tox -e py35-django19
py36-django19:
image: python:3.6
stage: test
before_script:
- pip install tox
script: tox -e py36-django19
py37-django19:
image: python:3.7-rc-stretch
stage: test
before_script:
- pip install tox
script: tox -e py37-dev-django19
py27-django110:
image: python:2.7
stage: test
before_script:
- pip install tox
script: tox -e py27-django110
py34-django110:
py34-django111:
image: python:3.4
stage: test
before_script:
- pip install tox
script: tox -e py34-django110
script: tox -e py34-django111
py35-django110:
py35-django111:
image: python:3.5
stage: test
before_script:
- pip install tox
script: tox -e py35-django110
script: tox -e py35-django111
py36-django110:
py36-django111:
image: python:3.6
stage: test
before_script:
- pip install tox
script: tox -e py36-django110
script: tox -e py36-django111
py37-django110:
py37-django111:
image: python:3.7-rc-stretch
stage: test
before_script:
- pip install tox
script: tox -e py37-dev-django110
py27-django111:
image: python:2.7
stage: test
before_script:
- pip install tox
script: tox -e py27-django111
script: tox -e py37-dev-django111
py34-django111:
py34-django20:
image: python:3.4
stage: test
before_script:
- pip install tox
script: tox -e py34-django111
script: tox -e py34-django20
py35-django111:
py35-django20:
image: python:3.5
stage: test
before_script:
- pip install tox
script: tox -e py35-django111
script: tox -e py35-django20
py36-django111:
py36-django20:
image: python:3.6
stage: test
before_script:
- pip install tox
script: tox -e py36-django111
script: tox -e py36-django20
py37-django111:
py37-django20:
image: python:3.7-rc-stretch
stage: test
before_script:
- pip install tox
script: tox -e py37-dev-django111
script: tox -e py37-dev-django20
......
django-app-settings==0.2.5
django-cerberus-ac==0.2.1
-r base.txt
pytest
pytest-travis-fold
pytest-cov
pytest-django
django-fake-model
......@@ -25,6 +25,7 @@ try:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sites',
'cerberus_ac',
'hope',
],
SITE_ID=1,
......
......@@ -56,7 +56,6 @@ setup(
# 'Framework :: Django :: 1.10',
# 'Framework :: Django :: 1.11',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
......@@ -68,7 +67,7 @@ setup(
'django-hope',
],
install_requires=[
# eg: 'aspectlib==1.1.1', 'six>=1.7',
'django-cerberus-ac'
],
extras_require={
# eg:
......
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import User
class SignUpForm(UserCreationForm):
email = forms.EmailField(label='Email', max_length=254)
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2', )
from django.db import models
from django.contrib.auth.models import AbstractUser
from cerberus_ac.models import RoleMixin
class User(AbstractUser, RoleMixin):
email_confirmed = models.BooleanField(default=False)
html, body {
height: 100%;
}
.container-fluid {
height: 100%;
}
{
"name": "static",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"bootstrap": "^3.3.7",
"jquery": "^3.2.1"
}
}
{% autoescape off %}
Hi {{ user.username }},
Please click on the link below to confirm your registration:
http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
{% endautoescape %}
{% extends "base.html" %}
{% block content %}
An email has been sent to the specified email address.
Please click on the link inside the email to activate your account.
{% endblock %}
{% load i18n static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
{# <link rel="icon" href="../../favicon.ico">#}
<title>
{% block title %}{{cookiecutter.package_name}}{% endblock %}
</title>
<!-- Bootstrap core CSS -->
<link href="{% static "node_modules/bootstrap/dist/css/bootstrap.min.css" %}" rel="stylesheet">
<!-- Custom CSS -->
<link href="{% static "css/base.css" %}" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<!-- Static navbar -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url "home" %}">HOPE</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="{% block navbar_home %}{% endblock %}"><a href="{% url "home" %}">Home</a></li>
<li class="{% block navbar_about %}{% endblock %}"><a href="{% url "about" %}">About</a></li>
<li class="{% block navbar_contact %}{% endblock %}"><a href="{% url "contact" %}">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
{% block content %}
{% endblock %}
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="{% static "node_modules/jquery/dist/jquery.min.js" %}"></script>
<script src="{% static "node_modules/bootstrap/dist/js/bootstrap.min.js" %}"></script>
</body>
</html>
{% extends 'base.html' %}
{% block title %}Hope{% endblock %}
{% block navbar_home %}active{% endblock %}
{% block content %}
<div class="jumbotron">
<h1>Welcome to Hope</h1>
<p>(Put Hope description here)</p>
{% if not user.is_authenticated %}
<a class="btn btn-default" href="{% url "signin" %}">Sign-in</a>
<a class="btn btn-success" href="{% url "signup" %}">Sign-up</a>
{% else %}
<a class="btn btn-primary" href="{% url "signout" %}">Sign-out</a>
{% endif %}
</div>
{% endblock %}
{% extends 'base.html' %}
{% load bootstrap %}
{% block title %}Sign in{% endblock %}
{% block content %}
<h2>Login</h2>
<form class="form form-vertical" role="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<div class="form-group">
<button type="submit" class="btn btn-primary">Sign-in</button>
</div>
</form>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Signed out{% endblock %}
{% block content %}
<h2>Yo have been signed out.</h2>
{% endblock %}
{% extends 'base.html' %}
{% load bootstrap %}
{% block title %}Sign up{% endblock %}
{% block content %}
<h2>Sign up</h2>
<form class="form form-vertical" role="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<div class="form-group">
<button type="submit" class="btn btn-primary">Sign-up</button>
</div>
</form>
{% endblock %}
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils import six
class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (
six.text_type(user.pk) + six.text_type(timestamp) +
six.text_type(user.email_confirmed)
)
account_activation_token = AccountActivationTokenGenerator()
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
url(r'^signup/$', views.signup, name='signup'),
url(r'^signin/$', auth_views.login,
{'template_name': 'hope/signin.html'}, name='signin'),
url(r'^signout/$', auth_views.logout,
{'template_name': 'hope/signout.html'}, name='signout'),
url(r'^account_activation_sent/$',
views.account_activation_sent, name='account_activation_sent'),
url(r'^activate/'
r'(?P<uidb64>[0-9A-Za-z_\-]+)/'
r'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
views.activate, name='activate')
]
from django.contrib.auth import login
from django.contrib.sites.shortcuts import get_current_site
from django.shortcuts import render, redirect
from django.template.loader import render_to_string
from django.utils.encoding import force_bytes, force_text
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from .forms import SignUpForm
from .models import User
from .tokens import account_activation_token
def signup(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
user = form.save(commit=False)
user.is_active = False
user.save()
current_site = get_current_site(request)
subject = 'Activate Your MySite Account'
message = render_to_string('account_activation_email.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
})
user.email_user(subject, message)
return redirect('account_activation_sent')
else:
form = SignUpForm()
return render(request, '{{cookiecutter.package_name}}/signup.html', {'form': form})
def activate(request, uidb64, token):
try:
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
except (TypeError, ValueError, OverflowError, User.DoesNotExist):
user = None
if user is not None and account_activation_token.check_token(user, token):
user.is_active = True
user.email_confirmed = True
user.save()
login(request, user)
# TODO: add a message with django message app
return redirect('home')
else:
return render(request, 'account_activation_invalid.html')
def account_activation_sent(request):
return render(request, 'account_activation_sent.html')
[tox]
envlist =
clean,setup,safety,style,docs,
py27-django18,
py27-django19,
py27-django110,
py27-django111,
py34-django18,
py34-django19,
py34-django110,
py34-django111,
py35-django18,
py35-django19,
py35-django110,
py34-django20,
py35-django111,
py36-django18,
py36-django19,
py36-django110,
py35-django20,
py36-django111,
py37-dev-django18,
py37-dev-django19,
py37-dev-django110,
py36-django20,
py37-dev-django111,
pypy-django18,
pypy-django19,
pypy-django110,
py37-dev-django20,
pypy-django111,
pypy-django20,
report
skip_missing_interpreters = true
......@@ -34,10 +20,8 @@ setenv =
PYTHONUNBUFFERED=yes
commands = {posargs:pytest --cov --cov-report=term-missing -vv runtests.py tests}
deps =
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
django111: Django>=1.11,<1.12
django20: Django>=2.0,<2.1
-r{toxinidir}/requirements/test.txt
passenv = *
usedevelop = false
......@@ -46,7 +30,7 @@ whitelist_externals = tox
[testenv:test]
description = Run all the Python/Django test environments.
skip_install = true
commands = tox -e py27-django18,py27-django19,py27-django110,py27-django111,py34-django18,py34-django19,py34-django110,py34-django111,py35-django18,py35-django19,py35-django110,py35-django111,py36-django18,py36-django19,py36-django110,py36-django111,py37-dev-django18,py37-dev-django19,py37-dev-django110,py37-dev-django111,pypy-django18,pypy-django19,pypy-django110,pypy-django111,
commands = tox -e py34-django111,py34-django20,py35-django111,py35-django20,py36-django111,py36-django20,py37-dev-django111,py37-dev-django20,pypy-django18,pypy-django19,pypy-django111,pypy-django20,
tox -e report
[testenv:dtest]
......@@ -54,7 +38,7 @@ description = Run all the Python/Django test environments in parallel.
skip_install = true
deps = detox
commands =
detox -e py27-django18,py27-django19,py27-django110,py27-django111,py34-django18,py34-django19,py34-django110,py34-django111,py35-django18,py35-django19,py35-django110,py35-django111,py36-django18,py36-django19,py36-django110,py36-django111,py37-dev-django18,py37-dev-django19,py37-dev-django110,py37-dev-django111,pypy-django18,pypy-django19,pypy-django110,pypy-django111,
detox -e py34-django111,py34-django20,py35-django111,py35-django20,py36-django111,py36-django20,py37-dev-django111,py37-dev-django20,pypy-django18,pypy-django19,pypy-django111,pypy-django20,
tox -e report
[testenv:detox]
......@@ -62,7 +46,7 @@ description = Run all the environments in parallel.
skip_install = true
deps = detox
commands =
detox -e clean,setup,safety,style,docs,py27-django18,py27-django19,py27-django110,py27-django111,py34-django18,py34-django19,py34-django110,py34-django111,py35-django18,py35-django19,py35-django110,py35-django111,py36-django18,py36-django19,py36-django110,py36-django111,py37-dev-django18,py37-dev-django19,py37-dev-django110,py37-dev-django111,pypy-django18,pypy-django19,pypy-django110,pypy-django111,
detox -e clean,setup,safety,style,docs,py34-django111,py34-django20,py35-django111,py35-django20,py36-django111,py36-django20,py37-dev-django111,py37-dev-django20,pypy-django18,pypy-django19,pypy-django111,pypy-django20,
tox -e report
[testenv:check]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment