Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/KSET/kset-org

Conflicts:
	kset/templates/members_templates/main.html
	requirements/base.txt
  • Loading branch information...
commit 40f2f0d8e879485ee80df6e764f17fe7a6c2cacd 2 parents 9a1f738 + 9856c90
@janza janza authored
View
0  kset/media/members/avatars/.keep
No changes.
View
2  kset/settings/base.py
@@ -117,6 +117,8 @@ def ensure_secret_key_file():
'newsletter',
'savjet',
'gallery',
+ 'sorl.thumbnail',
+ 'ajaxuploader',
)
View
58 kset/templates/members_templates/main.html
@@ -5,6 +5,48 @@
{% endblock members-css %}
{% block members-jss %}
+ <script src="{{ STATIC_URL }}ajaxuploader/js/fileuploader.js" ></script>
+ <link href="{{ STATIC_URL }}ajaxuploader/css/fileuploader.css" media="screen" rel="stylesheet" type="text/css" />
+ <script>
+ jQuery(function(){
+ var uploader = new qq.FileUploader({
+ action: "{% url 'members_avatar_upload' %}",
+ element: $('#file-uploader')[0],
+ multiple: false,
+ disableCancelForFormUploads: true,
+ allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
+ sizeLimit: 5242880,
+ onComplete: function(id, fileName, responseJSON) {
+ if(responseJSON.success) {
+ // alert("success!");
+ // $("#upload-button").removeAttr("disabled");
+ // $("#upload-button").removeClass("btn-inverse");
+ // $("#upload-button").addClass("btn-primary");
+
+ } else {
+ alert("Upload failed!");
+ }
+ },
+ onAllComplete: function(uploads) {
+ // uploads is an array of maps
+ // the maps look like this: {file: FileObject, response: JSONServerResponse}
+ var path = uploads[0].response.path
+ jQuery.ajax({
+ type: "POST",
+ url: "{% url 'members_avatar_update' %}",
+ data: {'filename': path}
+ });
+ location.reload();
+ },
+ params: {
+ 'csrf_token': '{{ csrf_token }}',
+ 'csrf_name': 'csrfmiddlewaretoken',
+ 'csrf_xname': 'X-CSRFToken',
+ },
+ });
+ });
+</script>
+
{% endblock members-jss %}
@@ -17,9 +59,19 @@
<div class="members-leftContent" style="">
{% block leftContent %}
<div class="top">
- <div class="image">
- {{member.image}}
- </div>
+
+ {% if member.image %}
+ <div id="member_avatar" class="image">
+ <img src="{{member.image}}" alt="Avatar">
+ </div>
+ {% endif %}
+ {% if is_owner %}
+ <div id="file-uploader">
+ <noscript>
+ <p>Please enable JavaScript to use file uploader.</p>
+ </noscript>
+ </div>
+ {% endif %}
</div>
{% endblock %}
</div>
View
2  kset/templates/news-item.html
@@ -31,7 +31,7 @@ <h1 class="single-title" itemprop="name">{{ news.subject }}</h1>
<section class="single-thumb">
{% if news.thumb %}
- <img src="{% version event.thumb 'semibig' %}" class="thumb" />
+ <img src="{% version news.thumb 'semibig' %}" class="thumb" />
{% endif %}
View
2  kset/templates/news.html
@@ -106,7 +106,7 @@ <h1 class="news-header">Večernji program</h1>
{% if item.thumb %}
<div class="news-item-thumb">
- <a href="{% url 'news_slug' slug=item.slug %}">
+ <a href="{% url 'event_slug' slug=item.slug %}">
<img src="{% version item.thumb 'event_big' %}" class="thumb" />
</a>
</div>
View
2  members/models.py
@@ -70,7 +70,7 @@ class Meta:
death = models.DateField("datum smrti", null=True, blank=True)
comment = HTMLField("komentar", null=True, blank=True)
groups = models.ManyToManyField(Group, through='MemberGroupLink')
- image = models.ImageField(upload_to="/", null=True, blank=True, verbose_name="slika")
+ image = models.ImageField(upload_to="members/avatars/", null=True, blank=True, verbose_name="slika")
objects = MemberManager()
def __init__(self, *args, **kwargs):
View
4 members/urls.py
@@ -19,6 +19,10 @@
name='members_delete_address'),
url(r'^contact/delete/(?P<id>\d+)/$', 'delete_contact',
name='members_delete_contact'),
+ url(r'avatar/ajax-upload/$', 'import_uploader',
+ name="members_avatar_upload"),
+ url(r'avatar/ajax-upload/update/$', 'update_avatar',
+ name="members_avatar_update"),
# ispis crvenih za pozivnice
url(r'^red/table/$', 'red_table',
View
18 members/views.py
@@ -8,11 +8,17 @@
from django.contrib import messages
from django.core.exceptions import PermissionDenied
+from ajaxuploader.views import AjaxFileUploader
+from ajaxuploader.backends.thumbnail import ThumbnailUploadBackend
+
from .forms import *
from .models import *
from .decorators import require_auth
+import_uploader = AjaxFileUploader(backend=ThumbnailUploadBackend, DIMENSIONS="170x200", KEEP_ORIGINAL=False)
+
+
def _display_member(request, template, member, address_form=None, contact_form=None):
return render(request, template, {
@@ -43,6 +49,18 @@ def index(request):
return _display_member(request, 'main.html', member, address_form, contact_form)
+@require_auth
+@require_POST
+def update_avatar(request):
+ member = get_object_or_404(Member, id=request.session['members_user_id'])
+ # FIXME: We should use a form here
+ filename = request.POST.get('filename')
+ if filename:
+ member.image = filename
+ member.save()
+ return redirect('members_index')
+
+
def login(request):
if request.session.get('members_user_id'):
return redirect('members_index')
View
2  requirements/base.txt
@@ -10,3 +10,5 @@ reportlab==2.7
djorm-ext-expressions==0.6
djorm-ext-pgarray==0.10
psycopg2==2.5.1
+sorl-thumbnail==11.12
+ajaxuploader==0.3.4
Please sign in to comment.
Something went wrong with that request. Please try again.