예제 #1
0
    def POST_snoovatar(self, form, jquery, public, snoo_color,
                       unvalidated_components):
        if not feature.is_enabled('snoovatars'):
            return

        if form.has_errors(
                "components",
                errors.NO_TEXT,
                errors.TOO_LONG,
                errors.BAD_STRING,
        ):
            return
        if form.has_errors("snoo_color", errors.BAD_CSS_COLOR):
            return

        try:
            tailors = g.plugins["gold"].tailors_data
            validated = {}

            for tailor in tailors:
                tailor_name = tailor["name"]

                component = unvalidated_components.get(tailor_name)

                # if the tailor requires a selection, ensure there is one
                if not tailor["allow_clear"]:
                    require(component)

                # ensure this dressing exists
                dressing = component.get("dressingName")
                if dressing:
                    for d in tailor["dressings"]:
                        if dressing == d["name"]:
                            break
                    else:
                        raise RequirementException

                validated[tailor_name] = component
        except RequirementException:
            c.errors.add(errors.INVALID_SNOOVATAR, field="components")
            form.has_errors("components", errors.INVALID_SNOOVATAR)
            return

        SnoovatarsByAccount.save(
            user=c.user,
            name="snoo",
            public=public,
            snoo_color=snoo_color,
            components=validated,
        )
    def POST_snoovatar(self, form, jquery, public, snoo_color, unvalidated_components):
        if not feature.is_enabled('snoovatars'):
            return

        if form.has_errors("components",
                           errors.NO_TEXT,
                           errors.TOO_LONG,
                           errors.BAD_STRING,
                          ):
            return
        if form.has_errors("snoo_color", errors.BAD_CSS_COLOR):
            return

        try:
            tailors = g.plugins["gold"].tailors_data
            validated = {}

            for tailor in tailors:
                tailor_name = tailor["name"]

                component = unvalidated_components.get(tailor_name)

                # if the tailor requires a selection, ensure there is one
                if not tailor["allow_clear"]:
                    require(component)

                # ensure this dressing exists
                dressing = component.get("dressingName")
                if dressing:
                    for d in tailor["dressings"]:
                        if dressing == d["name"]:
                            break
                    else:
                        raise RequirementException

                validated[tailor_name] = component
        except RequirementException:
            c.errors.add(errors.INVALID_SNOOVATAR, field="components")
            form.has_errors("components", errors.INVALID_SNOOVATAR)
            return

        SnoovatarsByAccount.save(
            user=c.user,
            name="snoo",
            public=public,
            snoo_color=snoo_color,
            components=validated,
        )
    def GET_snoovatar(self, vuser):
        if not feature.is_enabled("snoovatars"):
            self.abort404()

        if not vuser or vuser._deleted or not vuser.gold:
            self.abort404()

        snoovatar = SnoovatarsByAccount.load(vuser, "snoo")

        user_is_owner = c.user_is_loggedin and c.user == vuser
        if not user_is_owner:
            if not snoovatar or not snoovatar["public"]:
                self.abort404()

        return SnoovatarProfilePage(
            user=vuser, content=Snoovatar(editable=user_is_owner, snoovatar=snoovatar, username=vuser.name)
        ).render()
예제 #4
0
    def GET_snoovatar(self, vuser):
        if not vuser or vuser._deleted or not vuser.gold:
            self.abort404()

        snoovatar = SnoovatarsByAccount.load(vuser, "snoo")

        user_is_owner = c.user_is_loggedin and c.user == vuser
        if not user_is_owner:
            if not snoovatar or not snoovatar["public"]:
                self.abort404()

        return SnoovatarProfilePage(
            user=vuser,
            content=Snoovatar(
                editable=user_is_owner,
                snoovatar=snoovatar,
                username=vuser.name,
            ),
        ).render()
예제 #5
0
 def GET_snoovatar(self):
     snoovatar = SnoovatarsByAccount.load(c.user, "snoo")
     response.content_type = "application/json"
     return json.dumps(snoovatar)
 def GET_snoovatar(self):
     snoovatar = SnoovatarsByAccount.load(c.user, "snoo")
     response.content_type = "application/json"
     return json.dumps(snoovatar)