Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add import/export functionality to the API
- Loading branch information
Showing
27 changed files
with
512 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be> | ||
# Copyright (C) 2014 Jesús Espino <jespinog@gmail.com> | ||
# Copyright (C) 2014 David Barragán <bameda@dbarragan.com> | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import datetime | ||
|
||
from django.core.files.storage import default_storage | ||
from django.core.files.base import ContentFile | ||
from django.utils import timezone | ||
from django.conf import settings | ||
|
||
from djmail.template_mail import MagicMailBuilder | ||
|
||
from taiga.celery import app | ||
|
||
from .service import project_to_dict | ||
from .dump_service import dict_to_project | ||
from .renderers import ExportRenderer | ||
|
||
|
||
@app.task(bind=True) | ||
def dump_project(self, user, project): | ||
mbuilder = MagicMailBuilder() | ||
|
||
path = "exports/{}/{}.json".format(project.pk, self.request.id) | ||
|
||
try: | ||
content = ContentFile(ExportRenderer().render(project_to_dict(project), renderer_context={"indent": 4}).decode('utf-8')) | ||
default_storage.save(path, content) | ||
url = default_storage.url(path) | ||
except Exception: | ||
email = mbuilder.export_import_error( | ||
user.email, | ||
{ | ||
"user": user, | ||
"error_subject": "Error generating project dump", | ||
"error_message": "Error generating project dump", | ||
} | ||
) | ||
email.send() | ||
return | ||
|
||
deletion_date = timezone.now() + datetime.timedelta(seconds=settings.EXPORTS_TTL) | ||
email = mbuilder.dump_project(user.email, {"url": url, "project": project, "user": user, "deletion_date": deletion_date}) | ||
email.send() | ||
|
||
@app.task | ||
def delete_project_dump(project_id, task_id): | ||
default_storage.delete("exports/{}/{}.json".format(project_id, task_id)) | ||
|
||
@app.task | ||
def load_project_dump(user, dump): | ||
mbuilder = MagicMailBuilder() | ||
|
||
try: | ||
project = dict_to_project(dump, user.email) | ||
except Exception: | ||
email = mbuilder.export_import_error( | ||
user.email, | ||
{ | ||
"user": user, | ||
"error_subject": "Error loading project dump", | ||
"error_message": "Error loading project dump", | ||
} | ||
) | ||
email.send() | ||
return | ||
|
||
email = mbuilder.load_dump(user.email, {"user": user, "project": project}) | ||
email.send() |
28 changes: 28 additions & 0 deletions
28
taiga/export_import/templates/emails/dump_project-body-html.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% extends "emails/base.jinja" %} | ||
|
||
{% block body %} | ||
<table border="0" width="100%" cellpadding="0" cellspacing="0" class="table-body"> | ||
<tr> | ||
<td> | ||
<h1>Project dump generated</h1> | ||
<p>Hello {{ user.get_full_name() }},</p> | ||
<h3>Your project dump has been correctly generated.</h3> | ||
<p>You can download it from here: <a style="color: #669900;" href="{{ url }}">{{ url }}</a></p> | ||
<p>This file will be deleted on {{ deletion_date|date("r") }}.</p> | ||
<p>The Taiga Team</p> | ||
</td> | ||
</tr> | ||
</table> | ||
{% endblock %} | ||
|
||
{% block footer %} | ||
<em>Copyright © 2014 Taiga Agile, LLC, All rights reserved.</em> | ||
<br> | ||
<strong>Contact us:</strong> | ||
<br> | ||
<strong>Support:</strong> | ||
<a href="mailto:support@taiga.io" title="Taiga Support">support@taiga.io</a> | ||
<br> | ||
<strong>Our mailing address is:</strong> | ||
<a href="https://groups.google.com/forum/#!forum/taigaio" title="Taiga mailing list">https://groups.google.com/forum/#!forum/taigaio</a> | ||
{% endblock %} |
Oops, something went wrong.