pep
This commit is contained in:
parent
1af80897ac
commit
0ad5e4ae9d
|
@ -1,19 +1,19 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
# from ih import images
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
name = models.CharField(max_length=30, blank=True)
|
name = models.CharField(max_length=30, blank=True)
|
||||||
file = models.FileField(upload_to='images')
|
file = models.FileField(upload_to='images')
|
||||||
# thumb = models.CharField(max_length=32, null=True, blank=True)
|
thumb_name = property(thumb_name)
|
||||||
|
orig_name = property(orig_name)
|
||||||
|
|
||||||
def publish(self):
|
def publish(self):
|
||||||
self.published_date = timezone.now()
|
self.published_date = timezone.now()
|
||||||
print(self.__dict__)
|
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
@ -22,21 +22,7 @@ class Post(models.Model):
|
||||||
def thumb_name(self):
|
def thumb_name(self):
|
||||||
x = os.path.split(self.file.name)[-1]
|
x = os.path.split(self.file.name)[-1]
|
||||||
return '/thumb_' + x
|
return '/thumb_' + x
|
||||||
|
|
||||||
thumb_name = property(thumb_name)
|
|
||||||
|
|
||||||
def orig_name(self):
|
def orig_name(self):
|
||||||
|
|
||||||
x = os.path.split(self.file.name)[-1]
|
x = os.path.split(self.file.name)[-1]
|
||||||
return x
|
return x
|
||||||
|
|
||||||
orig_name = property(orig_name)
|
|
||||||
|
|
||||||
'''def resize_image(self.file):
|
|
||||||
path, file_long = os.path.split(self.file)
|
|
||||||
|
|
||||||
im=image.open(file_long)
|
|
||||||
size = 128, 128
|
|
||||||
im.thumbnail(size)
|
|
||||||
im.save(thumb_name)
|
|
||||||
property(resize_image)'''
|
|
|
@ -1,38 +1,35 @@
|
||||||
{% extends 'imagehosting/base.html' %}
|
{% extends 'imagehosting/base.html' %}
|
||||||
|
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
{% block content%}
|
{% block content%}
|
||||||
<div class="images">
|
<div class="images">
|
||||||
{% for image in all %}<a href="{% url 'image_detail' pk=image.pk %}" ><img src= "/media/images{{image.thumb_name }}"></a>{% endfor %}
|
{% for image in all %}<a href="{% url 'image_detail' pk=image.pk %}" ><img src= "/media/images{{image.thumb_name }}"></a>{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
|
||||||
<script>
|
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
||||||
$(function() {resizer(); })
|
<script>
|
||||||
$(window).resize(function() { resizer(); })
|
$(function() {resizer(); })
|
||||||
|
$(window).resize(function() { resizer(); })
|
||||||
function resizer() {
|
|
||||||
var imgs = $('img');
|
|
||||||
var row_width = $(window).width() - 50;
|
|
||||||
console.log(row_width);
|
|
||||||
//console.log(document.body.offsetWidth);
|
|
||||||
var prev = [];
|
|
||||||
var total_w = 0;
|
|
||||||
imgs.each(function (i, e) {
|
|
||||||
|
|
||||||
$(this).height(200);
|
|
||||||
prev[prev.length] = $(e);
|
|
||||||
total_w += $(e).width();
|
|
||||||
if (total_w > row_width) {
|
|
||||||
prev = $(prev);
|
|
||||||
prev.each(function (indx, element) {$(element).height(row_width*200/total_w);});
|
|
||||||
prev = [];
|
|
||||||
total_w = 0;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
//$('img').css('display', 'inline');
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
function resizer() {
|
||||||
|
var imgs = $('img');
|
||||||
|
var row_width = $(window).width() - 50;
|
||||||
|
var prev = [];
|
||||||
|
var total_w = 0;
|
||||||
|
imgs.each(function (i, e) {
|
||||||
|
$(this).height(200);
|
||||||
|
prev[prev.length] = $(e);
|
||||||
|
total_w += $(e).width();
|
||||||
|
if (total_w > row_width) {
|
||||||
|
prev = $(prev);
|
||||||
|
prev.each(function (indx, element) {$(element).height(row_width*200/total_w)});
|
||||||
|
prev = [];
|
||||||
|
total_w = 0;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,105 +1,114 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
|
||||||
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans:600" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans:600" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
|
||||||
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
||||||
<style>
|
<style>
|
||||||
body {margin: 0}
|
body {
|
||||||
.images {
|
margin: 0;
|
||||||
margin-top: 10px;
|
}
|
||||||
margin-left: 25px;
|
|
||||||
}
|
.images {
|
||||||
.header {dispaly: block;
|
margin-top: 10px;
|
||||||
color: black ;
|
margin-left: 25px;
|
||||||
background: linear-gradient(#f3f3f3, #e0e0e0);
|
}
|
||||||
//height: 50px;
|
|
||||||
padding: 10px 25px;
|
.header {
|
||||||
font-size: 30px
|
dispaly: block;
|
||||||
}
|
color: black;
|
||||||
ul.menu-icon {
|
background: linear-gradient(#f3f3f3, #e0e0e0);
|
||||||
display: none;
|
padding: 10px 25px;
|
||||||
float: right;
|
font-size: 30px
|
||||||
color: black;
|
}
|
||||||
padding: 7px 0 20px ;
|
|
||||||
margin: 0;
|
ul.menu-icon {
|
||||||
}
|
display: none;
|
||||||
.logo {
|
float: right;
|
||||||
font-family: 'Open Sans', sans-serif;
|
color: black;
|
||||||
color: #696969;
|
padding: 7px 0 20px;
|
||||||
width: 50px;
|
margin: 0;
|
||||||
text-decoration: none;
|
}
|
||||||
}
|
|
||||||
|
.logo {
|
||||||
|
font-family: 'Open Sans', sans-serif;
|
||||||
|
color: #696969;
|
||||||
|
width: 50px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
li {
|
li {
|
||||||
list-style-type: none
|
list-style-type: none
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu {
|
.menu {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
//background: linear-gradient(#f3f3f3, #e0e0e0);
|
right: 10px;
|
||||||
//width: 300px;
|
top: 60px;
|
||||||
right: 10px;
|
display: none;
|
||||||
top: 60px;
|
}
|
||||||
display: none;
|
|
||||||
}
|
.menu a {
|
||||||
.menu a {
|
text-align: right;
|
||||||
text-align: right;
|
display: inline-block;
|
||||||
display: inline-block;
|
padding: 10px;
|
||||||
padding: 10px;
|
background: #e0e0e0;
|
||||||
background: #e0e0e0;
|
width: 90%;
|
||||||
//background: linear-gradient(#f3f3f3, #e0e0e0);
|
text-decoration: none;
|
||||||
width: 90%;
|
}
|
||||||
//border-top:1px solid #eee;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
.menu a:hover {
|
|
||||||
color:#181D2B ;}
|
|
||||||
//ul.menu-icon:hover ul.menu{display: block;}
|
|
||||||
i {float: right;}
|
|
||||||
.right-menu {float: right;
|
|
||||||
padding: 12px;
|
|
||||||
font-family: 'Open Sans', sans-serif;
|
|
||||||
font-size: 20px;
|
|
||||||
display: inline;
|
|
||||||
}
|
|
||||||
a.right-menu {
|
|
||||||
text-decoration: none;
|
|
||||||
color: #4368AD; padding: 9px;
|
|
||||||
//border-left: 1px solid rgb(43, 63, 101)
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (max-width: 450px) {
|
.menu a:hover {
|
||||||
|
color:#181D2B;
|
||||||
|
}
|
||||||
|
|
||||||
|
i {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right-menu {
|
||||||
|
float: right;
|
||||||
|
padding: 12px;
|
||||||
|
font-family: 'Open Sans', sans-serif;
|
||||||
|
font-size: 20px;
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.right-menu {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #4368AD;
|
||||||
|
padding: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 450px) {
|
||||||
|
|
||||||
ul.menu-icon {display: block}
|
ul.menu-icon {display: block}
|
||||||
a.right-menu {display: none}
|
a.right-menu {display: none}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class='header'> <a href="{% url 'all_posts' %}" class='logo'>LOGO </a>
|
<div class='header'> <a href="{% url 'all_posts' %}" class='logo'>LOGO </a>
|
||||||
|
<a href="{% url 'image_new' %}" class='right-menu'>new image</a>
|
||||||
<a href="{% url 'image_new' %}" class='right-menu'>new image</a>
|
<a href="{% url 'all_posts' %}" class='right-menu'>all images</a>
|
||||||
<a href="{% url 'all_posts' %}" class='right-menu'>all images</a>
|
<ul class='menu-icon'>
|
||||||
<ul class='menu-icon'> <li> <i class="fa fa-bars"></i> </li>
|
<li><i class="fa fa-bars"></i></li>
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
<li class="long"><a href="{% url 'image_new' %}">new image</a></li>
|
<li class="long"><a href="{% url 'image_new' %}">new image</a></li>
|
||||||
<li class="long"><a href="{% url 'all_posts' %}">all images</a></li>
|
<li class="long"><a href="{% url 'all_posts' %}">all images</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock%}
|
{% endblock%}
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
$('.menu-icon').click(function() {if ($('.menu').css('display') == 'block') {
|
$('.menu-icon').click(function() {if ($('.menu').css('display') == 'block') {
|
||||||
$('.menu').css('display', 'none') } else {
|
$('.menu').css('display', 'none') } else {
|
||||||
$('.menu').css('display', 'block')
|
$('.menu').css('display', 'block')
|
||||||
|
}})
|
||||||
}})
|
</script>
|
||||||
</script>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
{% load staticfiles %}
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Gallery</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<nav>
|
|
||||||
<div class="nav-wrapper teal lighten-2">
|
|
||||||
<a class="brand-logo" href="/">Gallery</a>
|
|
||||||
</div>
|
|
||||||
<div class="nav-wrapper teal lighten-2">
|
|
||||||
|
|
||||||
<ul class="right">
|
|
||||||
<li><a href="/pfm">PFM</a>
|
|
||||||
<li><a class="dropdown-button" href="#1" data-activates="dropdown1">Notes</a><ul id="dropdown1" class="dropdown-content"></li> <li> <a href="{% url 'blog.views.post_new' %}">new post</a></li> <li><a href="/blog/1">all notes</a></li></ul>
|
|
||||||
<li><a class="dropdown-button" href="#2" data-activates="dropdown2">Imagehost</a><ul id="dropdown2" class="dropdown-content"></li><li> <a href="{% url 'imagehost.views.image_new' %}">new image</a></li> <li> <a href="{% url 'imagehost.views.all_posts' %}"><span>all images</span></a></li></ul>
|
|
||||||
<li><a href="/admin">/admin</a></li>
|
|
||||||
|
|
||||||
</ul></div></nav>
|
|
||||||
|
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
|
|
||||||
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
|
|
||||||
<script type="text/javascript" src="/js/materialize.min.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
$(document).ready(function(){
|
|
||||||
$('.carousel').carousel({ shift: 20 });
|
|
||||||
$('.materialboxed').materialbox();
|
|
||||||
$(".dropdown-button").dropdown();
|
|
||||||
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<!--Import Google Icon Font>
|
|
||||||
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"-->
|
|
||||||
<!--Import materialize.css-->
|
|
||||||
<link type="text/css" rel="stylesheet" href="/css/materialize.min.css" media="screen,projection">
|
|
||||||
|
|
||||||
<!--Let browser know website is optimized for mobile-->
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
||||||
<div class="card-panel teal lighten-5">
|
|
||||||
|
|
||||||
<div class="carousel">
|
|
||||||
{% for image in all %}
|
|
||||||
<a href="{% url 'image_detail' pk=image.pk %}"--> <a class="carousel-item"><img width="650" src="/media/images{{ image.thumb_name }}" ></a>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card-panel teal lighten-5">
|
|
||||||
<div class="row" style="display: flex; flex-wrap: wrap;">
|
|
||||||
{% for image in all %}
|
|
||||||
<div class="col s12 m6 l3">
|
|
||||||
<div class="card blue-grey darken-1"> <div class="card-content"> <img class="thumbnail" src="/media/images{{ image.thumb_name }}" ></a> </div>
|
|
||||||
<div class="card-action white-text"><a href="{% url 'image_detail' pk=image.pk %}">{{ image.name }}</a></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card-panel s1 teal lighten-5">1</div>
|
|
||||||
</div>
|
|
|
@ -2,16 +2,14 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="block" style="position: relative; width: 400px; width: padding: 50px; border: 1px solid #e0e0e0; margin: 100px auto;">
|
<div class="block" style="position: relative; width: 400px; width: padding: 50px; border: 1px solid #e0e0e0; margin: 100px auto;">
|
||||||
|
|
||||||
<a href="/media/{{post.file}}"><img src="/media/images{{ post.thumb_name }}" style="margin: auto; display: block; padding: 10px"></a>
|
<a href="/media/{{post.file}}"><img src="/media/images{{ post.thumb_name }}" style="margin: auto; display: block; padding: 10px"></a>
|
||||||
<div style="margin: auto; display: block; padding: 10px 0 20px; width: 140px; text-align: center;">
|
<div style="margin: auto; display: block; padding: 10px 0 20px; width: 140px; text-align: center;">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<a href="{% url 'delete_post' pk=post.pk %}" onclick = "return confirm('Удалить?')" style="padding-right: 30px; color: #888787">удалить</a>
|
<a href="{% url 'delete_post' pk=post.pk %}" onclick = "return confirm('Удалить?')" style="padding-right: 30px; color: #888787">удалить</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="/media/{{post.file}}" download style=" color: #888787; margin: auto; text-align: right"> {{ post.name }} скачать</a>
|
<a href="/media/{{post.file}}" download style=" color: #888787; margin: auto; text-align: right"> {{ post.name }} скачать</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="block" style="width: 500px; padding: 50px; margin: 100px auto; border: 1px solid #e0e0e0">
|
<div class="block" style="width: 500px; padding: 50px; margin: 100px auto; border: 1px solid #e0e0e0">
|
||||||
<form method="POST" class="post-form" enctype="multipart/form-data" action="" >{% csrf_token %}
|
<form method="POST" class="post-form" enctype="multipart/form-data" action="" >{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<input type="submit" value="send" class="save btn btn-default"></button>
|
<input type="submit" value="send" class="save btn btn-default"></button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
{% extends 'imagehosting/base.html' %}
|
{% extends 'imagehosting/base.html' %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<form method="post" action="{% url 'login' %}" class="w3-container" style="padding: 20px">
|
||||||
<form method="post" action="{% url 'login' %}" class="w3-container" style="padding: 20px">
|
<table>
|
||||||
<table>
|
{% csrf_token %}
|
||||||
{% csrf_token %}
|
{{form.as_table}}
|
||||||
{{form.as_table}}
|
<tr><td></td><td><input id="login" type="submit" class="w3-btn w3-right"value="login" /></td></tr>
|
||||||
<tr><td></td><td><input id="login" type="submit" class="w3-btn w3-right"value="login" /></td></tr>
|
</table>
|
||||||
</table>
|
<input type="hidden" name="next" value="{{ next }}" />
|
||||||
|
</form>
|
||||||
<input type="hidden" name="next" value="{{ next }}" />
|
{% endblock %}
|
||||||
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
|
@ -8,11 +8,11 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth.views import login, logout
|
from django.contrib.auth.views import login, logout
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.image_new, name='image_new'),
|
url(r'^$', views.image_new, name='image_new'),
|
||||||
url(r'^post/(?P<pk>[0-9]+)/$', views.image_detail, name='image_detail'),
|
url(r'^post/(?P<pk>[0-9]+)/$', views.image_detail, name='image_detail'),
|
||||||
url(r'^all/$', views.all_posts, name='all_posts'),
|
url(r'^all/$', views.all_posts, name='all_posts'),
|
||||||
url(r'^carousel/$', views.carousel, name='carousel'),
|
|
||||||
url(r'^delete/(?P<pk>[0-9]+)/$', views.delete_post, name='delete_post'),
|
url(r'^delete/(?P<pk>[0-9]+)/$', views.delete_post, name='delete_post'),
|
||||||
url(r'^admin/', admin.site.urls),
|
url(r'^admin/', admin.site.urls),
|
||||||
url(r'^login$', login, {'template_name':'imagehosting/login.html'}, name='login'),
|
url(r'^login$', login, {'template_name':'imagehosting/login.html'}, name='login'),
|
||||||
|
|
|
@ -5,84 +5,47 @@ from .models import Post
|
||||||
from .forms import PostForm, DeleteForm
|
from .forms import PostForm, DeleteForm
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from ih import files, images
|
from ih import files, images
|
||||||
#from django.views.decorators.csrf import requires_csrf_token
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from ih import images
|
from ih import images
|
||||||
from django.views.decorators.csrf import requires_csrf_token
|
from django.views.decorators.csrf import requires_csrf_token
|
||||||
|
|
||||||
'''def create_thumbnail(request):
|
|
||||||
# Get file from <InMemoryUploadedFile>
|
|
||||||
file_l, filename = files.get_file_from_request(request, 'file')
|
|
||||||
fh = files.write_to_shm(file_l, filename)
|
|
||||||
file_l = None
|
|
||||||
|
|
||||||
# Create thumbnail
|
|
||||||
thumb_name = images.resize_image(fh, {
|
|
||||||
'name': filename,
|
|
||||||
'size': (100, 100),
|
|
||||||
'dest': 'mysite/media/images'
|
|
||||||
}
|
|
||||||
|
|
||||||
)
|
|
||||||
print(thumb_name)
|
|
||||||
# Remove file from shm
|
|
||||||
e = files.rm_from_shm(filename)
|
|
||||||
if e is not True:
|
|
||||||
print "WARNING: " + e
|
|
||||||
|
|
||||||
return thumb_name'''
|
|
||||||
|
|
||||||
|
|
||||||
def create_thumb_from_file(filename):
|
def create_thumb_from_file(filename):
|
||||||
orig_file = 'imagehost/media/images/' + filename
|
orig_file = 'imagehost/media/images/' + filename
|
||||||
# f = str(filename)
|
|
||||||
# print(filename)
|
|
||||||
# print f
|
|
||||||
# Create thumbnail
|
# Create thumbnail
|
||||||
print("DEBUG: Resizing image " + orig_file)
|
|
||||||
thumb_name = images.resize_image(orig_file, {
|
thumb_name = images.resize_image(orig_file, {
|
||||||
'name': filename,
|
'name': filename,
|
||||||
'size': [300, 300],
|
'size': [300, 300],
|
||||||
'dest': 'imagehost/media/images'
|
'dest': 'imagehost/media/images'
|
||||||
}
|
}
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return thumb_name
|
return thumb_name
|
||||||
|
|
||||||
|
|
||||||
@login_required(login_url="/login")
|
@login_required(login_url="/login")
|
||||||
def image_new(request):
|
def image_new(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = PostForm(request.POST, request.FILES)
|
form = PostForm(request.POST, request.FILES)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
# thumb_name = create_thumbnail(request)
|
|
||||||
post = form.save(commit=False)
|
post = form.save(commit=False)
|
||||||
post.save()
|
post.save()
|
||||||
# print("FILE: ", post.file)
|
|
||||||
print(post.orig_name)
|
|
||||||
create_thumb_from_file(post.orig_name)
|
create_thumb_from_file(post.orig_name)
|
||||||
return redirect('imagehosting.views.image_detail', pk=post.id)
|
return redirect('imagehosting.views.image_detail', pk=post.id)
|
||||||
else:
|
else:
|
||||||
form = PostForm()
|
form = PostForm()
|
||||||
return render(request, 'imagehosting/index.html', {'form': form})
|
return render(request, 'imagehosting/index.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
def image_detail(request, pk):
|
def image_detail(request, pk):
|
||||||
post = get_object_or_404(Post, pk=pk)
|
post = get_object_or_404(Post, pk=pk)
|
||||||
print(post)
|
|
||||||
return render(request, 'imagehosting/image.html', {'post': post})
|
return render(request, 'imagehosting/image.html', {'post': post})
|
||||||
|
|
||||||
|
|
||||||
def all_posts(request):
|
def all_posts(request):
|
||||||
all = Post.objects.order_by('-pk')
|
all = Post.objects.order_by('-pk')
|
||||||
# page = request.POST.get("page")
|
|
||||||
return render(request, 'imagehosting/all.html', {'all': all})
|
return render(request, 'imagehosting/all.html', {'all': all})
|
||||||
|
|
||||||
|
|
||||||
def carousel(request):
|
|
||||||
return render(request, 'imagehosting/carousel.html', {'all': Post.objects.all()})
|
|
||||||
|
|
||||||
#@requires_csrf_token
|
|
||||||
@login_required(login_url="/login")
|
@login_required(login_url="/login")
|
||||||
def delete_post(request, pk):
|
def delete_post(request, pk):
|
||||||
post_to_delete = get_object_or_404(Post, pk=pk)
|
post_to_delete = get_object_or_404(Post, pk=pk)
|
||||||
|
@ -93,6 +56,4 @@ def delete_post(request, pk):
|
||||||
return HttpResponseRedirect('/admin')
|
return HttpResponseRedirect('/admin')
|
||||||
post_to_delete.delete()
|
post_to_delete.delete()
|
||||||
return redirect('imagehosting.views.all_posts')
|
return redirect('imagehosting.views.all_posts')
|
||||||
|
return render(request, 'imagehosting/delete.html', {'form': form})
|
||||||
#return render(request, 'imagehosting/delete.html', {'form': form})
|
|
||||||
return render(request, 'imagehosting/delete.html', {'form': form})
|
|
|
@ -1,18 +0,0 @@
|
||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% load pagination_tags %}
|
|
||||||
|
|
||||||
{% block content%}
|
|
||||||
<div style="display: flex; width: 101%; flex-wrap: wrap; justify-content: space-between; ">
|
|
||||||
{% for image in all %}
|
|
||||||
<div class="block" style="margin-bottom: 1em; width: 20em; height: 20em; padding: 0.5em; float: left; position:relative; flex-wrap: wrap; ">
|
|
||||||
<a href="{% url 'image_detail' pk=image.pk %}"><img style="position: absolute; bottom: 1em; right: 1em; " src="/media/images{{ image.thumb_name }}" padding=3%></a>
|
|
||||||
<span style="display:inline-block; position:absolute;top:30px; left:0px; background-color:rgba(230, 230, 230,.4); padding:10px 30px;" >
|
|
||||||
<a href="{% url 'image_detail' pk=image.pk %}">{{ image.name }}</a></span>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock content %}
|
|
||||||
|
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
|
|
||||||
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans:600" rel="stylesheet">
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
|
|
||||||
|
|
||||||
<style>
|
|
||||||
body {margin: 0}
|
|
||||||
.header {dispaly: block;
|
|
||||||
color: black ;
|
|
||||||
background: linear-gradient(#f3f3f3, #e0e0e0);
|
|
||||||
//height: 50px;
|
|
||||||
padding: 10px 25px;
|
|
||||||
font-size: 30px
|
|
||||||
}
|
|
||||||
.menu-icon {
|
|
||||||
display: inline-block;
|
|
||||||
float: right;
|
|
||||||
//color: #696969;
|
|
||||||
color: black;
|
|
||||||
padding: 1px;
|
|
||||||
}
|
|
||||||
.logo {
|
|
||||||
font-family: 'Open Sans', sans-serif;
|
|
||||||
color: #696969;
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class='header'> <span class='logo'>LOGO </span> <a class='menu-icon' href =""><i class="fa fa-bars"></i></a> </div>
|
|
||||||
{% block content %}
|
|
||||||
{% endblock%}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,62 +0,0 @@
|
||||||
{% load staticfiles %}
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Gallery</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<nav>
|
|
||||||
<div class="nav-wrapper teal lighten-2">
|
|
||||||
<a class="brand-logo" href="/">Gallery</a>
|
|
||||||
</div>
|
|
||||||
<div class="nav-wrapper teal lighten-2">
|
|
||||||
|
|
||||||
<ul class="right">
|
|
||||||
<li><a href="/pfm">PFM</a>
|
|
||||||
<li><a class="dropdown-button" href="#1" data-activates="dropdown1">Notes</a><ul id="dropdown1" class="dropdown-content"></li> <li> <a href="{% url 'blog.views.post_new' %}">new post</a></li> <li><a href="/blog/1">all notes</a></li></ul>
|
|
||||||
<li><a class="dropdown-button" href="#2" data-activates="dropdown2">Imagehost</a><ul id="dropdown2" class="dropdown-content"></li><li> <a href="{% url 'imagehost.views.image_new' %}">new image</a></li> <li> <a href="{% url 'imagehost.views.all_posts' %}"><span>all images</span></a></li></ul>
|
|
||||||
<li><a href="/admin">/admin</a></li>
|
|
||||||
|
|
||||||
</ul></div></nav>
|
|
||||||
|
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
|
|
||||||
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
|
|
||||||
<script type="text/javascript" src="/js/materialize.min.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
$(document).ready(function(){
|
|
||||||
$('.carousel').carousel({ shift: 20 });
|
|
||||||
$('.materialboxed').materialbox();
|
|
||||||
$(".dropdown-button").dropdown();
|
|
||||||
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<!--Import Google Icon Font>
|
|
||||||
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"-->
|
|
||||||
<!--Import materialize.css-->
|
|
||||||
<link type="text/css" rel="stylesheet" href="/css/materialize.min.css" media="screen,projection">
|
|
||||||
|
|
||||||
<!--Let browser know website is optimized for mobile-->
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
||||||
<div class="card-panel teal lighten-5">
|
|
||||||
|
|
||||||
<div class="carousel">
|
|
||||||
{% for image in all %}
|
|
||||||
<a href="{% url 'image_detail' pk=image.pk %}"--> <a class="carousel-item"><img width="650" src="/media/images{{ image.thumb_name }}" ></a>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card-panel teal lighten-5">
|
|
||||||
<div class="row" style="display: flex; flex-wrap: wrap;">
|
|
||||||
{% for image in all %}
|
|
||||||
<div class="col s12 m6 l3">
|
|
||||||
<div class="card blue-grey darken-1"> <div class="card-content"> <img class="thumbnail" src="/media/images{{ image.thumb_name }}" ></a> </div>
|
|
||||||
<div class="card-action white-text"><a href="{% url 'image_detail' pk=image.pk %}">{{ image.name }}</a></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card-panel s1 teal lighten-5">1</div>
|
|
||||||
</div>
|
|
|
@ -1,10 +0,0 @@
|
||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div> <h1>Delete</h1>
|
|
||||||
<form method="POST">{% csrf_token %}
|
|
||||||
{{ form.as_p }}
|
|
||||||
<button type="submit" class="save btn btn-default">delete</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
|
@ -1,13 +0,0 @@
|
||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="block" style="position: relative; ">
|
|
||||||
|
|
||||||
<p><a href="/media/{{post.file}}"><img src="/media/images{{ post.thumb_name }}" padding=3%></a></p>
|
|
||||||
<p><a href="/media/{{post.file}}" download> {{ post.name }} скачать </a></p>
|
|
||||||
|
|
||||||
<spam class="edit" style="position: absolute; bottom: 20px; right: 20px;"><a href="{% url 'delete_post' pk=post.pk %}">удалить</a></span>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="block">
|
|
||||||
<form method="POST" class="post-form" enctype="multipart/form-data" action="" >{% csrf_token %}
|
|
||||||
{{ form.as_p }}
|
|
||||||
<input type="submit" value="send" class="save btn btn-default"></button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
Loading…
Reference in New Issue
Block a user