diff --git a/dribdat/public/forms.py b/dribdat/public/forms.py index 7af94988..e9976a6c 100644 --- a/dribdat/public/forms.py +++ b/dribdat/public/forms.py @@ -8,6 +8,7 @@ StringField, TextAreaField, SelectField, + SelectMultipleField, HiddenField, ) from wtforms.fields import TimeField, DateField, URLField, DateTimeLocalField @@ -163,6 +164,9 @@ class ProjectPost(FlaskForm): id = HiddenField("id") has_progress = BooleanField("Level up") + roles = SelectMultipleField( + "Roles", coerce=int, description="Choose one or more team roles for yourself." + ) note = TextAreaField( "How are the vibes in your team right now?", [length(max=1024)], diff --git a/dribdat/public/project.py b/dribdat/public/project.py index 0a807c4b..a852702b 100644 --- a/dribdat/public/project.py +++ b/dribdat/public/project.py @@ -205,6 +205,10 @@ def project_post(project_id): stage, all_valid = validateProjectData(project) form = ProjectPost(obj=project, next=request.args.get("next")) + # Populate roles + from dribdat.user.models import Role + form.roles.choices = [(r.id, r.name) for r in Role.query.order_by("name")] + # Apply random questions form.note.label.text = drib_question() @@ -214,6 +218,9 @@ def project_post(project_id): # if form.is_submitted() and timelimit(thelastact): # flash("Please wait a minute before posting", 'warning') + if not form.is_submitted(): + form.roles.data = [r.id for r in current_user.roles] + if form.is_submitted() and not form.note.data: # Empty submission flash("Please add something to your note", "warning") @@ -224,9 +231,17 @@ def project_post(project_id): if stageProjectToNext(project): flash("Level up! You are at stage '%s'" % project.phase, "info") + # Update user roles + new_roles = Role.query.filter(Role.id.in_(form.roles.data)).all() + if set(new_roles) != set(current_user.roles): + current_user.roles = new_roles + current_user.save() + project_action(project_id, "update", action="post", text="🔄 Role swap") + # Update project data del form.id del form.has_progress + del form.roles # Process form form.populate_obj(project) project.update_now() diff --git a/dribdat/templates/public/projectlog.html b/dribdat/templates/public/projectlog.html index 4dca8b55..ae051082 100644 --- a/dribdat/templates/public/projectlog.html +++ b/dribdat/templates/public/projectlog.html @@ -138,6 +138,11 @@

{{s.title}}

{{ s.author }} + {% if s.user_roles %} + {% for r in s.user_roles %} + {{r[0]|upper}} + {% endfor %} + {% endif %} {% endif %} {% if s.ref_url %} diff --git a/dribdat/templates/public/projectpost.html b/dribdat/templates/public/projectpost.html index e9f7dd05..52087982 100644 --- a/dribdat/templates/public/projectpost.html +++ b/dribdat/templates/public/projectpost.html @@ -111,7 +111,72 @@

{% if stage %} - {{ render_form(url_for('project.project_post', project_id=project.id), form, formid='projectPost') }} +
+ {{ form.hidden_tag() }} +
+ {{ form.has_progress(class_="form-check-input") }} + {{ form.has_progress.label(class_="form-check-label") }} + {% if form.has_progress.errors %} +
    + {% for error in form.has_progress.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ + + +
+ +
+ {{ form.note(class_="form-control", rows="3") }} + {{ form.note.description }} + {% if form.note.errors %} +
    + {% for error in form.note.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+
+ +
+
+ {{ form.submit(class_="btn btn-primary") }} + + + Swap role + +
+
+
+ {% else %} {{ render_form(url_for('project.project_comment', project_id=project.id), form, formid='projectPost') }} {% endif %} @@ -135,6 +200,11 @@

{{ s.author }} + {% if s.user_roles %} + {% for r in s.user_roles %} + {{r[0]|upper}} + {% endfor %} + {% endif %} {% endif %}

diff --git a/dribdat/user/models.py b/dribdat/user/models.py index 09fa1689..0513c3b2 100644 --- a/dribdat/user/models.py +++ b/dribdat/user/models.py @@ -1096,6 +1096,7 @@ def all_dribs(self, limit=50, by_name=None, only_posts=False): "title": title, "text": text, "author": author, + "user_roles": a.data.get("user_roles"), "name": a.name, "date": a.timestamp, "timesince": a.data["timesince"], @@ -1455,7 +1456,10 @@ class Activity(PkModel): @property def data(self): """Get JSON representation.""" - localtime = self.timestamp.replace(tzinfo=current_app.tz) # pyright: ignore + try: + localtime = self.timestamp.replace(tzinfo=current_app.tz) # pyright: ignore + except Exception: + localtime = self.timestamp a = { "id": self.id, "time": int(mktime(self.timestamp.timetuple())), @@ -1469,6 +1473,7 @@ def data(self): if self.user: a["user_id"] = self.user.id a["user_name"] = self.user.username + a["user_roles"] = [r.name for r in self.user.roles] if self.project: a["project_id"] = self.project.id a["project_name"] = self.project.name diff --git a/flask.log b/flask.log new file mode 100644 index 00000000..99d02a0a Binary files /dev/null and b/flask.log differ