Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. <div id="dropzone-div">
  2. <form class = "dropzone" id = "image-form">
  3. {% csrf_token %}
  4. <div class="dropzone-previews"></div>
  5. <input type = "text" name = "album_Id" id = "album_Id" hidden>
  6. <div class="fallback">
  7. <input name="image_file" type="file" multiple="" />
  8.  
  9. </div>
  10. <input type = "reset" id ="resetImageForm" hidden>
  11. </form>
  12. </div>
  13.  
  14. <span><button class="btn btn-success" id = "upload">Upload</button></span>
  15.  
  16. var myDropzone = new Dropzone(".dropzone", {
  17. url: "{% url 'upload' %}",
  18. addRemoveLinks: true,
  19. thumbnailWidth: "80",
  20. thumbnailHeight: "80",
  21. dictCancelUpload: "Cancel",
  22. parallelUploads: 100,
  23. autoProcessQueue: false
  24. });
  25.  
  26. myDropzone.on("drop", function (event) {
  27. $('.dropzone').animate({
  28. opacity: 1,
  29. top: "-5"
  30. });
  31. });
  32.  
  33.  
  34. $("#upload").on('click', function () {
  35. myDropzone.processQueue();
  36. $.ajax({
  37. type: "POST",
  38. url: "{% url 'getPhoto' %}",
  39. dataType: "json",
  40. async: true,
  41. data: {
  42. album_Id_1:$("#album_Id").val()
  43. },
  44. success: function (json_data) {
  45.  
  46. alert(json_data)
  47. }
  48. });
  49.  
  50.  
  51. });
  52.  
  53. #module for uploading images
  54. @csrf_exempt
  55. def uploadImages(request):
  56. try:
  57. if request.session['member_id'] is not None:
  58. if request.method == "POST":
  59. album_Id = request.POST.get('album_Id','')
  60. files = request.FILES.getlist('file')
  61. for filename in files:
  62. save_image = AlbumPhotos(photo=filename, albumPhoto_id=album_Id)
  63. save_image.save()
  64.  
  65. data = {'status':'true'}
  66. return HttpResponse(json.dumps(data), content_type="application/json")
  67.  
  68. except KeyError:
  69. pass
  70. return redirect('/')
  71.  
  72.  
  73. #module for counting photos in current album
  74. @csrf_exempt
  75. def getPhotoCount(request):
  76.  
  77. if request.session['member_id'] is not None:
  78. if request.method == "POST":
  79. response = {}
  80. album_Id = request.POST.get('album_Id_1','')
  81. countPhotos = AlbumPhotos.objects.filter(albumPhoto_id=album_Id).count()
  82. print("_______",countPhotos)
  83. response['count'] = countPhotos
  84. return HttpResponse(json.dumps(response), content_type="application/json")
  85.  
  86. #except KeyError:
  87. # pass
  88. #return redirect('/')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement