Skip to content

Commit

Permalink
#5 Add support for setting random label color when creating a new label
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnBarton27 committed Mar 17, 2022
1 parent 679fd0d commit ded8830
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions sit/label.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

from sit_object import SitObject
from item import Item

Expand Down Expand Up @@ -37,6 +39,11 @@ def generate():
steel_blue = LabelColor(hex_code='#4F7CAC')
return [blue_jeans, bone, charcoal, dark_cornflower_blue, light_coral, middle_blue_green, midnight, steel_blue]

@staticmethod
def get_random():
all_colors = LabelColor.get_all()
return random.choice(all_colors)

def _get_create_params_dict(self):
return {
'hex_code': self.hex_code,
Expand Down
5 changes: 3 additions & 2 deletions sit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# SIT
from building import Building
from item import Item
from label import Label
from label import Label, LabelColor
from room import Room

app = Flask(__name__, template_folder=os.path.abspath('static'))
Expand Down Expand Up @@ -120,7 +120,8 @@ def create_room():
def create_label():
label_text = request.form['labelText']

label = Label(text=label_text)
label_color = LabelColor.get_random()
label = Label(text=label_text, color=label_color)
label.create()

all_labels = Label.get_all()
Expand Down
2 changes: 1 addition & 1 deletion sit/static/items/item_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h1 style="text-align: center; display: inline-block; margin-right: 15px;">{{ it
<div id="labels" style="text-align: center; margin-top: 15px;">
{% for label in item.labels %}
<a class="sit-inv-link sit-info-card" href="/label/{{ label.id }}" style="background-color: {{ label.color.hex_code }}; {{ 'color: white;' if label.color.white_text else '' }}">
<i style="margin-right: 5px;"></i>{{ label.text }}
{{ label.text }}
</a>
{% endfor %}
</div>
4 changes: 2 additions & 2 deletions sit/static/labels/list_labels.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% for label in labels %}
<a class="sit-inv-link sit-info-card" href="/label/{{ label.id }}">
<i style="margin-right: 5px;"></i>{{ label.text }}
<a class="sit-inv-link sit-info-card" href="/label/{{ label.id }}" style="background-color: {{ label.color.hex_code }}; {{ 'color: white;' if label.color.white_text else '' }}">
{{ label.text }}
</a>
{% endfor %}

0 comments on commit ded8830

Please sign in to comment.