Commit 85f929e3 authored by Benoit Alessandroni's avatar Benoit Alessandroni

Merge branch 'feature/add-visibility' into 'master'

Feature/add visibility

See merge request !77
parents f845a974 c1a82033
[
{
"model": "coopstarter_data.sharingcriteria",
"pk": 1,
"fields": {
"value": "private",
"name": "Private"
}
},
{
"model": "coopstarter_data.sharingcriteria",
"pk": 2,
"fields": {
"value": "organisation",
"name": "Organisation"
}
},
{
"model": "coopstarter_data.sharingcriteria",
"pk": 3,
"fields": {
"value": "public",
"name": "Public"
}
}
]
\ No newline at end of file
[
{
"model": "coopstarter_data.target",
"pk": 1,
"fields": {
"value": "mentor",
"name": "Mentor"
}
},
{
"model": "coopstarter_data.target",
"pk": 2,
"fields": {
"value": "entrepreneur",
"name": "Entrepreneur"
}
},
{
"model": "coopstarter_data.target",
"pk": 3,
"fields": {
"value": "public",
"name": "Public"
}
}
]
\ No newline at end of file
# -*- coding: utf-8 -*-
# Generated by Django 1.11.27 on 2020-01-28 09:45
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import djangoldp.fields
class Migration(migrations.Migration):
dependencies = [
('coopstarter_data', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='SharingCriteria',
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)),
('name', models.CharField(max_length=128, verbose_name='name')),
('value', models.CharField(blank=True, max_length=128, null=True, verbose_name='value')),
],
options={
'abstract': False,
'default_permissions': ('add', 'change', 'delete', 'view', 'control'),
},
),
migrations.CreateModel(
name='Target',
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)),
('name', models.CharField(max_length=128, verbose_name='name')),
('value', models.CharField(blank=True, max_length=128, null=True, verbose_name='value')),
],
options={
'abstract': False,
'default_permissions': ('add', 'change', 'delete', 'view', 'control'),
},
),
migrations.RemoveField(
model_name='request',
name='target',
),
migrations.AlterField(
model_name='resource',
name='sharing',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='coopstarter_data.SharingCriteria', verbose_name='Sharing profile'),
),
migrations.AlterField(
model_name='resource',
name='target',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='coopstarter_data.Target', verbose_name='Target audience'),
),
]
......@@ -64,6 +64,19 @@ class Type (Model):
def __str__(self):
return self.name
class Target (Model):
name = models.CharField(max_length=128, verbose_name="name")
value = models.CharField(max_length=128, verbose_name="value", blank=True, null=True)
def __str__(self):
return self.name
class SharingCriteria (Model):
name = models.CharField(max_length=128, verbose_name="name")
value = models.CharField(max_length=128, verbose_name="value", blank=True, null=True)
def __str__(self):
return self.name
class Entrepreneur(Model):
......@@ -155,11 +168,11 @@ class Resource (Model):
preview_image = models.URLField(blank=True, null=True)
# Classification Fields
target = models.CharField(max_length=32, choices=(('mentor', 'Mentor'), ('entrepreneur', 'Entrepreneur'), ('public', 'Public')), verbose_name="Target audience", blank=True, null=True)
target = models.ForeignKey(Target, verbose_name="Target audience", blank=True, null=True)
type = models.ForeignKey(Type, blank=True, verbose_name="Type of content", related_name='resources')
sharing = models.ForeignKey(SharingCriteria, blank=True, null=True, verbose_name="Sharing profile")
steps = models.ManyToManyField(Step, blank=True, related_name="resources")
sharing = models.CharField(max_length=32, choices=(('private', 'Private (nobody)'), ('public', 'Public (everybody)')), verbose_name="Sharing profile", blank=True, null=True)
# Relations to other models
submitter = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE, related_name='resources')
......@@ -194,10 +207,9 @@ class Request (Model):
language = models.ForeignKey(Language, blank=True, verbose_name="Language")
fields = models.ManyToManyField(Field, blank=True)
country = models.ForeignKey(Country, null=True)
organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE, related_name="requests")
skills = models.TextField(verbose_name="Learning outcomes/skills")
target = models.CharField(max_length=32, choices=(('mentor', 'Mentor'), ('entrepreneur', 'Entrepreneur'), ('public', 'Public')), verbose_name="Target audience", blank=True, null=True)
submitter = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE, related_name='requests')
reviewer = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE, related_name='reviewed_requests')
......@@ -211,7 +223,7 @@ class Request (Model):
authenticated_perms = ['inherit', 'add', 'change']
owner_field = 'submitter'
serializer_fields=["@id", "name", "description", "skills", "fields", "language",\
"organisation", "submitter", "reviewer", "created_on", "target", "country", "status"]
"organisation", "submitter", "reviewer", "created_on", "country", "status"]
owner_perms = ['inherit', 'change', 'control', 'delete']
nested_fields=["language", "fields", "organisation", "submitter", "country"]
container_path = 'requests/'
......
......@@ -7,8 +7,15 @@ class ValidatedResourcesByStepViewSet(LDPViewSet):
def get_queryset(self, *args, **kwargs):
step_id = self.kwargs['id']
if self.request.user.mentor_profile:
target='mentor'
elif self.request.user.entrepreneur_profile:
target='entrepreneur'
else:
target='public'
return super().get_queryset(*args, **kwargs)\
.filter(steps__in=step_id, review__status='validated')\
.filter(steps__in=step_id, review__status='validated', target__value=target)\
.exclude(submitter__username=self.request.user.username)
class PendingResourcesViewSet(LDPViewSet):
......
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