Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TIC-Desk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Teckids
TIC-Desk
Commits
b9a5fbad
Verified
Commit
b9a5fbad
authored
7 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Use working query for birthdays on date column.
parent
0a220627
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ticdesk_account/cron.py
+21
-15
21 additions, 15 deletions
ticdesk_account/cron.py
with
21 additions
and
15 deletions
ticdesk_account/cron.py
+
21
−
15
View file @
b9a5fbad
...
...
@@ -6,7 +6,7 @@ from django_cron import CronJobBase, Schedule
from
ldap
import
INVALID_SYNTAX
from
.models
import
TeckidsGroup
,
TeckidsPerson
from
ticdesk_org.util
import
may_see
_person
from
ticdesk_org.util
import
filter_disallowed
_person
s
class
CleanGroups
(
CronJobBase
):
RUN_EVERY_MINS
=
5
...
...
@@ -54,28 +54,34 @@ class BirthdayMails(CronJobBase):
# Get persons who subscribed to birthday mails
persons
=
TeckidsPerson
.
objects
.
filter
(
setting_birthday_mail_days__gte
=
1
).
all
()
# Get minimum year of birth
today
=
date
.
today
()
min_year
=
TeckidsPerson
.
objects
.
filter
(
date_of_birth__lte
=
today
).
order_by
(
'
date_of_birth
'
).
first
().
date_of_birth
.
year
for
person
in
persons
:
today
=
date
.
today
()
last
=
today
+
timedelta
(
days
=
person
.
setting_birthday_mail_days
)
# Get persons who have their birthday in that period
birthday_persons
=
[]
for
delta
in
range
(
0
,
person
.
setting_birthday_mail_days
+
1
):
day
=
today
+
timedelta
(
days
=
delta
)
birthday_persons
+=
TeckidsPerson
.
objects
.
filter
(
date_of_birth__endswith
=
day
.
strftime
(
'
-%m-%d
'
)
).
order_by
(
'
date_of_birth_str
'
).
all
()
# Iterate over persons and check read access
matching_persons
=
[
birthday_person
for
birthday_person
in
birthday_persons
if
may_see_person
(
birthday_person
,
person
)]
if
matching_persons
:
dates
=
[]
for
year
in
range
(
min_year
,
today
.
year
+
1
):
for
delta
in
range
(
0
,
person
.
setting_birthday_mail_days
+
1
):
day
=
today
+
timedelta
(
days
=
delta
)
dates
.
append
(
date
(
year
=
year
,
month
=
day
.
month
,
day
=
day
.
day
))
birthday_persons
=
filter_disallowed_persons
(
TeckidsPerson
.
objects
.
filter
(
date_of_birth__in
=
dates
).
order_by
(
'
date_of_birth
'
).
all
(),
person
)
if
birthday_persons
:
# Generate mail
last
=
today
+
timedelta
(
days
=
person
.
setting_birthday_mail_days
)
message
=
EmailMessage
()
message
.
to
=
[
person
.
mail
]
message
.
subject
=
_
(
'
Geburtstage von %s bis %s
'
)
%
(
str
(
today
),
str
(
last
))
message
.
body
=
_
(
'
Hallo %s,
\n\n
die folgenden Personen haben in nächster Zeit Geburtstag:
\n\n
'
)
%
person
.
given_name
for
birthday_person
in
matching
_persons
:
for
birthday_person
in
birthday
_persons
:
message
.
body
+=
_
(
'
%s
\t
%s (%s Jahre)
\n
'
)
%
(
str
(
birthday_person
.
date_of_birth
),
birthday_person
.
cn
,
str
(
birthday_person
.
age_at
(
last
))
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment