parent
0d2396c48e
commit
8e0657a011
17 changed files with 369 additions and 62 deletions
@ -0,0 +1,47 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
# Generated by Django 1.9.7 on 2016-07-11 14:59 |
||||||
|
from __future__ import unicode_literals |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
import django.db.models.deletion |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('users', '0019_auto_20160710_1950'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.CreateModel( |
||||||
|
name='ContractorResume', |
||||||
|
fields=[ |
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||||
|
('text', models.TextField()), |
||||||
|
('resume_file', models.FileField(upload_to='users/resume/files/')), |
||||||
|
], |
||||||
|
options={ |
||||||
|
'verbose_name': 'Резюме', |
||||||
|
'verbose_name_plural': 'Резюме', |
||||||
|
}, |
||||||
|
), |
||||||
|
migrations.CreateModel( |
||||||
|
name='ContractorResumeFiles', |
||||||
|
fields=[ |
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||||
|
('img', models.ImageField(upload_to='users/resume/images/')), |
||||||
|
('title', models.CharField(max_length=255)), |
||||||
|
('description', models.TextField(blank=True)), |
||||||
|
('type', models.CharField(choices=[('diplom', 'Дипломы/Сертификаты'), ('cro', 'Допуск CPO')], max_length=50)), |
||||||
|
], |
||||||
|
options={ |
||||||
|
'verbose_name': 'Файлы резюме', |
||||||
|
'verbose_name_plural': 'Файлы резюме', |
||||||
|
}, |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='user', |
||||||
|
name='contractor_resume', |
||||||
|
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='contractor', to='users.ContractorResume'), |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
# Generated by Django 1.9.7 on 2016-07-11 16:27 |
||||||
|
from __future__ import unicode_literals |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
import django.db.models.deletion |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('users', '0020_auto_20160711_1759'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AddField( |
||||||
|
model_name='contractorresumefiles', |
||||||
|
name='resume', |
||||||
|
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='resume_files', to='users.ContractorResume'), |
||||||
|
preserve_default=False, |
||||||
|
), |
||||||
|
] |
||||||
@ -1,5 +1,6 @@ |
|||||||
from django.contrib import admin |
from django.contrib import admin |
||||||
from .models import WorkSell, WorkSellPhoto |
from .models import WorkSell, WorkSellPhoto, Picture |
||||||
|
|
||||||
admin.site.register(WorkSell) |
admin.site.register(WorkSell) |
||||||
|
admin.site.register(Picture) |
||||||
admin.site.register(WorkSellPhoto) |
admin.site.register(WorkSellPhoto) |
||||||
|
|||||||
@ -0,0 +1,23 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
# Generated by Django 1.9.7 on 2016-07-11 08:33 |
||||||
|
from __future__ import unicode_literals |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('work_sell', '0010_auto_20160707_1401'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.CreateModel( |
||||||
|
name='Picture', |
||||||
|
fields=[ |
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||||
|
('file', models.ImageField(upload_to='worksell/pictures')), |
||||||
|
('slug', models.SlugField(blank=True)), |
||||||
|
], |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
import json |
||||||
|
from django.http import HttpResponse |
||||||
|
|
||||||
|
MIMEANY = '*/*' |
||||||
|
MIMEJSON = 'application/json' |
||||||
|
MIMETEXT = 'text/plain' |
||||||
|
|
||||||
|
|
||||||
|
def response_mimetype(request): |
||||||
|
can_json = MIMEJSON in request.META['HTTP_ACCEPT'] |
||||||
|
can_json |= MIMEANY in request.META['HTTP_ACCEPT'] |
||||||
|
return MIMEJSON if can_json else MIMETEXT |
||||||
|
|
||||||
|
|
||||||
|
class JSONResponse(HttpResponse): |
||||||
|
def __init__(self, obj='', json_opts=None, mimetype=MIMEJSON, *args, **kwargs): |
||||||
|
json_opts = json_opts if isinstance(json_opts, dict) else {} |
||||||
|
content = json.dumps(obj, **json_opts) |
||||||
|
super().__init__(content, mimetype, *args, **kwargs) |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
import mimetypes |
||||||
|
from django.core.urlresolvers import reverse |
||||||
|
|
||||||
|
|
||||||
|
def serialize(instance, file_attr='file'): |
||||||
|
obj = getattr(instance, file_attr) |
||||||
|
return { |
||||||
|
'url': obj.url, |
||||||
|
'name': obj.name, |
||||||
|
'type': mimetypes.guess_type(obj.path)[0] or 'image/png', |
||||||
|
'size': obj.size, |
||||||
|
'deleteUrl': '/delete', |
||||||
|
'deleteType': 'DELETE', |
||||||
|
} |
||||||
@ -0,0 +1,117 @@ |
|||||||
|
{% load staticfiles %} |
||||||
|
<!DOCTYPE HTML> |
||||||
|
<html lang="en"> |
||||||
|
<head> |
||||||
|
<!-- Force latest IE rendering engine or ChromeFrame if installed --> |
||||||
|
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]--> |
||||||
|
<meta charset="utf-8"> |
||||||
|
<title>Django jQuery File Upload Demo - Basic version</title> |
||||||
|
<meta name="description" content="File Upload widget with multiple file selection, drag&drop support and progress bar for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (PHP, Python, Ruby on Rails, Java, Node.js, Go etc.) that supports standard HTML form file uploads."> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||||
|
<!-- Bootstrap styles --> |
||||||
|
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> |
||||||
|
<!-- Generic page styles --> |
||||||
|
<link rel="stylesheet" href="/static/css/style.css"> |
||||||
|
<link rel='stylesheet' href='{% static "lib/jquery.fileupload/css/jquery.fileupload.css" %}'> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<div class="navbar navbar-default navbar-fixed-top"> |
||||||
|
<div class="container"> |
||||||
|
<div class="navbar-header"> |
||||||
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-fixed-top .navbar-collapse"> |
||||||
|
<span class="icon-bar"></span> |
||||||
|
<span class="icon-bar"></span> |
||||||
|
<span class="icon-bar"></span> |
||||||
|
</button> |
||||||
|
<a class="navbar-brand" href="https://github.com/sigurdga/django-jquery-file-upload">Django jQuery File Upload</a> |
||||||
|
</div> |
||||||
|
<div class="navbar-collapse collapse"> |
||||||
|
<ul class="nav navbar-nav"> |
||||||
|
<li class="active"><a href="#">Demo</a></li> |
||||||
|
</ul> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="container"> |
||||||
|
<h1>Django jQuery File Upload Demo</h1> |
||||||
|
<h2 class="lead">Basic version</h2> |
||||||
|
<ul class="nav nav-tabs"> |
||||||
|
<li class="active"><a href="/upload/basic">Basic</a></li> |
||||||
|
<li><a href="/upload/basic/plus">Basic Plus</a></li> |
||||||
|
<li><a href="/upload/new">Basic Plus UI</a></li> |
||||||
|
<li><a href="/upload/angular">AngularJS</a></li> |
||||||
|
<li><a href="/upload/jquery-ui">jQuery UI</a></li> |
||||||
|
</ul> |
||||||
|
<br> |
||||||
|
<blockquote> |
||||||
|
<p>File Upload widget</p> |
||||||
|
</blockquote> |
||||||
|
<br> |
||||||
|
<!-- The fileinput-button span is used to style the file input field as button --> |
||||||
|
<span class="btn btn-success fileinput-button"> |
||||||
|
<i class="glyphicon glyphicon-plus"></i> |
||||||
|
<span>Select files...</span> |
||||||
|
<!-- The file input field used as target for the file upload widget --> |
||||||
|
<input id="fileupload" type="file" name="file" multiple> |
||||||
|
</span> |
||||||
|
<br> |
||||||
|
<br> |
||||||
|
<!-- The global progress bar --> |
||||||
|
<div id="progress" class="progress"> |
||||||
|
<div class="progress-bar progress-bar-success"></div> |
||||||
|
</div> |
||||||
|
<!-- The container for the uploaded files --> |
||||||
|
<div id="files" class="files"></div> |
||||||
|
<br> |
||||||
|
</div> |
||||||
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> |
||||||
|
<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included --> |
||||||
|
<script src="{% static 'lib/jquery.fileupload/js/vendor/jquery.ui.widget.js'%}"></script> |
||||||
|
<!-- The Iframe Transport is required for browsers without support for XHR file uploads --> |
||||||
|
<script src='{% static "lib/jquery.fileupload/js/jquery.iframe-transport.js" %}'></script> |
||||||
|
|
||||||
|
<!-- The basic File Upload plugin --> |
||||||
|
<script src='{% static "lib/jquery.fileupload/js/jquery.fileupload.js" %}'></script> |
||||||
|
<!-- Bootstrap JS is not required, but included for the responsive demo navigation --> |
||||||
|
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> |
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> |
||||||
|
<script> |
||||||
|
/*jslint unparam: true */ |
||||||
|
/*global window, $ */ |
||||||
|
function csrfSafeMethod(method) { |
||||||
|
// these HTTP methods do not require CSRF protection |
||||||
|
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); |
||||||
|
} |
||||||
|
$(function () { |
||||||
|
'use strict'; |
||||||
|
// Change this to the location of your server-side upload handler: |
||||||
|
var url = '/work_sell/basic/'; |
||||||
|
var csrftoken = $.cookie('csrftoken'); |
||||||
|
$('#fileupload').fileupload({ |
||||||
|
url: url, |
||||||
|
crossDomain: false, |
||||||
|
beforeSend: function(xhr, settings) { |
||||||
|
if (!csrfSafeMethod(settings.type)) { |
||||||
|
xhr.setRequestHeader("X-CSRFToken", csrftoken); |
||||||
|
} |
||||||
|
}, |
||||||
|
dataType: 'json', |
||||||
|
done: function (e, data) { |
||||||
|
console.log(data); |
||||||
|
$.each(data.result.files, function (index, file) { |
||||||
|
$('<p/>').text(file.name).appendTo('#files'); |
||||||
|
}); |
||||||
|
}, |
||||||
|
progressall: function (e, data) { |
||||||
|
var progress = parseInt(data.loaded / data.total * 100, 10); |
||||||
|
$('#progress .progress-bar').css( |
||||||
|
'width', |
||||||
|
progress + '%' |
||||||
|
); |
||||||
|
} |
||||||
|
}).prop('disabled', !$.support.fileInput) |
||||||
|
.parent().addClass($.support.fileInput ? undefined : 'disabled'); |
||||||
|
}); |
||||||
|
</script> |
||||||
|
</body> |
||||||
|
</html> |
||||||
Loading…
Reference in new issue