Skip to content

Commit

Permalink
domain bulletin
Browse files Browse the repository at this point in the history
  • Loading branch information
twd2 committed Jul 23, 2017
1 parent 0001b6d commit 7a80e1a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions vj4/handler/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async def get(self):
@base.post_argument
@base.require_csrf_token
@base.sanitize
async def post(self, *, name: str, gravatar: str):
await domain.edit(self.domain_id, name=name, gravatar=gravatar)
async def post(self, *, name: str, gravatar: str, bulletin: str):
await domain.edit(self.domain_id, name=name, gravatar=gravatar, bulletin=bulletin)
self.json_or_redirect(self.url)


Expand Down
5 changes: 3 additions & 2 deletions vj4/handler/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ async def get(self):
@base.post_argument
@base.require_csrf_token
@base.sanitize
async def post(self, *, id: str, name: str, gravatar: str):
domain_id = await domain.add(id, self.user['_id'], name=name, gravatar=gravatar)
async def post(self, *, id: str, name: str, gravatar: str, bulletin: str):
domain_id = await domain.add(id, self.user['_id'], name=name,
gravatar=gravatar, bulletin=bulletin)
self.json_or_redirect(self.reverse_url('domain_manage', domain_id=domain_id))


Expand Down
1 change: 1 addition & 0 deletions vj4/locale/zh_CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,4 @@ Background Image: 背景图片
He:
She:
(unsafe): (不安全)
Bulletin: 公告
3 changes: 2 additions & 1 deletion vj4/model/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@
ROLE_DEFAULT: DEFAULT_PERMISSIONS,
ROLE_ADMIN: ADMIN_PERMISSIONS},
'gravatar': '',
'name': 'Vijos'
'name': 'Vijos',
'bulletin': ''
}
DOMAINS = [DOMAIN_SYSTEM]

Expand Down
5 changes: 3 additions & 2 deletions vj4/model/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
@argmethod.wrap
async def add(domain_id: str, owner_uid: int,
roles=builtin.DOMAIN_SYSTEM['roles'],
name: str=None, gravatar: str=None):
name: str=None, gravatar: str=None, bulletin: str=''):
validator.check_domain_id(domain_id)
validator.check_name(name)
validator.check_bulletin(bulletin)
for domain in builtin.DOMAINS:
if domain['_id'] == domain_id:
raise error.DomainAlreadyExistError(domain_id)
coll = db.coll('domain')
try:
return (await coll.insert_one({'_id': domain_id, 'owner_uid': owner_uid,
'roles': roles, 'name': name,
'gravatar': gravatar})).inserted_id
'gravatar': gravatar, 'bulletin': bulletin})).inserted_id
except errors.DuplicateKeyError:
raise error.DomainAlreadyExistError(domain_id) from None

Expand Down
11 changes: 11 additions & 0 deletions vj4/ui/templates/domain_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
{% extends "layout/basic.html" %}
{% import "components/contest.html" as contest with context %}
{% block content %}
{% if handler.domain['bulletin'] %}
<div class="row">
<div class="large-12 columns">
<div class="section">
<div class="section__body typo">
{{ handler.domain['bulletin']|markdown }}
</div>
</div>
</div>
</div>
{% endif %}
<div class="row">
<div class="large-9 columns">
{% if not tdocs %}
Expand Down
8 changes: 8 additions & 0 deletions vj4/ui/templates/domain_manage.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{% import "components/user.html" as user %}
{% extends "domain_base.html" %}
{% block domain_content %}
{% if handler.domain['bulletin'] %}
<div class="section">
<div class="section__body typo">
{{ handler.domain['bulletin']|markdown }}
</div>
</div>
{% endif %}
<div class="section">
<div class="section__header">
<h1 class="section__title" data-heading>{{ _('Information') }}</h1>
Expand All @@ -10,6 +17,7 @@ <h1 class="section__title" data-heading>{{ _('Information') }}</h1>
<dt>{{ _('Gravatar') }}</dt><dd><img src="{{ handler.domain['gravatar']|gravatar_url }}" width="32" height="32"></dd>
<dt>{{ _('Owner') }}</dt><dd>{{ user.render_inline(owner_udoc, badge=false) }}</dd>
<dt>{{ _('Name') }}</dt><dd>{{ handler.domain['name'] }}</dd>
</dl>
</div>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions vj4/ui/templates/partials/domain_edit_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
{% endif %}
{{ form.form_text(label='Name', name='name', value=ddoc['name']|default(''), autofocus=(page_name == 'domain_manage_edit'), required=true) }}
{{ form.form_text(label='Gravatar Email', help_text='Will be used as the domain icon.', name='gravatar', value=ddoc['gravatar']|default('')) }}
{{ form.form_textarea(columns=12, label='Bulletin', name='bulletin', value=ddoc['bulletin']|default(''), markdown=true, required=false) }}
9 changes: 9 additions & 0 deletions vj4/util/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ def check_description(s):
raise error.ValidationError('description')


def is_bulletin(s):
return isinstance(s, str) and len(s) < 65536


def check_bulletin(s):
if not is_bulletin(s):
raise error.ValidationError('bulletin')


def is_lang(i):
return i in constant.language.LANG_TEXTS

Expand Down

0 comments on commit 7a80e1a

Please sign in to comment.