Commit be34e253 authored by Benoit Alessandroni's avatar Benoit Alessandroni

Merge branch 'feature/brokenlink' into 'master'

Feature/brokenlink

See merge request !63
parents c0a56160 3e0ef3f0
# -*- coding: utf-8 -*-
# Generated by Django 1.11.24 on 2019-10-11 09:47
# Generated by Django 1.11.24 on 2019-10-11 10:55
from __future__ import unicode_literals
from django.conf import settings
......@@ -15,11 +15,18 @@ class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('djangoldp_conversation', '0007_merge_20190918_1209'),
('djangoldp_like', '0001_initial'),
('djangoldp_conversation', '0007_merge_20190918_1209'),
]
operations = [
migrations.CreateModel(
name='BrokenLink',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('urlid', djangoldp.fields.LDPUrlField(blank=True, null=True, unique=True)),
],
),
migrations.CreateModel(
name='Country',
fields=[
......@@ -225,4 +232,14 @@ class Migration(migrations.Migration):
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='entrepreneur_profile', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='brokenlink',
name='resource',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='brokenlink_resource', to='coopstarter_data.Resource'),
),
migrations.AddField(
model_name='brokenlink',
name='submitter',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='brokenlink_submitter', to=settings.AUTH_USER_MODEL),
),
]
......@@ -64,6 +64,8 @@ class Type (Model):
def __str__(self):
return self.name
class Entrepreneur(Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name="entrepreneur_profile")
organisation = models.ForeignKey(Organisation, null=True, on_delete=models.CASCADE, related_name="entrepreneurs")
......@@ -219,6 +221,22 @@ class Request (Model):
def __str__(self):
return self.name
class BrokenLink(Model):
submitter = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="brokenlink_submitter")
resource = models.ForeignKey(Resource, null=True, on_delete=models.CASCADE, related_name="brokenlink_resource")
class Meta:
auto_author = 'submitter'
owner_field = 'submitter'
owner_perms = ['inherit', 'change', 'control', 'delete']
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
serializer_fields=["@id", "submitter", "resource"]
nested_fields=["submitter", "resource"]
container_path = 'brokenlinks/'
rdf_type = 'coopstarter:brokenlinks'
@receiver(post_save, sender=Resource)
def create_review(sender, instance, created, **kwargs):
if created:
......@@ -283,4 +301,23 @@ def update_review(sender, instance, created, **kwargs):
message,
resource.submitter.email,
[resource.submitter.email]
)
\ No newline at end of file
)
@receiver(post_save, sender=BrokenLink)
def sendMailToResourceSubmitter(sender, instance, created, **kwargs):
if created:
print(instance.resource.submitter.email)
message = loader.render_to_string(
'report_broken_link.txt',
{
'brokenlink': instance,
}
)
print(message)
send_mail(
'The resource you submitted has a brokenlink',
message,
instance.resource.submitter.email,
[instance.resource.submitter.email]
)
Hello {{brokenlink.resource.submitter.name}}
{{brokenlink.submitter.name|safe}} ({{brokenlink.submitter.email}}) is reporting you that the following resource you submit has a broken link :
Title: {{brokenlink.resource.name}}
Description: {{brokenlink.resource.description}}
URI: {{brokenlink.resource.uri}}
Have a nice day,
The Knowledge Base Team.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment