Exemple #1
0
def change_tagline():
    tagline = get_argument("tagline")
    try:
        g.user.set_properties( {tagline:tagline} )
        return json.dumps({"success": True})
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #2
0
def change_email():
    email = get_argument("email")
    try:
        g.user.request_change_properties( email = email )
        return json.dumps({"success": True})
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #3
0
def ajax_messages(discussion_uuid):
    try:
        result = {}
        discussion = Discussion.get_by_uuid(discussion_uuid)

        if request.method == "GET":
            offset = request.values.get("offset", None, type=int)
            first_index = request.values.get("first_index", None, type=int)

            if offset is None or first_index is None:
                result["unread_count"] = 0
                result["success"] = True
                return json.dumps(result)

            result = discussion.get_messages_json(offset=offset)
            messages = result.get("messages")
            if first_index is not None:
                messages = [message for message in messages if message.get("index", None) < first_index]
            result["messages"] = messages
            result["unread_count"] = discussion.unread_count()

        elif request.method == "POST":
            message = request.values.get("message", None, type=unicode)
            discussion.send_message(message)

            result = dict(discussion_uuid=discussion_uuid, message=message)

        result["success"] = True
        return json.dumps(result)

    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #4
0
def change_phone():
    phone = get_argument("phone")
    try:
        g.user.request_change_properties( phone = phone )
        return json.dumps({"success": True})
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #5
0
def ajax_close_issue(discussion_uuid):
    try:
        issue = Issue.get_by_uuid(discussion_uuid)
        result = issue.close()
        result["success"] = True
        return json.dumps(result)
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #6
0
def change_phone_confirm():
    verifyPhone = get_argument("verifyPhone")
    code = get_argument("code")
    try:
        g.user.confirm_mail_or_phone( phone = verifyPhone, code = code )
        return json.dumps({"success": True})
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #7
0
def change_username():
    password = get_argument("password")
    username = get_argument("username")
    try:
        g.user.set_properties_with_password( pwd = password, username = username )
        return json.dumps({"success": True})
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #8
0
def ajax_attachments(discussion_uuid):
    try:
        filename = request.values.get("filename", None)
        location = request.values.get("location", None)
        result = Discussion.add_attachments(filename, location, discussion_uuid)
        result["success"] = True
        return json.dumps(result)
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #9
0
def ajax_new_panel():
    try:
        result = dict()
        result = Discussion.create(
            title=request.values.get("title", None), description=request.values.get("description", None)
        )
        result["success"] = True
        return json.dumps(result)
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #10
0
def ajax_leave_panel(discussion_uuid):
    try:
        discussion = Discussion.get_by_uuid(discussion_uuid)
        result = discussion.delete_participants([g.user.uuid])

        result["success"] = True
        return json.dumps(result)

    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #11
0
def change_password():
    password = get_argument("password")
    newpassword = get_argument("newpassword")
    confirm = get_argument("confirm")
    if confirm != newpassword:
        return json.dumps({"success": False, "msg":unicode( _("Passwords must match"))})
    try:
        g.user.set_properties_with_password( pwd = password, password = newpassword )
        return json.dumps({"success": True})
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #12
0
def topics(page=1):
    topics = [ ]
    query = request.args[ "q" ] if "q" in request.args else ""
    session[ "search_q" ] = query
    try:
        paginator = Paginator(page, PAGINATION_PER_PAGE, 0)
        topics = TopicProxy.search(query, paginator=paginator)
    except HTTPError, e:
        res = check_error(e)
        if res is not None:
            return res
        flash(unicode(SERVER_ERRORS.get(e.code, e.msg)), 'error')
Exemple #13
0
def ajax_panel_update(discussion_uuid):
    try:
        discussion = Discussion.get_by_uuid(discussion_uuid)
        result = discussion.update(
            title=request.values.get("title", None), description=request.values.get("description", None)
        )

        result["success"] = True
        return json.dumps(result)

    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #14
0
def change_verify():
    email = get_argument("email")
    phone = get_argument("phone")
    try:
        if email:
            UserProxy.verify( email = email )
        elif phone:
            UserProxy.verify( phone = phone )
        else:
            return json.dumps({"success": False, "msg": unicode(_("Need 'email' or 'phone' in arguments"))})
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #15
0
def ajax_unread_total():
    try:
        result = {}
        discussion_list = Discussion.get_by_user_uuid(g.user.uuid, extras=["summary", "lastseen"])
        unread_total = 0
        for discussion in discussion_list:
            unread_total += discussion.unread_count()
        g.unread_total = unread_total
        result["unread_total"] = unread_total
        result["success"] = True
        return json.dumps(result)
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #16
0
def ajax_seen(discussion_uuid):
    try:
        result = {}
        discussion = Discussion.get_by_uuid(discussion_uuid)

        if request.method == "GET":
            result["unread_count"] = discussion.unread_count()
        elif request.method == "POST":
            seen_count = request.values.get("seen_count", None, type=int)
            if seen_count is not None and seen_count >= 0:
                result = Discussion.set_seen_count(discussion_uuid, seen_count)
            result["unread_count"] = 0

        result["success"] = True
        return json.dumps(result)
    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #17
0
def ajax_participants(discussion_uuid):
    try:
        result = dict()
        discussion = Discussion.get_by_uuid(discussion_uuid)

        if request.method == "POST":
            participants = request.values.get("participants", None)
            if participants is not None:
                participants = json.loads(participants)
                result = discussion.add_participants(participants)

        elif request.method == "DELETE":
            users = request.values.get("users", [])
            result = discussion.delete_participants(users)

        result["success"] = True
        return json.dumps(result)

    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #18
0
def panels(discussion_uuid=None):
    discussion = None
    discussions_list = []
    friends = []
    list_type = "own"
    query = request.args.get("q", None)
    offset = request.args.get("offset", None)
    to_json = request.args.get("to_json", None)

    try:
        if discussion_uuid is not None:
            discussion = Discussion.get_by_uuid(discussion_uuid)
        if query is not None:
            list_type = "search"
            discussions_list = Discussion.search(query)
        else:
            list_type = "own"
            discussions_list = Discussion.get_by_user_uuid(g.user.uuid, extras=["summary", "lastseen"])
        if g.user.is_authenticated():
            friends = g.user.get_friends()

    except HTTPError, e:
        flash(unicode(SERVER_ERRORS.get(e.code, e.msg)), "error")
Exemple #19
0
def ajax_panel(discussion_uuid):
    try:
        result = dict()
        discussion = Discussion.get_by_uuid(discussion_uuid)

        if request.method == "GET":
            result = discussion.get_messages_json()
            result["participants"] = discussion.get_participants_json()["participants"]
            result["attachments"] = discussion.attachments
            result["unread_count"] = discussion.unread_count()
            result["discussion"] = discussion.to_json()

        elif request.method == "PATCH":
            result = discussion.update(
                title=request.values.get("title", None), description=request.values.get("description", None)
            )

        result["success"] = True
        print result
        return json.dumps(result)

    except HTTPError, e:
        return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
Exemple #20
0
def settings_general( ):
    form_full_name = SettingsGeneralFullName(request.form )
    form_username = SettingsGeneralUserName(request.form )
    form_tagline = SettingsGeneralTagline(request.form)
    form_email = SettingsGeneralEmail(request.form )
    form_password = SettingsGeneralPassword(request.form )
    form_phone = SettingsGeneralPhone(request.form )
    form_network = SettingsGeneralNetwork(request.form )
    form_languages = SettingsGeneralLanguages(request.form )
    form_verify_email = SettingsVerifyEmail( request.form)
    form_verify_phone = SettingsVerifyPhone( request.form)
    organizations = []
    try:
        g.user.validate()

        if form_full_name.validate_on_submit( ):
            g.user.set_properties_with_password( pwd = form_full_name.password.data,
                                                 fullname = form_full_name.fullname.data )
            return redirect(url_for("settings_general"))

        if form_username.validate_on_submit( ):
            g.user.set_properties_with_password( pwd = form_username.password.data,
                                                 username = form_username.username.data )
            return redirect(url_for("settings_general"))

        if form_tagline.validate_on_submit( ):
            g.user.set_properties( {tagline:form_tagline.tagline.data} )
            return redirect(url_for("settings_general"))

        if form_email.validate_on_submit( ):
            g.user.request_change_properties( email = form_email.email.data )
            return redirect(url_for("settings_general"))

        if form_verify_email.validate_on_submit( ):
            g.user.confirm_mail_or_phone( email = form_verify_email.verifyEmail.data,
                                          code = form_verify_email.code.data )
            return redirect(url_for("settings_general"))

        if form_verify_phone.validate_on_submit( ):
            g.user.confirm_mail_or_phone( phone = form_verify_phone.verifyPhone.data,
                                          code = form_verify_phone.code.data )
            return redirect(url_for("settings_general"))

        if form_password.validate_on_submit( ):
            g.user.set_properties_with_password( pwd = form_password.password.data,
                                                 password = form_password.newpassword.data )
            return redirect(url_for("settings_general"))

        if form_phone.validate_on_submit( ):
            g.user.request_change_properties( phone = form_phone.phone.data )
            return redirect(url_for("settings_general"))

        if form_languages.validate_on_submit():
            # print form_languages.language.data
            g.user.set_properties( {language:form_languages.language.data})
            return redirect(url_for("settings_general"))

        organizations = g.user.organizations
    except HTTPError, e:
        res = check_error(e)
        if res is not None:
            return res
        flash( unicode(SERVER_ERRORS.get(e.code, e.msg)), 'error' )