Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- Merged with master branch
- Fixed translations
- Added a toast on the bast.html file
- Added toast while changing mail subscription
  • Loading branch information
orronai committed Oct 11, 2021
commit b741e53f536535e9cd38851d213ca61fb1519268
59 changes: 37 additions & 22 deletions lms/lmsweb/translations/he/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2021-10-10 11:43+0300\n"
"POT-Creation-Date: 2021-10-11 10:38+0300\n"
"PO-Revision-Date: 2021-09-29 11:30+0300\n"
"Last-Translator: Or Ronai\n"
"Language: he\n"
Expand All @@ -18,7 +18,7 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.9.1\n"

#: lmsdb/models.py:943
#: lmsdb/models.py:951
msgid "Fatal error"
msgstr "כישלון חמור"

Expand Down Expand Up @@ -75,6 +75,22 @@ msgstr "קישור לאיפוס הסיסמה נשלח בהצלחה"
msgid "Reset password link is expired"
msgstr "קישור איפוס הסיסמה פג תוקף"

#: lmsweb/views.py:376 templates/user.html:23
msgid "Mail Subscription"
msgstr "מנוי להודעות דוא\"ל"

#: lmsweb/views.py:378
msgid "You've successfully subscribed to get mails for new notifications"
msgstr "נרשמת בהצלחה לקבלת הודעות דוא\"ל עבור התראות חדשות"

#: lmsweb/views.py:383
msgid "You've successfully unsubscribed to get mails for new notifications"
msgstr "ביטלת בהצלחה את ההרשמה לקבלת הודעות דוא\"ל עבור התראות חדשות"

#: lmsweb/views.py:388
msgid "Something went wrong..."
msgstr "משהו השתבש..."

#: lmsweb/forms/change_password.py:20 lmsweb/forms/register.py:32
#: lmsweb/forms/reset_password.py:25
msgid "The passwords are not identical"
Expand Down Expand Up @@ -124,7 +140,7 @@ msgstr "שם המשתמש או הסיסמה שהוזנו לא תקינים"
msgid "You have to confirm your registration with the link sent to your email"
msgstr "עליך לאשר את מייל האימות"

#: models/users.py:50
#: models/users.py:61
#, python-format
msgid "You are already registered to %(course_name)s course."
msgstr "אתה כבר רשום לקורס %(course_name)s."
Expand Down Expand Up @@ -253,7 +269,6 @@ msgid "Logout"
msgstr "התנתקות"

#: templates/public-courses.html:6
#, fuzzy
msgid "Public Courses List"
msgstr "רשימת קורסים פתוחים"

Expand Down Expand Up @@ -303,7 +318,7 @@ msgstr "חמ\"ל תרגילים"
msgid "Name"
msgstr "שם"

#: templates/status.html:13 templates/user.html:50
#: templates/status.html:13 templates/user.html:53
msgid "Checked"
msgstr "נבדק/ו"

Expand Down Expand Up @@ -351,63 +366,63 @@ msgstr "פרטי משתמש"
msgid "Actions"
msgstr "פעולות"

#: templates/user.html:23
msgid "Mail Subscription"
msgstr "מינוי להודעות דוא\"ל"
#: templates/user.html:27
msgid "Join Courses"
msgstr "הירשם לקורסים"

#: templates/user.html:30
#: templates/user.html:33
msgid "Exercises Submitted"
msgstr "תרגילים שהוגשו"

#: templates/user.html:35
#: templates/user.html:38
msgid "Course name"
msgstr "שם קורס"

#: templates/user.html:36
#: templates/user.html:39
msgid "Exercise name"
msgstr "שם תרגיל"

#: templates/user.html:37
#: templates/user.html:40
msgid "Submission status"
msgstr "מצב הגשה"

#: templates/user.html:38
#: templates/user.html:41
msgid "Submission"
msgstr "הגשה"

#: templates/user.html:39
#: templates/user.html:42
msgid "Checker"
msgstr "בודק"

#: templates/user.html:40 templates/view.html:25 templates/view.html:112
#: templates/user.html:43 templates/view.html:25 templates/view.html:112
msgid "Assessment"
msgstr "הערה מילולית"

#: templates/user.html:50
#: templates/user.html:53
msgid "Submitted"
msgstr "הוגש"

#: templates/user.html:50
#: templates/user.html:53
msgid "Not submitted"
msgstr "לא הוגש"

#: templates/user.html:62
#: templates/user.html:65
msgid "Notes"
msgstr "פתקיות"

#: templates/user.html:67 templates/user.html:69
#: templates/user.html:70 templates/user.html:72
msgid "New Note"
msgstr "פתקית חדשה"

#: templates/user.html:73
#: templates/user.html:76
msgid "Related Exercise"
msgstr "תרגיל משויך"

#: templates/user.html:82
#: templates/user.html:85
msgid "Privacy Level"
msgstr "רמת פרטיות"

#: templates/user.html:88
#: templates/user.html:91
msgid "Add Note"
msgstr "הוסף פתקית"

Expand Down
15 changes: 14 additions & 1 deletion lms/lmsweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,20 @@ def read_all_notification():
@webapp.route('/mail/<subscription>', methods=['PATCH'])
def mail_subscription(subscription: str):
success_state = users.change_mail_subscription(current_user, subscription)
return jsonify({'success': success_state})
title = _('Mail Subscription')
if subscription == 'subscribe':

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move 'subscribe' and 'unsubscribe' to enum and replace the usage

body = _(
"You've successfully subscribed to get mails "
'for new notifications',
)
elif subscription == 'unsubscribe':
body = _(
"You've successfully unsubscribed to get mails "
'for new notifications',
)
else:
body = _('Something went wrong...')
return jsonify({'success': success_state, 'title': title, 'body': body})


@webapp.route('/share', methods=['POST'])
Expand Down
13 changes: 13 additions & 0 deletions lms/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ def change_mail_subscription(user: User, subscription: str) -> bool:
return False
user.save()
return True


def join_public_course(course: Course, user: User) -> None:
__, created = UserCourse.get_or_create(**{
UserCourse.user.name: user, UserCourse.course.name: course,
})
if not created:
raise AlreadyExists(
_(
'You are already registered to %(course_name)s course.',
course_name=course.name,
), 409,
)
30 changes: 27 additions & 3 deletions lms/static/my.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,41 @@ function trackReadAllNotificationsButton(button) {
});
}

function subscriptionToast(toastObject, title, body) {
const today = new Date().toLocaleString();
document.getElementById('toast-strong').innerHTML = title;
document.getElementById('toast-small').innerHTML = today;
document.getElementById('toast-body').innerHTML = body;
const toast = new bootstrap.Toast(toastObject);
toast.show()
}

function trackMailSubscriptionCheckbox() {
const checkbox = document.getElementById('mail-subscription-checkbox');
const toastObject = document.getElementById('toast');
if (checkbox === null) {
return;
}

checkbox.addEventListener('change', (e) => {
const subscription = (e.currentTarget.checked) ? 'subscribe' : 'unsubscribe';
const request = new XMLHttpRequest();
request.open('PATCH', `/mail/${subscription}`);
return request.send();
const xhr = new XMLHttpRequest();
xhr.open('PATCH', `/mail/${subscription}`);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.responseType = 'json';
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not === 5? please make move 4 to indicative variable name

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same as all the other xhr's in the JS files

if (xhr.status === 200) {
const title = xhr.response.title;
const body = xhr.response.body;
subscriptionToast(toastObject, title, body);
} else {
console.log(xhr.status);
}
}
};
xhr.send('');
return xhr;
});
}

Expand Down
13 changes: 12 additions & 1 deletion lms/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@
</head>
<body>
{% include 'navbar.html' %}
{% block page_content %}{% endblock %}
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
<div id="toast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong id="toast-strong" class="me-auto"></strong>
<small id="toast-small"></small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div id="toast-body" class="toast-body"></div>
</div>
</div>
{% block page_content %}
{% endblock %}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions lms/templates/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ <h2>{{ _('Actions') }}:</h2>
{{ _('Mail Subscription') }}
</label>
</div>
{% if public_course_exists %}
<li><a href="{{ url_for('public_courses') }}" role="button">{{ _('Join Courses') }}</a></li>
{% endif %}
</ul>
</div>
</div>
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.