Skip to content

Commit

Permalink
Merge pull request #24 from hacklabr/develop
Browse files Browse the repository at this point in the history
Fix: Solve issue #179 'formadores' cannot view activity files
  • Loading branch information
frclba authored Jul 3, 2020
2 parents 35a2d0a + deb1ff1 commit b6f0efa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
46 changes: 22 additions & 24 deletions discussion/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
TopicNotification, TopicLike, TopicRead,
CommentLike, TopicFile, CommentFile, ContentFile)


class BaseUserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()
Expand Down Expand Up @@ -33,29 +32,6 @@ class Meta:
fields = '__all__'


class BaseTopicSerializer(serializers.ModelSerializer):

read = serializers.SerializerMethodField()
author = BaseUserSerializer(read_only=True)

class Meta:
model = Topic
fields = ('id', 'created_at', 'updated_at', 'is_hidden', 'slug', 'title', 'content', 'is_public', 'author',
'hidden_by', 'tags', 'categories', 'comments', 'count_likes', 'count_uses', 'count_replies', 'last_activity_at',
'forum', 'read')
depth = 1

def get_read(self, obj):
request = self.context.get("request")
# If there is a TopicRead instance, return the content of "is_read" field
try:
topic_read = TopicRead.objects.get(topic=obj, user=request.user)
return topic_read.is_read
except TopicRead.DoesNotExist:
# If there is no instance, the topic is not read yet
return False


class BaseForumSerializer(serializers.ModelSerializer):

class Meta:
Expand Down Expand Up @@ -315,6 +291,28 @@ def get_read(self, obj):
# If there is no instance, the topic is not read yet
return False

class BaseTopicSerializer(serializers.ModelSerializer):

read = serializers.SerializerMethodField()
author = BaseUserSerializer(read_only=True)
files = TopicFileSerializer(many=True, read_only=True)

class Meta:
model = Topic
fields = ('id', 'created_at', 'updated_at', 'is_hidden', 'slug', 'title', 'content', 'is_public', 'author',
'files', 'hidden_by', 'tags', 'categories', 'comments', 'count_likes', 'count_uses', 'count_replies', 'last_activity_at',
'forum', 'read')
depth = 1

def get_read(self, obj):
request = self.context.get("request")
# If there is a TopicRead instance, return the content of "is_read" field
try:
topic_read = TopicRead.objects.get(topic=obj, user=request.user)
return topic_read.is_read
except TopicRead.DoesNotExist:
# If there is no instance, the topic is not read yet
return False

class TopicLikeSerializer(serializers.ModelSerializer):

Expand Down
4 changes: 2 additions & 2 deletions discussion/static/js/discussion-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
$scope.topics = {}
$scope.search = {txt:""}
// Pagination Params
$scope.forum_pages_max_number = 10;
$scope.forum_pages_max_number = 20;
$scope.forum_topics_page = 20;
$scope.forum.page_size = 10;
$scope.forum.page_size = 20;
$scope.forum.current_page = 1

if(forum_id) {
Expand Down

0 comments on commit b6f0efa

Please sign in to comment.