コード例 #1
0
ファイル: profile.py プロジェクト: Rogaton/Booki
def remote_group_create(request, message, profileid):
    """
    Creates new Booki Group.

    Input:
     - groupName
     - groupDescription

    Output:
     - list

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type message: C{dict}
    @param message: Message object
    @type profileid: C{string}
    @param profile: Unique Profile id
    @rtype: C{dict}
    @return: Returns success of the command
    """

    from booki.utils.book import createBookiGroup, BookiGroupExist

    groupName = message.get("groupName", "")
    groupDescription = message.get("groupDescription", "")

    try:
        group = createBookiGroup(groupName, groupDescription, request.user)
        group.members.add(request.user)
    except BookiGroupExist:
        transaction.rollback()
        return {"created": False}
    else:
        transaction.commit()

    return {"created": True}
コード例 #2
0
def remote_group_create(request, message, profileid):
    """
    Creates new Booki Group.

    Input:
     - groupName
     - groupDescription

    Output:
     - list

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type message: C{dict}
    @param message: Message object
    @type profileid: C{string}
    @param profile: Unique Profile id
    @rtype: C{dict}
    @return: Returns success of the command
    """

    from booki.utils.book import createBookiGroup, BookiGroupExist

    groupName = message.get("groupName", "")
    groupDescription = message.get("groupDescription", "")

    try:
        group = createBookiGroup(groupName, groupDescription, request.user)
        group.members.add(request.user)
    except BookiGroupExist:
        transaction.rollback()
        return {"created": False}
    else:
        transaction.commit()

    return {"created": True}
コード例 #3
0
def create_group(request, username):
    """
    Django View. Show content for Create Group dialog and creates group.

    @type request: C{django.http.HttpRequest}
    @param request: Django Request
    @type username: C{string}
    @param username: Username.
    """

    from django.contrib.auth.models import User

    try:
        user = User.objects.get(username=username)
    except User.DoesNotExist:
        try:
            resp = pages.ErrorPage(request, "errors/user_does_not_exist.html",
                                   {"username": username})
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    if not request.user.is_authenticated():
        try:
            resp = pages.ErrorPage(request, "errors/no_permissions.html")
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    from booki.utils.book import checkGroupAvailability, createBookiGroup
    from booki.editor import models

    if request.GET.get("q", "") == "check":
        from booki.utils.json_wrapper import json

        data = {
            "available":
            checkGroupAvailability(request.GET.get('groupname', '').strip())
        }

        try:
            resp = HttpResponse(json.dumps(data), "text/plain")
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    if request.GET.get("q", "") == "create":
        from booki.utils.json_wrapper import json

        groupName = request.GET.get('name', '').strip()
        groupDescription = request.GET.get('description', '').strip()

        groupCreated = False

        if checkGroupAvailability(groupName):
            try:
                group = createBookiGroup(groupName, groupDescription,
                                         request.user)
                group.members.add(request.user)
                groupCreated = True
            except BookiGroupExist:
                groupCreated = False
                transaction.rollback()
            else:
                transaction.commit()

        data = {'created': groupCreated}

        try:
            resp = HttpResponse(json.dumps(data), "text/plain")
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    try:
        resp = render_to_response('account/create_group.html', {
            "request": request,
            "user": user
        })
    except:
        transaction.rollback()
        raise
    else:
        transaction.commit()

    return resp
コード例 #4
0
ファイル: views.py プロジェクト: MechanisM/Booktype
def create_group(request, username):
    """
    Django View. Show content for Create Group dialog and creates group.

    @type request: C{django.http.HttpRequest}
    @param request: Django Request
    @type username: C{string}
    @param username: Username.
    """

    from django.contrib.auth.models import User

    try:
        user = User.objects.get(username=username)
    except User.DoesNotExist:
        try:
            return pages.ErrorPage(request, "errors/user_does_not_exist.html", {"username": username})
        except:
            transaction.rollback()
        finally:
            transaction.commit()    

    if not request.user.is_authenticated():
        try:
            return pages.ErrorPage(request, "errors/no_permissions.html")
        except:
            transaction.rollback()
        finally:
            transaction.commit()    

            
    from booki.utils.book import checkGroupAvailability, createBookiGroup
    from booki.editor import models

    if request.GET.get("q", "") == "check":
        from booki.utils.json_wrapper import json

        data = {"available": checkGroupAvailability(request.GET.get('groupname', '').strip())}

        try:
            return HttpResponse(json.dumps(data), "text/plain")
        except:
            transaction.rollback()
        finally:
            transaction.commit()    


    if request.GET.get("q", "") == "create":
        from booki.utils.json_wrapper import json

        groupName = request.GET.get('name', '').strip()
        groupDescription = request.GET.get('description', '').strip()

        groupCreated = False

        if checkGroupAvailability(groupName):
            try:
                group = createBookiGroup(groupName, groupDescription, request.user)
                group.members.add(request.user)
                groupCreated = True
            except BookiGroupExist:
                groupCreated = False
                transaction.rollback()
            else:
                transaction.commit()

        data = {'created': groupCreated}

        try:
            return HttpResponse(json.dumps(data), "text/plain")
        except:
            transaction.rollback()
        finally:
            transaction.commit()    


    try:
        return render_to_response('account/create_group.html', {"request": request,
                                                               "user": user})
    except:
        transaction.rollback()
    finally:
        transaction.commit()