diff --git a/core/api.py b/core/api.py index 40209b3..229e010 100644 --- a/core/api.py +++ b/core/api.py @@ -137,7 +137,7 @@ class PinResource(ModelResource): return super(PinResource, self).save_m2m(bundle) class Meta: - fields = ['id', 'url', 'origin', 'description'] + fields = ['id', 'url', 'origin', 'description', 'referer'] ordering = ['id'] filtering = { 'submitter': ALL_WITH_RELATIONS diff --git a/core/migrations/0002_pin_referer.py b/core/migrations/0002_pin_referer.py new file mode 100644 index 0000000..6da3afe --- /dev/null +++ b/core/migrations/0002_pin_referer.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='pin', + name='referer', + field=models.URLField(null=True), + ), + ] diff --git a/core/models.py b/core/models.py index 7755866..838c412 100644 --- a/core/models.py +++ b/core/models.py @@ -42,6 +42,7 @@ class Pin(models.Model): submitter = models.ForeignKey(User) url = models.URLField(null=True) origin = models.URLField(null=True) + referer = models.URLField(null=True) description = models.TextField(blank=True, null=True) image = models.ForeignKey(Image, related_name='pin') published = models.DateTimeField(auto_now_add=True) diff --git a/pinry/static/js/bookmarklet.js b/pinry/static/js/bookmarklet.js index bb1df29..ee46d87 100644 --- a/pinry/static/js/bookmarklet.js +++ b/pinry/static/js/bookmarklet.js @@ -92,7 +92,8 @@ border: '1px solid #555' }); image.onclick = function() { - var popUrl = getFormUrl()+encodeURIComponent(imageUrl); + var popUrl = getFormUrl() + encodeURIComponent(imageUrl); + popUrl = popUrl + '&referer=' + encodeURIComponent(window.location); window.open(popUrl); closePinry(); }; diff --git a/pinry/static/js/pin-form.js b/pinry/static/js/pin-form.js index 74436d8..60c89b9 100644 --- a/pinry/static/js/pin-form.js +++ b/pinry/static/js/pin-form.js @@ -17,6 +17,7 @@ $(window).load(function() { return { submitter: currentUser, url: $('#pin-form-image-url').val(), + referer: $('#pin-form-referer').val(), description: $('#pin-form-description').val(), tags: cleanTags($('#pin-form-tags').val()) } @@ -26,6 +27,7 @@ $(window).load(function() { var context = {pins: [{ submitter: currentUser, image: {thumbnail: {image: $('#pin-form-image-url').val()}}, + referer: $('#pin-form-referer').val(), description: $('#pin-form-description').val(), tags: cleanTags($('#pin-form-tags').val()) }]}, @@ -59,9 +61,14 @@ $(window).load(function() { function createPinForm(editPinId) { $('body').append(renderTemplate('#pin-form-template', '')); var modal = $('#pin-form'), - formFields = [$('#pin-form-image-url'), $('#pin-form-description'), - $('#pin-form-tags')], - pinFromUrl = getUrlParameter('pin-image-url'); + formFields = [ + $('#pin-form-image-url'), + $('#pin-form-referer'), + $('#pin-form-description'), + $('#pin-form-tags') + ], + pinFromUrl = getUrlParameter('pin-image-url'), + pinFromReferer = getUrlParameter('referer'); // If editable grab existing data if (editPinId) { var promise = getPinData(editPinId); @@ -69,6 +76,7 @@ $(window).load(function() { editedPin = data; $('#pin-form-image-url').val(editedPin.image.thumbnail.image); $('#pin-form-image-url').parent().hide(); + $('#pin-form-referer').parent().hide(); $('#pin-form-image-upload').parent().hide(); $('#pin-form-description').val(editedPin.description); $('#pin-form-tags').val(editedPin.tags); @@ -113,6 +121,7 @@ $(window).load(function() { if (pinFromUrl) { $('#pin-form-image-upload').parent().css('display', 'none'); $('#pin-form-image-url').val(pinFromUrl); + $('#pin-form-referer').val(pinFromReferer); $('.navbar').css('display', 'none'); modal.css({ 'margin-top': -35, @@ -155,6 +164,7 @@ $(window).load(function() { } else { var data = { submitter: '/api/v1/user/'+currentUser.id+'/', + referer: $('#pin-form-referer').val(), description: $('#pin-form-description').val(), tags: cleanTags($('#pin-form-tags').val()) }; diff --git a/pinry/templates/includes/lightbox.html b/pinry/templates/includes/lightbox.html index ba7dd1e..dafdbec 100644 --- a/pinry/templates/includes/lightbox.html +++ b/pinry/templates/includes/lightbox.html @@ -24,8 +24,9 @@ {{/if}}
- Original URL - Pin URL + Referer + Original URL + Pin URL
diff --git a/pinry/templates/includes/pin_form.html b/pinry/templates/includes/pin_form.html index 21aaa7d..2e750de 100644 --- a/pinry/templates/includes/pin_form.html +++ b/pinry/templates/includes/pin_form.html @@ -17,6 +17,10 @@
+
+ + +