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

Commit

Permalink
Merge branch 'subgroup' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
whs committed Dec 8, 2015
2 parents bf5f408 + 2f3a610 commit 2c8cb6e
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 5 deletions.
17 changes: 17 additions & 0 deletions group/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,23 @@ def post(self, request, group_parent_id, format=None):
print inst # __str__ allows args to be printed directly
raise Http404

def put(self, request, group_parent_id, format=None):
parent_group = self.get_group(group_parent_id)
print request.data.get('group_id')
try:
sub_group = Group.objects.get(id=request.data.get('group_id'))
print sub_group
print sub_group.parent
print parent_group
if sub_group.parent == parent_group:
sub_group.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as inst:
print type(inst) # the exception instance
print inst # __str__ allows args to be printed directly
raise Http404


class GroupPostPegination(APIView):

serializer_class = GroupPostSerializer
Expand Down
20 changes: 20 additions & 0 deletions newsfeed/migrations/0004_auto_20151208_0511.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import newsfeed.models


class Migration(migrations.Migration):

dependencies = [
('newsfeed', '0003_comment_file'),
]

operations = [
migrations.AlterField(
model_name='comment',
name='file',
field=models.FileField(null=True, upload_to=newsfeed.models.comment_file_name),
),
]
4 changes: 3 additions & 1 deletion newsfeed/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ def FORMAT(self):
def __unicode__(self):
return "{}'s newsfeed (id={})".format(self.user.username, self.id)

def comment_file_name(instance, filename):
return 'posts/{0}_{1}'.format(instance.id, filename)

class Comment(models.Model):
post = models.ForeignKey(Post)
user = models.ForeignKey(User)
text = models.CharField(max_length=2000)
datetime = models.DateTimeField(auto_now_add=True)
file = models.FileField(
upload_to=lambda instance, filename: 'posts/{0}_{1}'.format(instance.id, filename),
upload_to=comment_file_name,
null=True
)

Expand Down
20 changes: 19 additions & 1 deletion ui/static/app/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ app.controller('GroupInfoController', function($scope, $http, $location){

});

app.controller('GroupManageController', function($scope, $http, $location){
app.controller('GroupManageController', function($scope, $http, $location, $stateParams){
var groupID = $location.path().split('/')[2];
function fetchMember(){
$http.get('/api/group/'+groupID+'/member/accepted').then(function(data){
Expand All @@ -225,8 +225,14 @@ app.controller('GroupManageController', function($scope, $http, $location){
$scope.groupMember_pending = data.data;
});
}
function fetchSubgroup(){
$http.get('/api/group/'+ $stateParams.id + '/subgroup').success(function(data){
$scope.subgroups = data;
});
}

fetchMember();
fetchSubgroup();

function acceptMember(pk){
$http.put('/api/group/'+groupID+'/member/'+ pk).then(function(data){
Expand All @@ -241,11 +247,23 @@ app.controller('GroupManageController', function($scope, $http, $location){
$scope.acceptMember = acceptMember;
$scope.denyMember = denyMember;

$scope.deleteSubgroup = function (id){
data = {
group_id : id
};
$http.put('/api/group/'+ $stateParams.id + '/subgroup',data).success(function(data){
fetchSubgroup();
});

};

$http.get('/api/group/'+groupID).then(function(data){
$scope.group = data.data;
});




$scope.editInfo = function(){
$http.put('/api/group/'+groupID+'/edit/',$scope.group).success(function(data){
});
Expand Down
1 change: 0 additions & 1 deletion ui/static/templates/groupfeed.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div class="row">
<div class="col-sm-2 subgroupmenu">
<ul class="nav nav-pills nav-stacked">
<li><a href="#" ui-sref="root.group.createsubgroup()"><i class="glyphicon glyphicon-plus"></i> Create subgroup</a></li>
<li ui-sref-active="active"><a href="#" ui-sref="root.group.feed({sub : null})">{{group.name}}</a></li>
<li ui-sref-active="active" ng-repeat="subgroup in subgroups" ui-sref="root.group.feed({sub : subgroup.id})"><a href="#">{{subgroup.name}}</a></li>
</ul>
Expand Down
37 changes: 35 additions & 2 deletions ui/static/templates/groupmanage.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,33 @@
</table>
</div>
</tab>
<tab heading="Subgroup" class="subgroups">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="subgroup in subgroups">
<td>{{subgroup.name}}</td>
<td>
<button ng-click="deleteSubgroup(subgroup.id)" class="btn btn-sm btn-danger">Remove</button>
</td>
</tr>
<tr>
<td colspan="2">
<a href="#" ui-sref="root.group.createsubgroup()" class="btn btn-default"><i class="glyphicon glyphicon-plus"></i> Create subgroup</a>
</td>
</tr>
</tbody>
</table>
</div>
</tab>
<tab heading="Description &amp; Settings" class="settings">
<form action="">
<form action="" enctype="multipart/form-data">
<div class="form-group">
<h4>What's this group about</h4>
<textarea ng-model = "group.description" class="form-control" rows="3"></textarea>
Expand All @@ -54,6 +79,14 @@ <h4>Your activities?</h4>
<textarea ng-model = "group.activities" class="form-control" rows="10"></textarea>
</div>

<div class="form-group">
<h4>Cover image</h4>
<input type="file" accept="image" class="form-control">
<div class="help-block">
945x200 pixels
</div>
</div>

<div class="form-group">
<h4>Directory</h4>
<div class="form-group">
Expand Down Expand Up @@ -112,4 +145,4 @@ <h4>Directory</h4>
</form>

</tab>
</tabset>
</tabset>

0 comments on commit 2c8cb6e

Please sign in to comment.