mirror of https://codeberg.org/dribdat/dribdat.git
Resource layout and filtering
This commit is contained in:
parent
b58741d01f
commit
5f5d1b5e93
|
@ -173,9 +173,9 @@ def user_deactivate(user_id, reactivate=False):
|
|||
db.session.add(user)
|
||||
db.session.commit()
|
||||
if reactivate:
|
||||
flash('User is now active.', 'success')
|
||||
flash('User %s is now active.' % user.username, 'success')
|
||||
else:
|
||||
flash('User deactivated.', 'warning')
|
||||
flash('User %s deactivated.' % user.username, 'warning')
|
||||
return users()
|
||||
|
||||
|
||||
|
@ -557,7 +557,7 @@ def role_delete(role_id):
|
|||
@admin_required
|
||||
def resources(page=1):
|
||||
resources = Resource.query.order_by(
|
||||
Resource.type_id.asc()
|
||||
Resource.id.desc()
|
||||
).paginate(page, per_page=10)
|
||||
return render_template('admin/resources.html', data=resources, endpoint='admin.resources', active='resources')
|
||||
|
||||
|
@ -569,6 +569,8 @@ def resource(resource_id):
|
|||
resource = Resource.query.filter_by(id=resource_id).first_or_404()
|
||||
form = ResourceForm(obj=resource, next=request.args.get('next'))
|
||||
form.user_id.choices = [(e.id, "%s" % (e.username)) for e in User.query.filter_by(active=True).order_by('username')]
|
||||
form.event_id.choices = [(e.id, e.name) for e in Event.query.order_by(Event.id.desc())]
|
||||
form.event_id.choices.insert(0, (0, ''))
|
||||
|
||||
if form.validate_on_submit():
|
||||
form.populate_obj(resource)
|
||||
|
@ -588,6 +590,7 @@ def resource_new():
|
|||
resource = Resource()
|
||||
form = ResourceForm(obj=resource, next=request.args.get('next'))
|
||||
form.user_id.choices = [(e.id, "%s" % (e.username)) for e in User.query.filter_by(active=True).order_by('username')]
|
||||
form.event_id.choices = [(e.id, e.name) for e in Event.query.order_by(Event.id.desc())]
|
||||
|
||||
if form.validate_on_submit():
|
||||
del form.id
|
||||
|
|
|
@ -72,8 +72,13 @@ def IsProjectStarred(project, current_user):
|
|||
user_id=current_user.id
|
||||
).count() > 0
|
||||
|
||||
def SuggestionsByProgress(progress):
|
||||
return Resource.query.filter_by(is_visible=True, progress_tip=progress).order_by(Resource.type_id).all()
|
||||
def SuggestionsByProgress(progress, event=None):
|
||||
if event:
|
||||
resources = event.resources_for_event()
|
||||
else:
|
||||
resources = Resource.query
|
||||
resources = resources.filter_by(is_visible=True, progress_tip=progress)
|
||||
return resources.order_by(Resource.type_id).all()
|
||||
|
||||
def GetEventUsers(event):
|
||||
if not event.projects: return None
|
||||
|
|
|
@ -77,7 +77,7 @@ def user(username):
|
|||
# projects = user.projects
|
||||
projects = user.joined_projects()
|
||||
posts = user.latest_posts()
|
||||
submissions = Resource.query.filter_by(user_id=user.id).order_by(Resource.id.desc()).all()
|
||||
submissions = Resource.query.filter_by(user_id=user.id).order_by(Resource.name.asc()).all()
|
||||
return render_template("public/userprofile.html", active="profile",
|
||||
current_event=event, event=event, user=user, cert_path=cert_path,
|
||||
projects=projects, submissions=submissions, posts=posts)
|
||||
|
@ -112,11 +112,11 @@ def event_resources(event_id):
|
|||
for ix, p in enumerate(projectProgressList(True, False)):
|
||||
steps.append({
|
||||
'index': ix + 1, 'name': p[1],
|
||||
'resources': SuggestionsByProgress(p[0])
|
||||
'resources': SuggestionsByProgress(p[0], event)
|
||||
})
|
||||
steps.append({
|
||||
'name': '/etc', 'index': -1,
|
||||
'resources': SuggestionsByProgress(None)
|
||||
'resources': SuggestionsByProgress(None, event)
|
||||
})
|
||||
return render_template("public/resources.html",
|
||||
current_event=event, steps=steps, active="resources")
|
||||
|
@ -180,7 +180,7 @@ def project_post(project_id):
|
|||
# Populate progress dialog
|
||||
form.progress.choices = projectProgressList(event.has_started or event.has_finished, False)
|
||||
# Populate resource list
|
||||
resources = Resource.query.filter_by(is_visible=True).order_by(Resource.type_id).all()
|
||||
resources = event.resources_for_event().filter_by(is_visible=True).order_by(Resource.type_id).all()
|
||||
resource_list = [(0, '')]
|
||||
resource_list.extend([(r.id, r.of_type + ': ' + r.name) for r in resources])
|
||||
form.resource.choices = resource_list
|
||||
|
@ -214,7 +214,7 @@ def project_action(project_id, of_type=None, as_view=True, then_redirect=False,
|
|||
project_team = project.team()
|
||||
latest_activity = project.latest_activity()
|
||||
project_dribs = project.all_dribs()
|
||||
suggestions = SuggestionsByProgress(project.progress)
|
||||
suggestions = SuggestionsByProgress(project.progress, event)
|
||||
return render_template('public/project.html', current_event=event, project=project,
|
||||
project_starred=starred, project_team=project_team, project_dribs=project_dribs, suggestions=suggestions,
|
||||
allow_edit=allow_edit, latest_activity=latest_activity)
|
||||
|
|
|
@ -902,14 +902,13 @@ pre { color: #333; background: white; }
|
|||
}
|
||||
.resources-page .step .resource-card {
|
||||
background: white;
|
||||
margin: 0.5em 0.3em;
|
||||
min-height: 4em;
|
||||
margin: 1px -1px;
|
||||
min-height: 7em;
|
||||
vertical-align: top;
|
||||
}
|
||||
.resources-page .resource-list {
|
||||
margin: 0; padding: 0;
|
||||
margin-bottom: 1em;
|
||||
margin-left: 2rem;
|
||||
margin-top: 1em;
|
||||
}
|
||||
.resources-page .event-resources {
|
||||
padding: 2rem; margin: 0;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
</thead>
|
||||
{% for resource in resources or data.items %}
|
||||
<tr>
|
||||
<td>
|
||||
<td width="50%">
|
||||
<a href="{{ url_for('admin.resource', resource_id=resource.id) }}">
|
||||
{{ resource.name }}
|
||||
</a>
|
||||
|
@ -25,6 +25,10 @@
|
|||
<i title="{{ resource.created_at }}">
|
||||
{{ resource.since }}
|
||||
</i>
|
||||
|
||||
{% if resource.event_id %}
|
||||
@ {{ resource.event.name }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if resource.user_id %}
|
||||
|
|
|
@ -4,13 +4,10 @@
|
|||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<h2>{{ user.username }}</h2>
|
||||
<h4>Edit account</h4>
|
||||
|
||||
<p><a href="{{ url_for('public.user', username=user.username )}}" class="btn btn-success" target="_blank">View profile</a></p>
|
||||
|
||||
<h4>Edit account</h4>
|
||||
|
||||
{{ render_form(url_for('admin.user', user_id=user.id), form) }}
|
||||
|
||||
<hr>
|
||||
|
@ -19,14 +16,21 @@
|
|||
<p>Last active: {{ user.last_active }}</p>
|
||||
|
||||
<div class="btn-group">
|
||||
<a href="{{ url_for('admin.user_delete', user_id=user.id) }}" class="btn btn-sm btn-danger"
|
||||
onclick="if(!window.confirm('Are you sure you wish to delete this user?')) return false">
|
||||
Delete user
|
||||
</a>
|
||||
{% if user.active %}
|
||||
<a href="{{ url_for('admin.user_deactivate', user_id=user.id) }}" class="btn btn-sm btn-warning">
|
||||
{% if not user.active %}
|
||||
<a href="{{ url_for('admin.user_reactivate', user_id=user.id) }}"
|
||||
class="btn btn-sm btn-success">
|
||||
Reactivate account
|
||||
</a>
|
||||
<a href="{{ url_for('admin.user_delete', user_id=user.id) }}" class="btn btn-sm btn-danger"
|
||||
onclick="if(!window.confirm('Are you sure you wish to delete this user?')) return false">
|
||||
Delete user
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('admin.user_deactivate', user_id=user.id) }}"
|
||||
title="Prevent user from making any changes to content except their own profile, which is hidden"
|
||||
class="btn btn-sm btn-warning">
|
||||
Deactivate account
|
||||
</a> <br><small>(* prevents user from making any changes to content except their own profile, which is hidden)</small>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
<h4 class="title">{{ step.name }}</h4>
|
||||
{% endif %}
|
||||
{% if step.resources %}
|
||||
<div class="resource-list col-12">
|
||||
<div class="resource-list row">
|
||||
{% for resource in step.resources %}
|
||||
<a class="col-4 resource-card" href="{{ url_for('public.resource', resource_id=resource.id) }}">
|
||||
<a class="col resource-card" href="{{ url_for('public.resource', resource_id=resource.id) }}">
|
||||
<i title="{{resource.of_type}}"
|
||||
class="fa fa-{{resource.icon}}"></i>
|
||||
<b>{{resource.name}}</b>
|
||||
|
|
|
@ -129,12 +129,12 @@
|
|||
{% endif %}
|
||||
|
||||
{% if submissions %}
|
||||
<div class="row">
|
||||
<div class="resource-list col-12">
|
||||
<h5 class="mt-2">Tips</h5>
|
||||
<div class="container">
|
||||
<h5 class="mt-5 text-center">Resources</h5>
|
||||
<div class="resource-list row">
|
||||
{% for resource in submissions %}
|
||||
{% if resource.is_visible %}
|
||||
<a class="col-5 resource-card" href="{{ url_for('public.resource', resource_id=resource.id) }}">
|
||||
<a class="col resource-card" href="{{ url_for('public.resource', resource_id=resource.id) }}">
|
||||
<i title="{{resource.of_type}}"
|
||||
class="fa fa-{{resource.icon}}"></i>
|
||||
<b>{{resource.name}}</b>
|
||||
|
|
|
@ -292,13 +292,21 @@ class Event(PkModel):
|
|||
return format_date_range(self.starts_at, self.ends_at)
|
||||
|
||||
# Event categories
|
||||
def categories_for_event(self, event_id=None):
|
||||
if event_id is None: event_id = self.id
|
||||
def categories_for_event(self):
|
||||
return Category.query.filter(or_(
|
||||
Category.event_id==None,
|
||||
Category.event_id==event_id
|
||||
Category.event_id==-1,
|
||||
Category.event_id==self.id
|
||||
)).order_by('name')
|
||||
|
||||
# Event resources
|
||||
def resources_for_event(self):
|
||||
return Resource.query.filter(or_(
|
||||
Resource.event_id==None,
|
||||
Resource.event_id==0,
|
||||
Resource.event_id==self.id
|
||||
))
|
||||
|
||||
# Number of projects
|
||||
@property
|
||||
def project_count(self):
|
||||
|
|
Loading…
Reference in New Issue