Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Futuria integrations w/ IPFS and Solana #34

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions portal/apps/comunidad/migrations/0004_auto_20221205_0014.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2022-12-05 00:14
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('comunidad', '0003_auto_20211203_1142'),
]

operations = [
migrations.AddField(
model_name='subscriberarticle',
name='ipfs_cid',
field=models.TextField(blank=True, help_text='CID de la nota en IPFS', null=True, verbose_name='id de IPFS'),
),
migrations.AddField(
model_name='subscriberarticle',
name='ipfs_upload',
field=models.BooleanField(default=True, verbose_name='Publicar en IPFS'),
),
migrations.AddField(
model_name='subscriberarticle',
name='solana_signature',
field=models.TextField(blank=True, help_text='Firma del autor en Solana', null=True, verbose_name='Firma de Solana'),
),
migrations.AddField(
model_name='subscriberarticle',
name='solana_signature_address',
field=models.TextField(blank=True, help_text='Wallet autora de la firma en Solana', null=True, verbose_name='Wallet de Solana'),
),
]
49 changes: 46 additions & 3 deletions portal/apps/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
from django.contrib.messages import constants as messages
from django.contrib.admin import ModelAdmin, TabularInline, site, widgets
from django.contrib.admin.options import get_ul_class
from django.forms import ModelForm, ValidationError, ChoiceField, RadioSelect, TypedChoiceField, Textarea
from django.forms import (
ModelForm, ValidationError, ChoiceField, RadioSelect, TypedChoiceField, Field, Textarea, Widget
)
from django.forms.models import BaseInlineFormSet, inlineformset_factory
from django.utils import timezone
from django.forms.fields import CharField, IntegerField
Expand All @@ -37,6 +39,9 @@
from django.utils.text import Truncator
from django.utils.translation import ugettext as _

from django.template import loader
from django.utils.safestring import mark_safe

from core.templatetags.ldml import ldmarkup, cleanhtml

from .models import (
Expand Down Expand Up @@ -284,8 +289,45 @@ class ArticleEditionInline(TabularInline):
extra = 1


class SolanaSignatureWidget(Widget):
template_name = 'admin/core/article/solana_signature.html'

def __init__(self, *args, **kwargs):
kwargs['attrs'] = {'readonly': True}
super(SolanaSignatureWidget, self).__init__(*args, **kwargs)

def get_context(self, name, value, attrs=None):
return {'widget': {
'name': name,
'value': value,
}}

def render(self, name, value, attrs=None):
context = self.get_context(name, value, attrs)
template = loader.get_template(self.template_name).render(context)
return mark_safe(template)

class SolanaSignatureField(Field):
def __init__(self, field, *args, **kwargs):
self.field = field
kwargs["widget"] = SolanaSignatureWidget

super(SolanaSignatureField, self).__init__(*args, **kwargs)

def clean(self, value):
return value

class ArticleAdminModelForm(ModelForm):
body = CharField(widget=MarkdownWidget())
solana_signature_address = SolanaSignatureField(
"Firma con Solana",
label='Firma con Solana',
required=False,
help_text=(
'Podés firmar esta nota con Solana desde tu wallet. '
'<a href="https://solana.com/" target="_blank">¿Qué es Solana?</a>'
),
)
headline = CharField(label='Título', widget=TextInput(attrs={'style': 'width:600px'}))
slug = CharField(
label='Slug',
Expand Down Expand Up @@ -384,7 +426,7 @@ class ArticleAdmin(ModelAdmin):
date_hierarchy = 'date_published'
ordering = ('-date_created', )
raw_id_fields = ('photo', 'gallery', 'main_section')
readonly_fields = ('date_published', )
readonly_fields = ('date_published', 'solana_signature')
inlines = article_optional_inlines + [ArticleExtensionInline, ArticleBodyImageInline, ArticleEditionInline]

def creation_date(self, obj):
Expand All @@ -410,7 +452,7 @@ def publication_date(self, obj):
}
),
('Metadatos', {'fields': ('date_published', 'tags', 'main_section')}),
('Autor', {'fields': ('byline', 'only_initials', 'location'), 'classes': ('collapse', )}),
('Autor', {'fields': ('byline', 'only_initials', 'location', 'solana_signature_address'), 'classes': ('collapse', )}),
('Multimedia', {'fields': ('photo', 'gallery', 'video', 'youtube_video', 'audio'), 'classes': ('collapse', )}),
(
'Avanzado',
Expand All @@ -423,6 +465,7 @@ def publication_date(self, obj):
'allow_related',
'show_related_articles',
'newsletter_featured',
'ipfs_upload',
),
'additional_access',
('latitude', 'longitude'),
Expand Down
35 changes: 35 additions & 0 deletions portal/apps/core/migrations/0029_auto_20221204_2346.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2022-12-04 23:46
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0028_auto_20221017_1335'),
]

operations = [
migrations.AddField(
model_name='article',
name='ipfs_cid',
field=models.TextField(blank=True, help_text='CID de la nota en IPFS', null=True, verbose_name='id de IPFS'),
),
migrations.AddField(
model_name='article',
name='ipfs_upload',
field=models.BooleanField(default=True, verbose_name='Publicar en IPFS'),
),
migrations.AddField(
model_name='article',
name='solana_signature',
field=models.TextField(blank=True, help_text='Firma del autor en Solana', null=True, verbose_name='Firma de Solana'),
),
migrations.AddField(
model_name='article',
name='solana_signature_address',
field=models.TextField(blank=True, help_text='Wallet autora de la firma en Solana', null=True, verbose_name='Wallet de Solana'),
),
]
39 changes: 39 additions & 0 deletions portal/apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from tagging.fields import TagField
from tagging.models import Tag
from videologue.models import Video, YouTubeVideo
import w3storage

from .managers import PublishedArticleManager
from .utils import (
Expand Down Expand Up @@ -975,6 +976,24 @@ class ArticleBase(Model, CT):
last_modified = DateTimeField('última actualización', auto_now=True)
views = PositiveIntegerField('vistas', default=0, db_index=True)
allow_comments = BooleanField('Habilitar comentarios', default=True)
ipfs_upload = BooleanField('Publicar en IPFS', default=True)
ipfs_cid = TextField('id de IPFS',
blank=True,
null=True,
help_text='CID de la nota en IPFS',
)
solana_signature = TextField(
'Firma de Solana',
blank=True,
null=True,
help_text='Firma del autor en Solana',
)
solana_signature_address = TextField(
'Wallet de Solana',
blank=True,
null=True,
help_text='Wallet autora de la firma en Solana',
)
created_by = ForeignKey(
User,
verbose_name='creado por',
Expand Down Expand Up @@ -1028,6 +1047,26 @@ def save(self, *args, **kwargs):

now = datetime.now()

if self.solana_signature_address:
# since we have only one field for the signature, we split it and the first part is the signature and the second part is the address
splitted = self.solana_signature_address.split(";")
self.solana_signature = splitted[0]
self.solana_signature_address = splitted[1]
else:
self.solana_signature = None

if self.ipfs_upload:
content = self.headline + '\n \n' + self.body
if (self.ipfs_cid):
content = "Nota editada. Versión anterior de la nota en: https://ipfs.io/ipfs/" + self.ipfs_cid + "\n \n \n" + self.body
if (self.solana_signature):
content += "\n \n" + "Dirección del autor: " + self.solana_signature_address + "\n" + "Firma del autor: " + self.solana_signature
w3 = w3storage.API(token=settings.IPFS_TOKEN)
cid = w3.post_upload((self.slug, content))
self.ipfs_cid = cid
else:
self.ipfs_cid = None

if self.is_published:
if not self.date_published:
self.date_published = now
Expand Down
67 changes: 52 additions & 15 deletions portal/apps/core/templates/article/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

{% if article.photo %}
{% if header_display == 'FW' %}
<div>{# closed in line 243 #}
<div>{# closed in line 255 #}
<div class="fullwidth-container">
<div class="main-photo">
<div>
Expand Down Expand Up @@ -107,7 +107,7 @@
</div>
</div>
</div>
{# missing close div here is closed correctly in line 243 #}
{# missing close div here is closed correctly in line 255 #}
{% else %}
<div class="container-photo photo {{ card_size|default:'BG' }} {{ article.photo_layout }}">
<figure class="principal">
Expand Down Expand Up @@ -225,9 +225,34 @@ <h1 class="article-title after_foto">{{ article.headline|ldmarkup:article.id|ble
</div>
</div>
{% endif %}
{% if article.ipfs_upload and article.ipfs_cid %}
<div class="read-later top">
<a class="read-later__btn open-ipfs">
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="195" height="195" viewBox="0 0 195 195" version="1.1" id="svg23" sodipodi:docname="rust-ipfs-logo.svg" inkscape:version="0.92.3 (2405546, 2018-03-11)">
<g xmlns="http://www.w3.org/2000/svg" id="IPFS-logo-(new)" style="fill-rule:nonzero">
<polygon id="Path" points="84.3,194.5 168.3,146 168.3,49 84.3,0.5 0.3,49 0.3,146 " style="fill:#262626"/>
<path d="m 75.7,12.1 -61,35.2 c 0.09999,1.097728 0.09999,2.202272 0,3.3 l 60.9,35.2 c 5.140467,-3.80057 12.159533,-3.80057 17.3,0 l 60.9,-35.2 c -0.1,-1.097728 -0.1,-2.202272 0,-3.3 L 93,12.1 c -5.140467,3.80057 -12.159533,3.80057 -17.3,0 z m 84,48.2 -61,35.6 c 0.678108,6.33353 -2.791626,12.38539 -8.6,15 l 0.1,70 c 0.986199,0.43498 1.924564,0.97119 2.8,1.6 l 60.9,-35.2 c -0.67811,-6.33353 2.79163,-12.38539 8.6,-15 V 61.9 c -0.97488,-0.457093 -1.91126,-0.992166 -2.8,-1.6 z M 8.9,60.7 c -0.8754357,0.628814 -1.813801,1.165022 -2.8,1.6 v 70.4 c 5.888216,2.52578 9.395106,8.64245 8.6,15 l 60.9,35.2 c 0.875436,-0.62881 1.813801,-1.16502 2.8,-1.6 v -70.4 c -5.888215,-2.52578 -9.395106,-8.64245 -8.6,-15 z" id="Shape" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" inkscape:connector-curvature="0" style="fill:#fff"/>
<path d="m 84.3,11 75.1,43.4 v 86.7 L 84.3,184.5 9.2,141.1 V 54.3 L 84.3,11 m 0,-10.3 -84,48.5 v 97 l 84,48.5 84,-48.5 v -97 z" id="path8" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" inkscape:connector-curvature="0" style="fill:#262626"/>
<polygon id="polygon12" points="84.3,98.1 0.3,49.6 0.3,146.7 84.3,195.2 " style="fill:#083b54;fill-opacity:0.15"/>
<polygon id="polygon14" points="168.4,48.8 84.4,97.3 84.4,194.4 168.4,145.8 " style="fill:#083b54;fill-opacity:0.05"/>
</g>
</svg> Ver en IPFS
</a>
</div>
{% endif %}
{% if article.solana_signature %}
<div class="solana-signature read-later top">
<p>
Este artículo fue firmado en Solana por el autor
<span class="show-solana-info">Mostrar info</span>
</p>
<p class="solana-info hide">
Firma: {{ article.solana_signature }}<br>Dirección: {{ article.solana_signature_address }}</p>
</div>
{% endif %}
{% endif %}
</div>
{% if article.photo and header_display == 'FW' %}</div>{# opened in line 86 #}{% endif %}
{% if article.photo and header_display == 'FW' %}</div>{# opened in line 79 #}{% endif %}

{% if article.has_deck or article.has_lead %}
{% if article.has_deck %}
Expand Down Expand Up @@ -269,23 +294,27 @@ <h2 class="article-deck article__deck">{{ article.deck|ldmarkup:article.id|bleac
{% if not request.signupwall %}
{# Soft wall: Suscripción #}
{% if not article.public %}
{% include 'article/paywall/pw_auth_with_credits.html' %}
{% if not user|has_bought_article:article %}
{% include 'article/paywall/pw_auth_with_credits.html' %}
{% endif %}
{% endif %}
{% else %}{# signupwall raised #}
{# Hard wall -> Suscripción #}
<!-- Hard wall / suscripción-->
<div class="article-body article-body--faded">
{{ article.body|ldmarkup:article.id|truncatehtml:100 }}
</div>
{% include 'article/paywall/pw_auth_wo_credits.html' %}
{% if not user|has_bought_article:article %}
<!-- Hard wall / suscripción-->
<div class="article-body article-body--faded">
{{ article.body|ldmarkup:article.id|truncatehtml:100 }}
</div>
{% include 'article/paywall/pw_auth_wo_credits.html' %}
{% endif %}
{% endif %}
{% endif %}

{% endif %}

{# END signupwall #}

{% if not request.signupwall %}{# closed in line 550 #}
{% if not request.signupwall or user|has_bought_article:article %}{# closed in line 566 #}

<div class="article-body paywalled-content">
{% block article_body_content %}{{ article.body|ldmarkup:article.id }}{% endblock %}
Expand Down Expand Up @@ -533,7 +562,7 @@ <h2 class="article-deck article__deck">{{ article.deck|ldmarkup:article.id|bleac
</div>
{% endif %}

{% endif %}{# opened in line 301 #}
{% endif %}{# opened in line 318 #}

{% else %}{# restricted content message #}

Expand All @@ -550,7 +579,7 @@ <h2 class="article-deck article__deck">{{ article.deck|ldmarkup:article.id|bleac

<aside>

{% if not request.signupwall %}{# closed in line 694 #}
{% if not request.signupwall %}{# closed in line 710 #}

{% if article.public %}

Expand All @@ -566,7 +595,7 @@ <h2 class="article-deck article__deck">{{ article.deck|ldmarkup:article.id|bleac

{% endif %}

{% if not article.is_restricted or user|has_restricted_access:article %}{# begin restricted content2 #}
{% if not article.is_restricted or user|has_restricted_access:article or user|has_bought_article:article %}{# begin restricted content2 #}

{% if TALK_URL and article.allow_comments %}
<div id="comentarios">
Expand Down Expand Up @@ -677,11 +706,11 @@ <h2 class="article-deck article__deck">{{ article.deck|ldmarkup:article.id|bleac

{% endif %}{# end restricted content2 #}

{% endif %}{# opened in line 567 #}
{% endif %}{# opened in line 583 #}

{% block article_extra %}{% endblock %}

{% if not request.signupwall or article.is_restricted and not user|has_restricted_access:article %}
{% if not request.signupwall or article.is_restricted and not user|has_restricted_access:article or user|has_bought_article:article %}
<div class="align-center u-mb-50 footer-section">
<a href="{% url 'home' %}" class="ut-btn ut-btn-outline">Ir a la portada</a>
</div>
Expand Down Expand Up @@ -781,6 +810,14 @@ <h2 class="article-deck article__deck">{{ article.deck|ldmarkup:article.id|bleac
{% endif %}
});

$('a.open-ipfs').click(function(){
window.open('https://ipfs.io/ipfs/{{ article.ipfs_cid }}', 'Ver en IPFS');
});

$('span.show-solana-info').click(function(){
$('.solana-info').toggleClass('hide');
});

$('a.read-later__saved').click(function(){
{% if user.is_authenticated %}
$.get("{% url 'actstream_unfollow' content_type_id=article_ct_id object_id=article.id %}", function(data){
Expand Down
Loading