Skip to content
Snippets Groups Projects
Commit a28996c2 authored by Martin Mareš's avatar Martin Mareš
Browse files

Unified processing of last change times of posts

parent df257c9e
Branches
No related tags found
No related merge requests found
......@@ -119,7 +119,7 @@ def send_notify_to_dest(post: db.Post, topic: db.Topic, course: db.Course, autho
msg['From'] = email.headerregistry.Address(display_name=author.full_name() + " via Owl", addr_spec=app.config['MAIL_FROM'])
msg['To'] = email.headerregistry.Address(display_name=dest.full_name(), addr_spec=dest.email)
msg['Subject'] = f'Owl: {topic.title}'
msg['Date'] = (post.modified or post.created).astimezone()
msg['Date'] = post.last_change_time().astimezone()
if 'MAIL_REFERENCES' in app.config:
# Everybody gets his own view of the thread, so the target is the observer's uid
msg['References'] = '<' + app.config['MAIL_REFERENCES'].format(tid=post.tid, target=dest.uid) + '>'
......
......@@ -174,9 +174,8 @@ def topic_index(sident: str, cident: str, tident: str, student_uid: Optional[int
topic=g.topic)
)
post_times = [p.created for p in posts] + [p.modified for p in posts if p.modified is not None]
if post_times:
last_post_time = max(post_times)
if posts:
last_post_time = max(p.last_change_time() for p in posts)
if seen is None or seen < last_post_time:
form.ack_time.data = last_post_time
......
# SQLAlchemy definitions of all tables in the database
# Generated by sqlacodegen and then heavily edited.
import datetime
from sqlalchemy import Boolean, CHAR, Column, DateTime, ForeignKey, Integer, Numeric, String, Text, UniqueConstraint, text
from sqlalchemy.orm import relationship, Session
from sqlalchemy.ext.declarative import declarative_base
......@@ -116,6 +117,12 @@ class Post(Base):
target = relationship('User', primaryjoin='Post.target_uid == User.uid')
topic = relationship('Topic')
def last_change_time(self) -> datetime.datetime:
if self.modified is not None:
return self.modified
else:
return self.created
class Seen(Base):
__tablename__ = 'owl_seen'
......
......@@ -87,10 +87,9 @@ def teacher(sident: str, cident: str):
sol = solutions[p.target_uid][p.tid]
if p.points is not None:
sol.points = p.points
if sol.last_activity is None or sol.last_activity < p.created:
sol.last_activity = p.created
if p.modified is not None and sol.last_activity < p.modified:
sol.last_activity = p.modified
mtime = p.last_change_time()
if sol.last_activity is None or sol.last_activity < mtime:
sol.last_activity = mtime
totals: Dict[int, Decimal] = {}
for u in solutions.keys():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment