python3 compat and deps++

This commit is contained in:
nikolark committed 2016-02-08 23:07:01 +01:00
1 parent 88eeabe746
commit 5efea835d0
9 files changed
+58 -64

No files matched your search

+1 -1
View File
@@ -17,4 +17,4 @@ class DomainAdmin(admin.ModelAdmin):
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
pass
pass
@@ -57,4 +57,4 @@ class Command(BaseCommand):
self.stdout.write('Imported {}, skipped {} existing, total {}'.format(
counts['imported'],
counts['existing'],
len(new_aliases)))
len(new_aliases)))
+7 -3
View File
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
class BaseModel(models.Model):
@@ -10,13 +11,14 @@ class BaseModel(models.Model):
abstract = True
@python_2_unicode_compatible
class Alias(BaseModel):
source = models.EmailField(max_length=254)
destination = models.EmailField(max_length=254)
domain = models.ForeignKey('dpdapi.Domain')
active = models.BooleanField(default=True)
def __unicode__(self):
def __str__(self):
return "{}={}".format(self.source, self.destination)
def save(self, *args, **kwargs):
@@ -30,10 +32,11 @@ class Alias(BaseModel):
unique_together = ('source', 'destination', 'domain')
@python_2_unicode_compatible
class Domain(BaseModel):
name = models.CharField(max_length=254, unique=True)
def __unicode__(self):
def __str__(self):
return self.name
def save(self, *args, **kwargs):
@@ -42,12 +45,13 @@ class Domain(BaseModel):
super(Domain, self).save(*args, **kwargs)
@python_2_unicode_compatible
class User(BaseModel):
email = models.EmailField(max_length=254, unique=True)
password = models.CharField(max_length=109)
domain = models.ForeignKey('dpdapi.Domain')
def __unicode__(self):
def __str__(self):
return self.email
def save(self, *args, **kwargs):
+1 -1
View File
@@ -7,4 +7,4 @@ router = DefaultRouter()
router.register(r'aliases', AliasViewSet)
router.register(r'domains', DomainViewSet)
router.register(r'users', UserViewSet)
urlpatterns = router.urls
urlpatterns = router.urls
+3
View File
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import logging
import operator
from django.utils import six
from django.db.models import Q
from rest_framework.decorators import list_route
from rest_framework.permissions import IsAuthenticated
@@ -11,6 +12,8 @@ from dpdapi.filters import AliasRegexFilterBackend
from dpdapi.models import Alias, Domain, User
from dpdapi.serializers import AliasSerializer, AliasDeleteSerializer, DomainSerializer, UserSerializer
if six.PY3:
from functools import reduce
logger = logging.getLogger(__name__)
+24 -3
View File
@@ -20,7 +20,28 @@ SECRET_KEY = 'hlaf#yma(8s!cy-bf5e6kc&_5n_l1h!34c(j32-b3v8o7pg$5n'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
ALLOWED_HOSTS = []
@@ -93,6 +114,6 @@ REST_FRAMEWORK = {
}
try:
from local_settings import *
from .local_settings import *
except ImportError:
pass
pass
+10 -7
View File
@@ -1,11 +1,14 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic import RedirectView
from rest_framework import urls as rest_framework_urls
urlpatterns = patterns(
'',
from dpdapi import urls as dpdapi_urls
urlpatterns = [
url(r'^$', RedirectView.as_view(pattern_name='api-root')),
url(r'^api/', include('dpdapi.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
)
url(r'^api/', include(dpdapi_urls)),
url(r'^admin/', admin.site.urls),
url(r'^api-auth/', include(rest_framework_urls, namespace='rest_framework'))
]
Vendored
+4 -41
View File
@@ -1,9 +1,5 @@
import logging
import sys
from contextlib import contextmanager as _contextmanager
from fabric.api import run, sudo, env, cd, prefix, lcd
from fabric.api import local as lrun
from fabric.api import run, sudo, env, cd, prefix
env.use_ssh_config = True
env.hosts = ['lynx.neuf.no']
@@ -14,50 +10,17 @@ env.activate = 'source {}/venv/bin/activate'.format(env.project_path)
@_contextmanager
def virtualenv():
with cd(env.project_path):
with prefix(env.activate):
yield
def __git_validate_clean():
with lcd(env.project_path):
if lrun('git diff-files', capture=True) != '':
logging.error("Your git-tree isn't clean! Commit your changes before deploying.")
sys.exit(1)
def test():
lrun("python manage.py test dpdapi")
def commit():
lrun("git add -p && git commit")
def push():
lrun("git push")
def prepare_deploy():
test()
commit()
push()
def gitstatus():
# __git_validate_clean()
with virtualenv():
# Get source
run('git branch -v')
with cd(env.project_path), prefix(env.activate):
yield
def deploy():
# __git_validate_clean()
with virtualenv():
run('git pull') # Get source
run('pip install -r requirements.txt') # install deps in virtualenv
run('umask 022; python manage.py collectstatic --noinput') # Collect static
run('python manage.py migrate') # Run DB migrations
# TODO: Supervisor
# Reload gunicorn
sudo('/etc/init.d/gunicorn reload', shell=False)
+7 -7
View File
@@ -1,7 +1,7 @@
Django>=1.7,<1.8
django-extensions==1.4.9
django-filter==0.9.1
djangorestframework>=3.0,<3.1
passlib==1.6.2
mysqlclient==1.3.4
Fabric==1.10.1
Django>=1.9,<1.10
djangorestframework>=3.3,<3.4
django-extensions==1.6.1
django-filter==0.12.0
passlib==1.6.5
mysqlclient==1.3.7
Fabric==1.10.2