Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
merge new design from design into group branch
Browse files Browse the repository at this point in the history
  • Loading branch information
somnus0x committed Oct 19, 2015
2 parents aa0ad49 + fdb0ec3 commit 4a86c9b
Show file tree
Hide file tree
Showing 20 changed files with 496 additions and 43 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: python
python:
- '2.7'
services:
- mysql
before_script:
- mysql -e 'CREATE DATABASE social_test;'
install: pip install -r requirements.txt
script:
- python manage.py migrate --noinput
sudo: false
after_success:
- openssl aes-256-cbc -K $encrypted_aa5263036386_key -iv $encrypted_aa5263036386_iv
-in .travis/ssh_key.enc -out .travis/deploy -d
- echo "madoka.whs.in.th,103.246.18.42 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDN717hGRfIpN9psGG9q8VXuyVE6w8H1Fa0BqkHOBGJFgAq2uV0/bdYNOpvG27ngLDOmOmNLpdlIYQiI56E+qUPUBxLH3fvhVQVKItP5MRlc97an98Ozg+bOl3SjdUWgFeHIRHwu6UllZUL8U6pjJS/GZsumzwwwTOnLRutYWegxeHjW2DU5Q2BkCU5z/3b+7gFu4s9gRFZ57En/GG2aZYrKBGgoUvjEAOL3B+/nCm1ZTlV2IdKA9gpF/7SyZIozKHXXUA/Xw27aOxebFL2VHO7YtgvkNoiJ5uc6ZQuRB9VPmNKBSYH5fwSICtSHTGlCKLOUd91SBG8JRm/fXES24jn"
> $HOME/.ssh/known_hosts
- chmod 600 .travis/deploy $HOME/.ssh/known_hosts
- test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && ssh -i
.travis/deploy [email protected] social/deploy.sh
1 change: 1 addition & 0 deletions .travis/ssh_key.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$s@��c�1�������W��6� ��`�EM.���k�x�!�-����S��c 3 �:��y襘�U"eQ��-1�l�zG�c}x,�� �����)�ډ��0�ZT�S����:&����;�+���Q.@攎&����:^���0���m��Z�L������#@ύ������dڋB0^t���Ɗ�ţ�d��l�&�xFG��7���MbU��)W$�k wi8��&�H�;>�
1 change: 1 addition & 0 deletions group/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class Meta:

class GroupSerializer(serializers.ModelSerializer):
class Meta:
app_label = "social_group"
model = Group
fields = ('name', 'description', 'short_description', 'activities', 'type')
2 changes: 2 additions & 0 deletions group/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
url(r'^all/$', views.GroupViewSet.as_view(), name='LookForGroup'),
url(r'^(?P<group_id>[0-9]+)/edit/$', views.EditInfo.as_view(), name='EditInfo'),
url(r'^category/(?P<cat>[a-zA-Z]+)/$', views.GroupByCategory.as_view(), name='GroupByCategory'),
url(r'^(?P<group_id>[0-9]+)/post/$', views.GroupPostView.as_view(), name='PostDetail'),

]
36 changes: 35 additions & 1 deletion group/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from rest_framework.exceptions import NotAuthenticated
from rest_framework.exceptions import NotFound
from rest_framework.views import APIView
from django.contrib.contenttypes.models import ContentType
from newsfeed.models import Post
from newsfeed.models import Comment
from newsfeed.serializer import GroupPostSerializer
from newsfeed.serializer import CommentSerializer
from models import *
from serializers import *
from django.http import Http404
Expand Down Expand Up @@ -45,18 +50,23 @@ def create(self, *args, **kwargs):

return Response(GroupMemberSerializer(member).data)


class PendingMemberViewSet(ListCreateAPIView):
serializer_class = GroupMemberSerializer

def get_queryset(self):
this_group = Group.objects.get(id=int(self.kwargs['group_id']))
return GroupMember.objects.filter(group=this_group, role=0)


class AcceptedMemberViewSet(ListCreateAPIView):
serializer_class = GroupMemberSerializer

def get_queryset(self):
this_group = Group.objects.get(id=int(self.kwargs['group_id']))
return GroupMember.objects.filter(group=this_group, role=1)


class GroupViewSet(APIView):
serializer_class = GroupSerializer

Expand All @@ -75,6 +85,7 @@ def post(self, request, format=None):
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class GroupViewDetail(APIView):
serializer_class = GroupSerializer

Expand All @@ -98,6 +109,7 @@ def post(self, request, group_id, format=None):
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class MemberDetail(APIView):
serializer_class = GroupMemberSerializer

Expand All @@ -124,6 +136,7 @@ def get(self, request, group_id, pk, format=None):
return Response(response.data)



class EditInfo(APIView):
serializer_class = GroupSerializer

Expand All @@ -146,4 +159,25 @@ class GroupByCategory(APIView):
def get(self, request, cat, format=None):
group = Group.objects.filter(category=cat)
response = self.serializer_class(group, many=True)
return Response(response.data)
return Response(response.data)


class GroupPostView(APIView):
serializer_class = GroupPostSerializer
group_model_id = 15

def get(self, request, group_id, format=None):
post = Post.objects.filter(target_id=group_id, target_type=self.group_model_id).order_by('-datetime')
response = self.serializer_class(post, many=True)
return Response(response.data)

def post(self, request, group_id, format=None):
serializer = GroupPostSerializer(data=request.data)

if serializer.is_valid():

if self.request.user.is_authenticated():
serializer.save(user=User.objects.get(id=self.request.user.id), target_id=group_id, target_type=ContentType.objects.get(id=self.group_model_id))
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

7 changes: 7 additions & 0 deletions newsfeed/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.humanize.templatetags.humanize import naturaltime


class Post(models.Model):
Expand All @@ -12,6 +13,9 @@ class Post(models.Model):
target_id = models.PositiveIntegerField()
target_object = GenericForeignKey('target_type', 'target_id')

def FORMAT(self):
return naturaltime(self.datetime)

def __unicode__(self):
return "{}'s newsfeed (id={})".format(self.user.username, self.id)

Expand All @@ -22,5 +26,8 @@ class Comment(models.Model):
text = models.CharField(max_length=2000)
datetime = models.DateTimeField(auto_now_add=True)

def FORMAT(self):
return naturaltime(self.datetime)

def __unicode__(self):
return "{}'s comment (id={})".format(self.user.username, self.id)
21 changes: 19 additions & 2 deletions newsfeed/serializer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.auth.models import User

from rest_framework import serializers
from rest_framework.serializers import ModelSerializer
from newsfeed.models import Post, Comment

Expand All @@ -12,16 +13,32 @@ class Meta:

class PostSerializer(ModelSerializer):
user = UserSerializer(read_only=True)
datetime = serializers.ReadOnlyField(source='FORMAT')

class Meta:
model = Post
fields = ('id', 'user', 'text', 'datetime',
'target_type', 'target_id', 'target_object')
'target_type', 'target_id')
#'target_type', 'target_id', 'target_object')


class CommentSerializer(ModelSerializer):
class GroupPostSerializer(ModelSerializer):
group_model_id = 15
user = UserSerializer(read_only=True)
target_type = serializers.HiddenField(default=group_model_id)
target_id = serializers.HiddenField(default=0)
datetime = serializers.ReadOnlyField(source='FORMAT')

class Meta:
model = Post
fields = ('id', 'user', 'text', 'datetime',
'target_type', 'target_id')


class CommentSerializer(ModelSerializer):
user = UserSerializer(read_only=True)
datetime = serializers.ReadOnlyField(source='FORMAT')

class Meta:
model = Comment
fields = ('id', 'post', 'user', 'text', 'datetime')
4 changes: 2 additions & 2 deletions newsfeed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class PostViewList(APIView):
serializer_class = PostSerializer

def get(self, request, id=None, format=None):
post = Post.objects.all()
post = Post.objects.order_by('-datetime')
response = self.serializer_class(post, many=True)

return Response(response.data)

def post(self, request, format=None):
serializer = PostSerializer(data=request.data)

Expand Down
72 changes: 71 additions & 1 deletion ui/static/app/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,74 @@ app.controller('GroupController', function($scope, $stateParams, Restangular, $h
});
});


app.controller('GroupFeedController', function($scope, $http, $location){
$scope.allowPost = true;
$scope.newsfeed = null;
$scope.nftext ="";
var groupID = $location.path().split('/')[2];
$http.get('/api/group/'+groupID+'/post').success(function(data){
$scope.newsfeed = data;
});

$scope.postStatus = function() {
postData = {
text : $scope.nftext,
};

if (postData.text.length > 0) {
$http.post('/api/group/'+groupID+'/post/', postData).then(function(response){
console.log(response);
$scope.nftext="";
$scope.newsfeed.unshift(response.data);
}, function(xhr){
alert(xhr.data);
console.log(xhr.data);
});
}
};

});



app.controller('GroupCommentController', function($rootScope, $scope, $http){

var loadCommentsByPostId = function(postID) {
$http.get('/api/newsfeed/post/'+postID+'/comment/').success(function(commentsData){
$scope.comments = commentsData;
});
};

loadCommentsByPostId($scope.data.id);
$scope.comments = null;

$scope.commentPost = function(postData) {
commentData = {
text : $scope.comment,
post : postData.id,
datetime : 'Just now',
user : {
username : $rootScope.user,
},
};

if (commentData.text.length > 0) {
$scope.comments.push(commentData);
$scope.comment = "";
$http.post('/api/newsfeed/comment/', commentData).then(function(response){
console.log(response);
loadCommentsByPostId($scope.data.id);
}, function(xhr){
alert(xhr.data);
console.log(xhr.data);
});
}
};

});


app.controller('GroupInfoController', function($scope, $http, $location){
var groupID = $location.path().split('/')[2];
$http.get('/api/group/'+groupID).success(function(data){
Expand Down Expand Up @@ -54,6 +122,7 @@ app.controller('GroupManageController', function($scope, $http, $location){
$scope.acceptMember = acceptMember;
$scope.denyMember = denyMember;


$http.get('/api/group/'+groupID).then(function(data){
$scope.group = data.data;
});
Expand All @@ -73,4 +142,5 @@ app.controller('GroupCategoryController', function($scope, $http, $stateParams){

});

})();
})();

43 changes: 34 additions & 9 deletions ui/static/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('root', {
templateUrl: 'templates/root.html',
controller: 'MainAuthController'
controller: 'MainController',
resolve: {
user: function(Restangular){
return Restangular.one('auth/check').get().then(function(user){
return user;
}, function(error){
return null;
});
}
},
})
.state('root.newsfeed', {
url: '/',
Expand All @@ -39,6 +48,11 @@ app.config(function($stateProvider, $urlRouterProvider) {
templateUrl: 'templates/groupinfo.html',
controller: 'GroupInfoController'
})
.state('root.group.feed', {
url: '/feed',
templateUrl: 'templates/groupfeed.html',
controller: 'GroupFeedController'
})
.state('root.group.manage', {
url: '/manage',
templateUrl: 'templates/groupmanage.html',
Expand All @@ -53,20 +67,31 @@ app.config(function($stateProvider, $urlRouterProvider) {
templateUrl: 'templates/groupbrowser_cat.html',
controller: 'GroupCategoryController'
})
.state('root.creategroup', {
url: '/groups/create',
templateUrl: 'templates/groupcreate.html',
})
.state('root.user', {
url: '/{user:int}',
abstract: true,
templateUrl: 'templates/user.html'
})
.state('root.user.timeline', {
url: '/',
templateUrl: 'templates/usertimeline.html'
})
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'LoginController'
});
});

app.controller('MainAuthController', function($rootScope, Restangular, $state){
$rootScope.user = null;
Restangular.one('auth/check').get().then(function(user){
$rootScope.user = user;
}, function(){
$state.go('login');
});
app.controller('MainController', function($rootScope, user){
$rootScope.user = user;
});
app.controller('NotificationController', function($rootScope){
$rootScope.notificationCount = Math.floor(Math.random() * 20);
});

})();
})();
Loading

0 comments on commit 4a86c9b

Please sign in to comment.