Example #1
0
    def __init__(
            self,
            name,
            placeholder=""):
        """ Construct a Autocomplete input set.

        Required:
        str     name                name of key to be submited as part of form

        Optional:
        str     autocomple_class    class representing which type of
                                    autocomplete
        str     placeholder         placeholder to put inside TextInput

        """
        super(AutocompleteInput, self).__init__()
        self.append_class(self.AUTOCOMPLETE_CLASS)

        # textinput doesn't actually contain data but does autocomplete.
        input_div = Div()  # for overflow auto and automatic width
        input = TextInput(name + "-" + self.AUTOCOMPLETE_LABEL_CLASS)
        input.set_placeholder(placeholder)
        input.append_class(self.AUTOCOMPLETE_LABEL_CLASS)
        input_div.append_child(input)
        self.append_child(input_div)

        # hiddeninput has actual data to submit.
        hidden = HiddenInput(name)
        hidden.append_class(self.AUTOCOMPLETE_VALUE_CLASS)
        self.append_child(hidden)
Example #2
0
    def __init__(self, current_person, story_id):
        """ Construct a CommentForm.

        Required:
        Person  current_person  the current User's associated Person
        id  story_id    id of the SqNode Story object

        """
        super(CommentForm, self).__init__(
                "{}{}".format(PAGE_NAME.LEAGUE, story_id))

        # TODO: make this draw from view.url constants
        self.set_action("/comment")
        self.append_class(self.COMMENT_FORM_CLASS)

        self.append_child(HiddenInput(SQ_DATA.GAME_ID, story_id))

        self.append_child(AppThumbnail(current_person.picture_url))

        # div allows overflow: auto to maximize that column
        comment_div = Div()
        comment_input = TextInput(SQ_DATA.MESSAGE)
        comment_input.set_placeholder(Copy.comment)
        comment_div.append_child(comment_input)

        self.append_child(comment_div)
        self.append_child(SubmitButton(Copy.comment))
Example #3
0
    def set_content(self, aggregations):
        """ Construct and add content as a direct child. """
        # TODO: remove string and pull directly from aggregations
        div = Div()
        div.append_child(Headline(Copy.rankings_title))
        div.append_child(RankingsList(aggregations.get("standings")))

        self.append_child(div)
Example #4
0
    def set_content(self, item):
        """ Set content for Rankings LI. """
        # TODO make this some default scoreboard icon

        div = Div()
        # FIXME: model should send None instead of "" since "" is a valid
        # src, but model doesn't yet distinguish/translate empty db values.
        src = item.picture_url if item.picture_url else None
        div.append_child(AppThumbnail(src, item.name))
        self.set_column(div)

        opponent = A({"href": "#"}, item.name)
        self.set_column(opponent)

        current_result_streak = Span()
        streak_text = item.current_result_streak
        if streak_text > 0:
            streak_text = "{}{}".format(
                    Copy.win_short,
                    streak_text)
        elif streak_text < 0:
            streak_text = "{}{}".format(
                    Copy.loss_short,
                    -streak_text)
        else:
            streak_text = "--"
        current_result_streak.set_text(streak_text)
        self.set_column(current_result_streak)

        percentage_span = Span()
        win_percentage = item.win_percentage
        win_percentage_text = " .{:.0f}".format(win_percentage * 1000)
        if win_percentage == 1.0:
            win_percentage_text = "1.000"
        elif win_percentage == 0.0:
            win_percentage_text = " .000"
        percentage_span.set_text(win_percentage_text)
        self.set_column(percentage_span)

        loss_count = Span()
        loss_count.set_text(item.loss_count)
        self.set_column(loss_count)

        win_count = Span()
        win_count.set_text(item.win_count)
        self.set_column(win_count)
Example #5
0
    def __init__(self, unique_str, content_element):
        """ Construct a content container, which is needed by iScroll for nice
        scrolling.

        Both the outer and inner container are required and they both must have
        unique ids for iScroll to work.

        Required:
        str     unique_str          the unique identifier of this content
        Element content_element     the element that should be scrollable

        """
        super(ContentWrapper, self).__init__()
        outer_container_id = "{}-{}".format(
                unique_str,
                self.OUTER_CONTAINER_CLASS)
        inner_container_id = "{}-{}".format(
                unique_str,
                self.INNER_CONTAINER_CLASS)

        self.set_id(outer_container_id)
        self.append_class(self.OUTER_CONTAINER_CLASS)

        inner_container = Div()
        inner_container.set_id(inner_container_id)
        inner_container.append_class(self.INNER_CONTAINER_CLASS)

        inner_container.append_child(content_element)
        self.append_child(inner_container)
Example #6
0
    def __init__(self, opponents, result_str):
        """ Construct an opponent section.

        Required:
        list    opponents   a list of Opponent objects.
        str     results_str a string for the result of the opponent group

        """
        super(OpponentsResultGroup, self).__init__()
        self.append_class(self.OPPONENTS_RESULT_GROUP_CLASS)

        # each opponent with a thumbnail and name
        self.append_child(OpponentsList(opponents))

        # the result of the opponent group
        result_div = Div()
        result_div.set_text(result_str)
        self.append_child(result_div)
Example #7
0
    def __init__(self, game):
        """ Construct a section with BoxscoreMedia.

        Required:
        Game game   the game to create the boxscore from

        """
        super(BoxscoreMedia, self).__init__()
        self.append_class(self.BOXSCORE_MEDIA_CLASS)

        # to allow the outer object to fit the screen width and still
        # wrap the inner floats
        floatable = FloatContainer()

        game_overview = Div()
        game_overview.append_class(self.GAME_OVERVIEW_CLASS)
        final = Span()
        final.set_text(Copy.final)
        game_overview.append_child(final)
        game_overview.append_child(SportComponent(game.sport))
        floatable.append_child(game_overview)

        # FIXME: get_opponents breaks the contract that the view doesnt get
        # access to non-property methods in model.api.Game.

        # Generate Opponent groups.
        if game.is_rivalry:
            floatable.append_child(OpponentsResultGroup(
                    game.get_opponents(game.winner_ids),
                    Copy.won))
            floatable.append_child(OpponentsResultGroup(
                    game.get_opponents(game.loser_ids),
                    Copy.lost))
        else:
            floatable.append_child(OpponentsResultGroup(
                    game.get_opponents(game.camaraderie_ids),
                    Copy.played))

        self.append_child(floatable)
Example #8
0
    def set_content(self, item):
        """ Set content for CommentLI. """
        comment = item  # item must be a comment

        thumbnail = AppThumbnail(
                comment.commenter_picture_url,
                comment.commenter_name)
        self.set_column(thumbnail)

        div = Div()

        name = A({"href": "#"}, comment.commenter_name)
        div.append_child(name)

        msg = Span()
        msg.set_text(comment.message)
        div.append_child(msg)

        created_ts = RelativeDateComponent(comment.created_ts)
        div.append_child(created_ts)

        self.set_column(div)