Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
steering
Commits
4b432445
Commit
4b432445
authored
14 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
data migration, added Note import.
parent
bbbb87cf
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/management/commands/importnotes.py
+62
-0
62 additions, 0 deletions
program/management/commands/importnotes.py
with
62 additions
and
0 deletions
program/management/commands/importnotes.py
0 → 100644
+
62
−
0
View file @
4b432445
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ObjectDoesNotExist
,
MultipleObjectsReturned
from
django.core.management.base
import
NoArgsCommand
from
django.utils.html
import
clean_html
,
strip_tags
import
MySQLdb
from
program.models
import
Note
,
Show
,
TimeSlot
USER
=
'
helsinki
'
PASSWD
=
'
helsinki
'
DB
=
'
helsinki
'
OWNER
=
User
.
objects
.
get
(
pk
=
1
)
class
Command
(
NoArgsCommand
):
help
=
'
Import notes from current program
'
def
handle_noargs
(
self
,
**
options
):
connection
=
MySQLdb
.
connect
(
user
=
USER
,
passwd
=
PASSWD
,
db
=
DB
)
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"""
SELECT n.titel, n.datum, s.titel, n.notiz
FROM notizen AS n JOIN sendungen AS s ON n.sendung_id=s.id
WHERE n.sendung_id in (SELECT id FROM sendungen WHERE letzter_termin > current_date) AND n.titel !=
''"""
)
counter
=
0
for
ntitel
,
datum
,
stitel
,
notiz
in
cursor
.
fetchall
():
ntitel
=
strip_tags
(
ntitel
.
decode
(
'
latin1
'
).
encode
(
'
utf8
'
))
stitel
=
strip_tags
(
stitel
.
decode
(
'
latin1
'
).
encode
(
'
utf8
'
))
notiz
=
clean_html
(
notiz
.
decode
(
'
latin1
'
).
encode
(
'
utf8
'
))
if
stitel
.
endswith
(
'
(Wiederholung)
'
):
stitel
=
stitel
[:
-
15
]
if
datum
:
year
,
month
,
day
=
datum
.
year
,
datum
.
month
,
datum
.
day
try
:
show
=
Show
.
objects
.
get
(
name
=
stitel
)
try
:
timeslot
=
TimeSlot
.
objects
.
get
(
programslot__show
=
show
,
start__year
=
year
,
start__month
=
month
,
start__day
=
day
)
except
ObjectDoesNotExist
:
print
'
no timeslot found for sendung
"
%s
"
and datum
"
%s
"'
%
(
stitel
,
datum
)
except
MultipleObjectsReturned
:
print
'
multiple timeslots found for sendung
"
%s
"
and datum
"
%s
"'
%
(
stitel
,
datum
)
else
:
note
=
Note
(
timeslot
=
timeslot
,
owner
=
OWNER
,
title
=
ntitel
,
content
=
notiz
)
try
:
note
.
save
()
except
:
print
'
could not save note
"
%s
"
for show
"
%s
"'
%
(
ntitel
,
stitel
)
else
:
counter
+=
1
except
ObjectDoesNotExist
:
print
'
show with name
"
%s
"
not found
'
%
stitel
cursor
.
close
()
connection
.
close
()
print
'
%i notes imported
'
%
counter
\ No newline at end of file
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