def group_edit( request, group_id ): """ Edit Group data :param: request :param: group_id :return: String """ # Identify database record group = get_object_or_404( Group, pk = group_id ) # When form is submitted if request.method == 'POST': # Tries to validate form and save data form = GroupForm( request.POST, instance = group ) if form.is_valid(): form.save() messages.success( request, 'Group was successfully updated.') return HttpResponseRedirect( reverse( 'admin:core:group_details', args = ( group_id, ) ) ) else: form = GroupForm( instance = group ) # Template data context = { 'form': form, 'cancel_url': reverse( 'admin:core:group_details', args = ( group_id, ) ) } # Print Template return render( request, 'core/admin/group/edit.html', context )
def group_add( request ): """ Add new Group :param: request :param: user_id :return: String """ # When form is submitted if request.method == 'POST': # Tries to validate form and save data form = GroupForm( request.POST ) if form.is_valid(): group = form.save() messages.success( request, 'Group was successfully added.') return HttpResponseRedirect( reverse( 'admin:core:group_details', args = ( group.id, ) ) ) else: form = GroupForm() # Template data context = { 'form': form, 'cancel_url': reverse( 'admin:core:groups' ) } # Print Template return render( request, 'core/admin/group/add.html', context )
def group_edit(request, group_id): """ Edit Group data :param: request :param: group_id :return: String """ # Identify database record group = get_object_or_404(Group, pk=group_id) # When form is submitted if request.method == 'POST': # Tries to validate form and save data form = GroupForm(request.POST, instance=group) if form.is_valid(): form.save() messages.success(request, 'Group was successfully updated.') return HttpResponseRedirect( reverse('admin:core:group_details', args=(group_id, ))) else: form = GroupForm(instance=group) # Template data context = { 'form': form, 'cancel_url': reverse('admin:core:group_details', args=(group_id, )) } # Print Template return render(request, 'core/admin/group/edit.html', context)
def group_add(request): """ Add new Group :param: request :param: user_id :return: String """ # When form is submitted if request.method == 'POST': # Tries to validate form and save data form = GroupForm(request.POST) if form.is_valid(): group = form.save() messages.success(request, 'Group was successfully added.') return HttpResponseRedirect( reverse('admin:core:group_details', args=(group.id, ))) else: form = GroupForm() # Template data context = {'form': form, 'cancel_url': reverse('admin:core:groups')} # Print Template return render(request, 'core/admin/group/add.html', context)