mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 21:27:49 +02:00
Add a CSV export functionality in admin and add price fields (#41)
* Implement an action do download data in csv * Refactor CSV download * Move price to main models and add csv to bookshelf * Update template and API * Small refactoring
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from ram.utils import git_suffix
|
||||
|
||||
__version__ = "0.14.3"
|
||||
__version__ = "0.15.0"
|
||||
__version__ += git_suffix(__file__)
|
||||
|
@@ -170,6 +170,9 @@ SITE_NAME = "Railroad Assets Manger"
|
||||
# The file must be placed in the root of the 'static' folder
|
||||
DEFAULT_CARD_IMAGE = "coming_soon.svg"
|
||||
|
||||
CSV_SEPARATOR = ","
|
||||
CSV_SEPARATOR_ALT = ";"
|
||||
|
||||
DECODER_INTERFACES = [
|
||||
(0, "Built-in"),
|
||||
(1, "NEM651"),
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import os
|
||||
import csv
|
||||
import hashlib
|
||||
import subprocess
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse
|
||||
from django.utils.html import format_html
|
||||
from django.utils.text import slugify as django_slugify
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
@@ -57,3 +60,15 @@ def slugify(string, custom_separator=None):
|
||||
if custom_separator is not None:
|
||||
string = string.replace("-", custom_separator)
|
||||
return string
|
||||
|
||||
|
||||
def generate_csv(header, data, filename, separator=settings.CSV_SEPARATOR):
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response["Content-Disposition"] = 'attachment; filename="{}"'.format(
|
||||
filename
|
||||
)
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(header)
|
||||
for row in data:
|
||||
writer.writerow(row)
|
||||
return response
|
||||
|
Reference in New Issue
Block a user