Skip to content

Commit 7416e94

Browse files
committed
Added first uploader image version with it works with flask..
Fixed errors in tasks.py for incorrect dependencies Delete unused .js files Commented extension file checker. Pending to fix problem
1 parent 1b4bb0b commit 7416e94

File tree

8 files changed

+70
-179
lines changed

8 files changed

+70
-179
lines changed

app/mod_photos/controllers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ def post_photos():
2626

2727
data = None
2828
if request.method == 'POST':
29+
app.logger.debug("Applying post image")
2930
file = request.files['file']
30-
if file and not allowed_file(file.filename):
31-
return responses.new202()
31+
32+
#TODO pending for testing!
33+
#if file and not allowed_file(file.filename):
34+
# return responses.new202()
35+
3236

3337
extension = os.path.splitext(file.filename)[1]
3438
f_name=str(uuid.uuid4()) + extension
39+
app.logger.debug("f_name="+f_name)
3540
filepath=os.path.join(app.config['UPLOAD_FOLDER'], f_name)
3641
photo = Photo(f_name,filepath)
3742
data ={'uuid':f_name, 'filepath': filepath}

app/static/js/app.js

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,61 @@
11
'use strict';
22

3+
var app = angular.module('app',[]);
34

5+
app.config(['$interpolateProvider',
6+
function($interpolateProvider) {
7+
$interpolateProvider.startSymbol('[[');
8+
$interpolateProvider.endSymbol(']]');
9+
}]);
410

5-
/*
6-
n app module
7-
* @name app
8-
* * @type {angular.Module}
9-
* */
10-
var app = angular.module('app', ['flow'])
11-
.config(['flowFactoryProvider', function (flowFactoryProvider) {
12-
flowFactoryProvider.defaults = {
13-
target: 'test.php',
14-
permanentErrors: [404, 500, 501],
15-
maxChunkRetries: 1,
16-
chunkRetryInterval: 5000,
17-
simultaneousUploads: 4,
18-
singleFile: true
19-
};
20-
flowFactoryProvider.on('catchAll', function (event) {
21-
console.log('catchAll', arguments);
22-
});
23-
// Can be used with different implementations of Flow.js
24-
// // flowFactoryProvider.factory = fustyFlowFactory;
25-
}]);
26-
/*
27-
angular.module('AngularFlask', ['angularFlaskServices'])
28-
.config(['$routeProvider', '$locationProvider',
29-
function($routeProvider, $locationProvider) {
30-
$routeProvider
31-
.when('/', {
32-
templateUrl: 'static/partials/landing.html',
33-
controller: IndexController
34-
})
35-
.when('/about', {
36-
templateUrl: 'static/partials/about.html',
37-
controller: AboutController
38-
})
39-
.when('/post', {
40-
templateUrl: 'static/partials/post-list.html',
41-
controller: PostListController
42-
})
43-
.when('/post/:postId', {
44-
templateUrl: '/static/partials/post-detail.html',
45-
controller: PostDetailController
46-
})
47-
.when('/blog', {
48-
templateUrl: 'static/partials/post-list.html',
49-
controller: PostListController
50-
})
51-
.otherwise({
52-
redirectTo: '/'
53-
})
54-
;
55-
56-
$locationProvider.html5Mode(true);
57-
}])
58-
;
59-
*/
11+
12+
app.directive('fileModel',['$parse', function($parse) {
13+
return {
14+
restrict: 'A',
15+
link: function(scope, element, attrs) {
16+
var model = $parse(attrs.fileModel)
17+
var modelSetter = model.assign;
18+
element.bind('change', function() {
19+
scope.$apply(function () {
20+
modelSetter(scope,element[0].files[0]);
21+
});
22+
23+
});
24+
25+
}
26+
27+
};
28+
29+
}]);
30+
31+
32+
app.service('fileUpload',['$http',
33+
function($http) {
34+
this.uploadFileToUrl = function(file) {
35+
var fd = new FormData();
36+
fd.append('file',file);
37+
$http.post('/photos/v1.0/photos',fd, {
38+
transformRequest: angular.identity,
39+
headers: {'Content-Type': undefined }
40+
})
41+
.success(function() {
42+
})
43+
.error(function() {
44+
});
45+
46+
}
47+
}]);
48+
49+
50+
51+
app.controller('myController', ['$scope', 'fileUpload',
52+
function($scope,fileUpload) {
53+
$scope.uploadFile = function () {
54+
var file = $scope.myFile;
55+
console.log('File is ');
56+
console.dir(file);
57+
var uploadUrl = "/fileUpload";
58+
fileUpload.uploadFileToUrl(file);
59+
};
60+
61+
}]);

app/static/js/controllers.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

app/static/js/directives.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

app/static/js/filters.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/static/js/services.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/templates/index.html

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,80 +8,19 @@
88

99
<script src="/static/lib/angular/angular.js"></script>
1010
<script src="/static/lib/angular/angular-resource.js"></script>
11-
12-
<script src="/static/js/flow.js"></script>
1311
<script src="/static/js/app.js"></script>
14-
<script src="/static/js/controllers.js"></script>
15-
<script src="/static/js/services.js"></script>
12+
1613

1714
<script src="/static/lib/jquery/jquery.min.js"></script>
1815
<script src="/static/lib/bootstrap/bootstrap.min.js"></script>
1916

2017
<!-- <script type="text/javascript" src="angular.min.js"></script>-->
2118

2219
</head>
23-
<body ng-app="fileUpload" ng-controller="MyCtrl">
24-
<div id="header" class="header navbar navbar-static-top">
25-
<div class="navbar-inner">
26-
<div class="container">
27-
<!--
28-
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
29-
</button>
30-
<a class="brand" href="/">AngularFlask</a>
31-
<div class="nav-collapse collapse">
32-
<ul class="nav pull-right">
33-
<li class="">
34-
<a href="/">Home</a>
35-
</li>
36-
</ul>
37-
</div>
38-
-->
39-
</div>
40-
</div>
41-
</div>
42-
43-
44-
<div class="container page">
45-
<div id="content" class="container main" ng-view>
46-
47-
<form name="myForm">
48-
<fieldset>
49-
<legend>Upload on form submit</legend>
50-
Username:
51-
<input type="text" name="userName" ng-model="username" size="31" required>
52-
<i ng-show="myForm.userName.$error.required">*required</i>
53-
<br>Photo:
54-
<input type="file" ngf-select ng-model="picFile" name="file"
55-
accept="image/*" ngf-max-size="2MB" required
56-
ngf-model-invalid="errorFile">
57-
<i ng-show="myForm.file.$error.required">*required</i><br>
58-
<img ng-show="myForm.file.$valid" ngf-thumbnail="picFile" class="thumb"> <button ng-click="picFile = null" ng-show="picFile">Remove</button>
59-
<br>
60-
<button ng-disabled="!myForm.$valid"
61-
ng-click="uploadPic(picFile)">Submit</button>
62-
<span class="progress" ng-show="picFile.progress >= 0">
63-
</span>
64-
<span ng-show="picFile.result">Upload Successful</span>
65-
</fieldset>
66-
<br>
67-
</form>
68-
69-
70-
71-
</div>
72-
73-
<hr>
74-
<footer id="footer" class="footer">
75-
<!--
76-
<div class="footer-left">
77-
<a href="/about">About</a> |
78-
<a href="/">Home</a>
79-
</div>
80-
-->
81-
<div class="footer-right">
82-
<span>&copy; 2016 BaezCorp</span>
83-
</div>
84-
</footer>
85-
</div>
20+
<body ng-app="app" ng-controller="myController">
21+
<form>
22+
<input type="file" file-model="myFile" />
23+
<button ng-click="uploadFile()"> upload me</button>
24+
</form>
8625
</body>
8726
</html/>

tasks.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from celery import Celery
22
from flask.ext.sqlalchemy import SQLAlchemy
3-
from app.mod_winners.models import Winner
4-
from app.mod_auth.models import User
53
from app.data import db
64

75
celery = Celery('tasks')

0 commit comments

Comments
 (0)