def jointogroup(request, **kwargs): from qlnhom.models import Nhom, ThanhVienNhom nhom = Nhom.objects.get(pk=kwargs["nhomid"]) response = ( u"<div class='alert'><button type='button' class='close' data-dismiss='alert'>×</button>" u"<strong>Thông báo: </strong>Bạn đã tham gia nhóm thành công</div>" u"<script>$('a[href$=\"%s\"]')" u".html('<i class=\"icon-remove\"></i> Bỏ nhóm')" u".attr('data-method','POST')" u".attr('data-target','#deleteModal')" u".removeClass('btn-info ajax').addClass('btn-warning ajax-modal')" u".attr('href','%s')</script>" % (request.get_full_path(), nhom.get_absolute_url() + "/out") ) join = ThanhVienNhom(user=request.user, nhom=nhom) try: join.full_clean() join.save() except ValidationError as e: response = "" for message in e.messages: response += ( u"<div class='alert alert-error'>" u"<button type='button' class='close' data-dismiss='alert'>×</button>" u"<strong>Lỗi: </strong> %s </div>" % message ) data = {"html": response} return HttpResponse(json.dumps(data), mimetype="application/json")
def saveForm(**kwargs): g = kwargs["form"].save() from qlnhom.models import ThanhVienNhom m = ThanhVienNhom(user=kwargs["user"], nhom_id=g.pk, nhom_truong=True) msg = ( u"<div class='alert alert-success'>" u"<button type='button' class='close'" u" data-dismiss='alert'>×</button>" u"<strong>Thông báo: </strong>Tạo nhóm" u" thành công</div>" ) m.save() msg += ( u"<div class='alert alert-success'>" u"<button type='button' class='close' data-dismiss='alert'>×</button>" u"<strong>Thông báo: </strong> Bạn trở thành nhóm trưởng </div>" ) return {"message": msg}