Revert django-angular dependency commits.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-15 14:51:56 -04:00
parent ee3b6d8988
commit 18aa7020be
9 changed files with 3 additions and 176 deletions

7
.gitignore vendored
View File

@ -1,8 +1,5 @@
# database
*.sqlite3
# python
*.pyc
# static files
babyblotter/static
# database
*.sqlite3

View File

@ -6,5 +6,3 @@ url = "https://pypi.python.org/simple"
django = "*"
djangorestframework = "*"
django-filter = "*"
django-angular = "*"
whitenoise = "*"

8
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "58ee3f51b748a5b05db80eda5a1885ac84e5645f540c5d67a00555a2b1156cc1"
"sha256": "a0ef885217179eed1565af7ec6a732e8b141fb42c156f152380a65feac7cb1fe"
},
"requires": {},
"sources": [
@ -15,9 +15,6 @@
"django": {
"version": "==1.11.4"
},
"django-angular": {
"version": "==1.1"
},
"django-filter": {
"version": "==1.0.4"
},
@ -26,9 +23,6 @@
},
"pytz": {
"version": "==2017.2"
},
"whitenoise": {
"version": "==3.3.0"
}
},
"develop": {}

View File

@ -22,7 +22,6 @@ INSTALLED_APPS = [
'api',
'core',
'djng',
'rest_framework',
'django.contrib.admin',
@ -35,9 +34,6 @@ INSTALLED_APPS = [
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
@ -95,22 +91,8 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'babyblotter/static')
# Form rendering
# https://docs.djangoproject.com/en/1.11/ref/settings/#form-renderer
FORM_RENDERER = 'djng.forms.renderers.DjangoAngularBootstrap3Templates'
# Django Rest Framework
# http://www.django-rest-framework.org/#

View File

@ -4,11 +4,7 @@ from __future__ import unicode_literals
from django.conf.urls import url, include
from django.contrib import admin
from core import views
urlpatterns = [
url(r'^baby/add/$', views.BabyFormView.as_view(), name='baby_add'),
url(r'^admin/', admin.site.urls),
url(r'', include('api.urls')),
]

View File

@ -1,36 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.core.exceptions import ValidationError
from django.forms import widgets
from djng.forms import fields, NgModelFormMixin, NgFormValidationMixin
from djng.styling.bootstrap3.forms import Bootstrap3Form
class BabyForm(NgModelFormMixin, NgFormValidationMixin, Bootstrap3Form):
use_required_attribute = False
scope_prefix = 'subscribe_data'
form_name = 'baby_new'
first_name = fields.CharField(
label='First name',
min_length=3,
max_length=20)
last_name = fields.RegexField(
r'^[A-Z][a-z -]?',
label='Last name',
error_messages={'invalid': 'Last names shall start in upper case'})
birth_date = fields.DateField(
label='Date of birth',
widget=widgets.DateInput(attrs={'validate-date': '^(\d{4})-(\d{1,2})-(\d{1,2})$'}),
help_text='Allowed date format: yyyy-mm-dd')
def clean(self):
if self.cleaned_data.get(
'first_name') == 'John' and self.cleaned_data.get(
'last_name') == 'Doe':
raise ValidationError(
'The full name "John Doe" is rejected by the server.')
return super(BabyForm, self).clean()

View File

@ -1,37 +0,0 @@
{% extends "base.html" %}
{% block title %}Add Baby Form{% endblock %}
{% block head %}
<script type="text/javascript">
angular.module('baby-add', ['djng.forms']).config(function($httpProvider) {
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
$httpProvider.defaults.headers.common['X-CSRFToken'] = '{{ csrf_token }}';
});
angular.module('baby-add').controller('BabyNewForm', ['$scope', '$http', '$window', 'djangoForm',
function($scope, $http, $window, djangoForm) {
$scope.submit = function() {
if ($scope.subscribe_data) {
$http.post(".", $scope.subscribe_data).then(function(response) {
if (!djangoForm.setErrors($scope.my_form, response.data.errors)) {
// on successful post, redirect onto success page
$window.location.href = response.data.success_url;
}
}, function() {
console.error('An error occurred during submission');
});
}
return false;
};
}]);
</script>
{% endblock %}
{% block content %}
<form name="{{ form.form_name }}" method="post" action="." novalidate ng-controller="BabyNewForm">
{% csrf_token %}
{{ form.as_div }}
<button type="submit" ng-disabled="{{ form.form_name }}.$invalid" class="btn btn-primary">Submit via Post</button>
<button type="button" ng-disabled="{{ form.form_name }}.$invalid" ng-click="submit()" class="btn btn-primary">Submit via Ajax</button>
</form>
{% endblock %}

View File

@ -1,40 +0,0 @@
{% load static djng_tags %}
<!doctype html>
<html lang="en">
<head>
<title>{% block form_title %}Baby Blotter{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css" />
<link href="{% static 'djng/css/styles.css' %}" rel="stylesheet" />
<link href="{% static 'djng/css/bootstrap3.css' %}" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.11/angular.js"></script>
</head>
<body>
<header class="navbar navbar-static-top navbar-inverse">
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1 class="navbar-brand">Baby Blotter<small style="margin-left: 3em;">Tracking literal shit.</small></h1>
</div>
</div>
</div>
</header>
<div class="container">
<div class="row">
<nav class="col-md-3" style="margin-top: 65px;" role="navigation">
<ul class="nav nav-pills nav-stacked">
<li>
<a href="{% url 'baby_add' %}">Add Baby</a>
</li>
</ul>
</nav>
<main class="col-md-9">
{% block content %}{% endblock %}
</main>
</div>
</div>
</body>
</html>

View File

@ -1,27 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
from django.http import HttpResponse
from django.core.urlresolvers import reverse_lazy
from django.views.generic.edit import FormView
from django.utils.encoding import force_text
from core.forms import BabyForm
class BabyFormView(FormView):
template_name = 'baby-form.html'
form_class = BabyForm
success_url = reverse_lazy('form_data_valid')
def post(self, request, **kwargs):
if request.is_ajax():
return self.ajax(request)
return super(BabyFormView, self).post(request, **kwargs)
def ajax(self, request):
form = self.form_class(data=json.loads(request.body))
response_data = {'errors': form.errors, 'success_url': force_text(self.success_url)}
return HttpResponse(json.dumps(response_data), content_type="application/json")