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

Commit

Permalink
delete subgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
smartlt committed Dec 7, 2015
1 parent a822df5 commit 8e31744
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
18 changes: 16 additions & 2 deletions group/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,20 +419,34 @@ def get(self, request, group_parent_id, format=None):

def post(self, request, group_parent_id, format=None):
parent_group = self.get_group(group_parent_id)
print parent_group
try:
sub_group = Group.objects.create(
name=request.data.get('name'), type=1, description="Subgroup of"+parent_group.name,
short_description="Subgroup of"+parent_group.name, activities="somthing",
parent=parent_group
).save()
print sub_group
return Response(sub_group)
except Exception as inst:
print type(inst) # the exception instance
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):

Expand Down
15 changes: 13 additions & 2 deletions ui/static/app/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ app.controller('GroupFeedController', function($scope, $stateParams, $http, $loc
}

$http.get('/api/group/'+ $stateParams.id + '/subgroup').success(function(data){
console.log(data);
$scope.subgroups = data;
});

Expand Down Expand Up @@ -150,7 +149,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 @@ -176,11 +175,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){
});

};

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

$http.get('/api/group/'+ $stateParams.id + '/subgroup').success(function(data){
$scope.subgroups = data;
});

$scope.editInfo = function(){
$http.put('/api/group/'+groupID+'/edit/',$scope.group).success(function(data){
});
Expand Down
8 changes: 4 additions & 4 deletions ui/static/templates/groupmanage.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="subgroup in [1,2,3]">
<td>Name</td>
<tr ng-repeat="subgroup in subgroups">
<td>{{subgroup.name}}</td>
<td>
<button class="btn btn-sm btn-danger">Remove</button>
<button ng-click="deleteSubgroup(subgroup.id)" class="btn btn-sm btn-danger">Remove</button>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -145,4 +145,4 @@ <h4>Directory</h4>
</form>

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

0 comments on commit 8e31744

Please sign in to comment.