Commit f3e4f9e2 authored by Benoit Alessandroni's avatar Benoit Alessandroni

Adding some stuff

parent 809ec8e1
"""djangoldp project URL Configuration"""
from django.conf.urls import url
from .views import PendingResourcesViewSet
urlpatterns = [
url(r'^resources/pending/', PendingResourcesViewSet.urls(model_prefix="resources-pending")),
]
\ No newline at end of file
......@@ -5,13 +5,9 @@ from django_countries.fields import CountryField
from django.contrib.auth import get_user_model
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.sites.models import Site
from djangoldp_conversation.models import Conversation, Message
from djangoldp_like.models import Like
# from registration.models import RegistrationManager
# from registration.models import RegistrationProfile
# from pprint import pprint
class Language (Model):
code = models.CharField(max_length=2, verbose_name="ISO Code")
......@@ -27,11 +23,41 @@ class Organisation (Model):
def __str__(self):
return self.name
class Step (Model):
name = models.CharField(max_length=128, verbose_name="Name")
order = models.IntegerField(verbose_name="Order", blank=True, null=True, default=0)
def __str__(self):
return self.name
class Format (Model):
name = models.CharField(max_length=128, verbose_name="Title")
def __str__(self):
return self.name
class Field (Model):
name = models.CharField(max_length=128, verbose_name="Title")
def __str__(self):
return self.name
class Type (Model):
name = models.CharField(max_length=128, verbose_name="Title")
def __str__(self):
return self.name
class Entrepreneur(Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name="entrepreneur_profile")
organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE)
class Meta:
auto_author = 'user'
owner_field = 'user'
owner_perms = ['inherit', 'change', 'control', 'delete']
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
serializer_fields=["@id"]
nested_fields=["user", "organisation"]
container_path = 'entrepreneurs/'
......@@ -45,7 +71,7 @@ class Mentor(Model):
phone = models.CharField(max_length=25, null=True, blank=True, verbose_name='Phone number')
organisation = models.ForeignKey(Organisation, null=True, on_delete=models.CASCADE)
country = CountryField(blank=True)
language = models.ForeignKey(Language, blank=True, null=True)
languages = models.ManyToManyField(Language, blank=True)
profile = models.ImageField(upload_to="mentors", blank=True, verbose_name="Profile picture")
headline = models.CharField(max_length=256, blank=True, verbose_name='Headline or current position')
......@@ -54,45 +80,25 @@ class Mentor(Model):
biography = models.TextField(blank=True, verbose_name="Tell us more about your activities")
skills = models.TextField(blank=True, verbose_name="What skills can you share with our entrepreneurs ?")
fields = models.ManyToManyField(Field, blank=True)
linkedin = models.CharField(max_length=256, blank=True, verbose_name='Linkedin account')
twitter = models.CharField(max_length=256, blank=True, verbose_name='Twitter account')
class Meta:
auto_author = 'user'
serializer_fields=["@id", "phone", "headline", "biography", "skills", "linkedin", "twitter"]
nested_fields=["user", "organisation"]
container_path = 'mentors/'
rdf_type = 'coopstarter:mentor'
owner_field = 'user'
owner_perms = ['inherit', 'change', 'control', 'delete']
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
def __str__(self):
return self.user.get_full_name()
class Step (Model):
name = models.CharField(max_length=128, verbose_name="Name")
order = models.IntegerField(verbose_name="Order", blank=True, null=True, default=0)
def __str__(self):
return self.name
class Format (Model):
name = models.CharField(max_length=128, verbose_name="Title")
def __str__(self):
return self.name
class Field (Model):
name = models.CharField(max_length=128, verbose_name="Title")
def __str__(self):
return self.name
class Type (Model):
name = models.CharField(max_length=128, verbose_name="Title")
def __str__(self):
return self.name
class Resource (Model):
# Mandatory Fields
name = models.CharField(max_length=32, verbose_name="Title")
......@@ -100,7 +106,7 @@ class Resource (Model):
format = models.ManyToManyField(Format, blank=True)
publication_year = models.IntegerField(verbose_name="Publication Year")
language = models.ForeignKey(Language, blank=True, verbose_name="Language")
field = models.ManyToManyField(Field, blank=True)
fields = models.ManyToManyField(Field, blank=True)
country = CountryField(verbose_name="Country of publication", blank=True)
uri = models.CharField(max_length=4086, verbose_name="Location/weblink")
author = models.CharField(max_length=32, verbose_name="Author")
......@@ -128,7 +134,7 @@ class Resource (Model):
class Meta:
owner_field = 'submitter'
owner_perms = ['inherit', 'change', 'control', 'delete']
nested_fields=["format", "conversations", "steps", "language", "field", "type", "submitter", "related", "likes"]
nested_fields=["format", "conversations", "steps", "language", "fields", "type", "submitter", "related", "likes"]
container_path = 'resources/'
rdf_type = 'coopstarter:resource'
anonymous_perms = ['view']
......@@ -178,11 +184,4 @@ class Review (Model):
owner_perms = ['inherit', 'change', 'control', 'delete']
def __str__(self):
return self.comment
@receiver(post_save, sender=Resource)
def create_review(sender, instance, created, **kwargs):
if created:
# instance.objects.create(submitter=sender)
instance.reviews.objects.create()
# Review.objects.create(reviewer=instance.submitter, resource=instance, status='pending')
\ No newline at end of file
return self.comment
\ No newline at end of file
from djangoldp.views import LDPViewSet
from .models import Resource
class PendingResourcesViewSet(LDPViewSet):
model = Resource
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs)\
.filter(reviews=None, language__in=self.request.user.mentor_profile.languages.all(), fields__in=self.request.user.mentor_profile.fields.all())\
.exclude(submitter=self.request.user)
\ 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