Skip to content

Commit

Permalink
[update]
Browse files Browse the repository at this point in the history
  • Loading branch information
boke0 committed Mar 7, 2021
1 parent e5ed1d5 commit f0daac1
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 243 deletions.
55 changes: 0 additions & 55 deletions mitama/app/templates/lists.macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@
</div>
{% endif %}
{%- endmacro %}
{% macro userItemEx(user, id=None, link=None, small=False) -%}
{% if link != None %}
<a href="{{link}}" class="user-item {% if small %}small{% endif %}" id='{{id}}'>
{% else %}
<div href="{{link}}" class="user-item {% if small %}small{% endif %}" id='{{id}}'>
{% endif %}
<img src='{{ dataurl(user.icon) }}' class='icon' />
<div class='detail'>
<div class='name'>{{ user.name }}</div>
<div class='screen-name'>{{ user.screen_name }}</div>
{{ caller() }}
</div>
{% if link != None %}
</a>
{% else %}
</div>
{% endif %}
{%- endmacro %}
{% macro groupItem(group, id=None, link=None, tree=False, small=False) -%}
<div class="group-item {% if small %}small{% endif %}" id='{{id}}'>
<div class='branch'></div>
Expand All @@ -50,24 +32,6 @@
{% endif %}
</div>
{%- endmacro %}
{% macro groupItemEx(group, id=None, link=None, tree=False, small=False) -%}
<div class="group-item {% if small %}small{% endif %}" id='{{id}}'>
<div class='branch'></div>
<a {% if link != None %}href="{{link}}"{% endif %} class='profile'>
<img src='{{ dataurl(group.icon) }}' class='icon' />
<div class='detail'>
<div class='name'>{{ group.name }}</div>
<div class='screen-name'>{{ group.screen_name }}</div>
{{ caller() }}
</div>
</a>
{% if tree and group.groups.length != 0 %}
<div class='children'>
{{ tree(group.groups) }}
</div>
{% endif %}
</div>
{%- endmacro %}
{% macro appItem(app, id=None, link=None, small=False) -%}
{% if link != None %}
<a href="{{link}}" class="app-item {% if small %}small{% endif %}" id='{{id}}'>
Expand All @@ -86,22 +50,3 @@
</div>
{% endif %}
{%- endmacro %}
{% macro appItemEx(app, id=None, link=None, small=False) -%}
{% if link != None %}
<a href="{{link}}" class="app-item {% if small %}small{% endif %}" id='{{id}}'>
{% else %}
<div href="{{link}}" class="app-item {% if small %}small{% endif %}" id='{{id}}'>
{% endif %}
<img src='{{ dataurl(app.icon) }}' class='icon' />
<div class='detail'>
<div class='name'>{{ app.name }}</div>
<div class='screen-name'>{{ app.screen_name }}</div>
<p class='description'>{{ app.description }}</p>
{{ caller() }}
</div>
{% if link != None %}
</a>
{% else %}
</div>
{% endif %}
{%- endmacro %}
3 changes: 2 additions & 1 deletion mitama/models/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ def is_ancestor(self, node):
return True
layer_ = list()
for node_ in layer:
layer_.extend([node_.parent])
if node_.parent is not None:
layer_.extend([node_.parent])
layer = layer_
return False

Expand Down
51 changes: 16 additions & 35 deletions mitama/portal/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ class GroupsController(Controller):
def create(self, req):
template = self.view.get_template("group/create.html")
groups = Group.list()
error = ""
if req.method == "POST":
form = GroupCreateForm(req.post())
try:
Expand All @@ -454,12 +455,13 @@ def create(self, req):
group.append(req.user)
return Response.redirect(self.app.convert_url("/groups"))
except ValidationError as err:
return Response.render(
template,
{"groups": groups, "icon": load_noimage_group(), "error": str(err)},
)
error = str(err)
return Response.render(
template, {"groups": groups, "icon": load_noimage_group()}
template, {
"groups": groups,
"icon": load_noimage_group(),
"error": error
}
)

def retrieve(self, req):
Expand All @@ -474,14 +476,15 @@ def retrieve(self, req):

def update(self, req):
template = self.view.get_template("group/update.html")
roles = Role.list()
inner_roles = InnerRole.list()
group = Group.retrieve(screen_name=req.params["id"])

groups = list()
for g in Group.list():
if not (group.is_ancestor(g) or group.is_descendant(g) or g == group):
groups.append(g)
users = list()
error = ""
message = ""
for u in User.list():
if not group.is_in(u):
users.append(u)
Expand All @@ -491,6 +494,7 @@ def update(self, req):
icon = resize_icon(form["icon"]) if form["icon"] is not None else group.icon
group.screen_name = form["screen_name"]
group.name = form["name"]
group.parent = Group.retrieve(form["parent"]) if form["parent"] is not None else None
for role in form["roles"]:
group.roles.append(Role.retrieve(screen_name=role))
group.icon = icon
Expand All @@ -501,39 +505,16 @@ def update(self, req):
rel = UserGroup.retrieve(group = group, user = User.retrieve(user))
rel.roles = [InnerRole.retrieve(screen_name = role) for role in roles]
group.update()
return Response.render(
template,
{
"message": "変更を保存しました",
"group": group,
"screen_name": group.screen_name,
"name": group.name,
"all_groups": groups,
"all_users": users,
"icon": group.icon,
"roles": Role.list(),
"inner_roles": inner_roles
},
)
message = "変更を保存しました"
except ValidationError as err:
error = str(err)
return Response.render(
template,
{
"error": error,
"all_groups": groups,
"all_users": users,
"group": group,
"screen_name": form["screen_name"],
"name": form["name"],
"icon": group.icon,
"roles": Role.list(),
"inner_roles": inner_roles
},
)
roles = Role.list()
inner_roles = InnerRole.list()
return Response.render(
template,
{
"message": message,
"error": error,
"group": group,
"all_groups": groups,
"all_users": users,
Expand Down
59 changes: 41 additions & 18 deletions mitama/portal/static/mitama-style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mitama/portal/static/mitama-style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mitama/portal/templates/group/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
<div class='group-list'>
{% if groups|length %}
{% for group in groups recursive %}
<div class='mt-2'>
{{ lists.groupItem(group, link=url("/groups/" + group.screen_name), tree=loop) }}
</div>
{% endfor %}
{% else%}
<div class='no-item'>グループは存在しません</div>
Expand Down
2 changes: 2 additions & 0 deletions mitama/portal/templates/group/retrieve.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ <h2 class="name">{{group.name}}</h2>
<h3 class="mini-title">メンバー</h3>
<div class="user-list">
{% for user in group.users %}
<div class='mb-2'>
{{ lists.userItem(user, link=url('/users/'+user.screen_name)) }}
</div>
{% endfor %}
</div>
</div>
Expand Down
Loading

0 comments on commit f0daac1

Please sign in to comment.