Skip to content

Instantly share code, notes, and snippets.

Nicolai nspo

  • Karlsruhe, Germany
Block or report user

Report or block nspo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nspo
nspo / pdfcrop5multi
Created Nov 17, 2019
Automatically crop list of PDF files in place (no copy)
View pdfcrop5multi
#!/bin/bash
for file in "$@"; do
echo "--- [$file]"
echo "- Cropping $file..."
pdfcrop --margin 5 $file /tmp/PDFCROP_TEMP.pdf
if [ $? -eq 0 ]; then
# success
echo "- Conversion successful. Replacing original file $file."
mv /tmp/PDFCROP_TEMP.pdf $file
View Example
line 1 a
line 2
line 3
@nspo
nspo / settings.py of site1
Created Mar 30, 2018
Running multiple Django projects on one Apache instance with mod_wsgi
View settings.py of site1
STATIC_URL = '/site1/static/'
# adjust name of session id
SESSION_COOKIE_NAME = "site1"
@nspo
nspo / custom-validation-inlineformset.py
Created Apr 21, 2017
Custom validation of Django inline formset
View custom-validation-inlineformset.py
class ProductAutochangeInlineFormSet(
forms.inlineformset_factory(ProductAutochangeSet, ProductAutochange, form=ProductAutochangeForm, extra=1)):
def clean(self):
super(ProductAutochangeInlineFormSet, self).clean()
product_pks = []
num_productautochanges = 0
for form in self.forms:
if not form.is_valid():
continue
@nspo
nspo / django-detailview-with-extra-pagination.py
Last active Apr 3, 2020
Django DetailView with pagination for related objects
View django-detailview-with-extra-pagination.py
# A DetailView of a User can have a paginated list of Purchases
# In the template, the pagination needs to done similar to the following example:
# {% bootstrap_pagination purchases_page_obj extra=request.GET.urlencode parameter_name="purchases_page" %}
from django.views.generic.detail import DetailView
from django.core import paginator
@method_decorator(staff_member_required(login_url='user_login'), name='dispatch')
class UserDetailView(DetailView):
model = User
@nspo
nspo / export-django-filters-filterview-to-csv.py
Last active Mar 31, 2018
Export object_list of a django-filters FilterView to CSV
View export-django-filters-filterview-to-csv.py
# Normal View (has a link to export view and keeps GET parameters)
@method_decorator(staff_member_required(login_url='user_login'), name='dispatch')
class PaymentListView(FilterView):
filterset_class = filters.PaymentFilter
template_name = "barsys/userarea/payment_list.html"
paginate_by = 10
# Export View
@method_decorator(staff_member_required(login_url='user_login'), name='dispatch')
class PaymentExportView(FilterView):
@nspo
nspo / NoEditForeignTablesInlineMixin.py
Created Apr 7, 2017
Don't show buttons to add/change/delete a ForeignKey element of a model in form (tested in admin form)
View NoEditForeignTablesInlineMixin.py
class NoEditForeignTablesInlineMixin(object):
""" Don't show links to add/edit/delete foreign key element besides ForeignKey selection in forms """
no_edit_foreign_tables_in_form = []
def get_form(self, request, obj=None, **kwargs):
"""
Don't allow adding/changing/deleting users inline
"""
form = super(NoEditForeignTablesInlineMixin, self).get_form(request, obj, **kwargs)
for key in self.no_edit_foreign_tables_in_form:
View ActivityNotFoundException.patch
From ff4af50a4326956672989b335c21520189b6b49b Mon Sep 17 00:00:00 2001
From: Nicolai Spohrer <nicolai@xeve.de>
Date: Wed, 20 Mar 2013 15:20:31 +0100
Subject: [PATCH 1/2] Fix unhandled ActivityNotFoundException if no Play Store
is installed on device (e.g. emulator)
---
AppRate/src/com/tjeannin/apprate/AppRate.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
View 0001-Fix-unhandled-ActivityNotFoundException-if-no-Play-S.patch
From ff4af50a4326956672989b335c21520189b6b49b Mon Sep 17 00:00:00 2001
From: Nicolai Spohrer <nicolai@xeve.de>
Date: Wed, 20 Mar 2013 15:20:31 +0100
Subject: [PATCH] Fix unhandled ActivityNotFoundException if no Play Store is
installed on device (e.g. emulator)
---
AppRate/src/com/tjeannin/apprate/AppRate.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
View 0001-Fix-unhandled-ActivityNotFoundException-if-no-Play-S.patch
From 593ff8b6a854df5cf3695dd571592cca8e204075 Mon Sep 17 00:00:00 2001
From: Nicolai Spohrer <nicolai@xeve.de>
Date: Wed, 20 Mar 2013 15:08:00 +0100
Subject: [PATCH] Fix unhandled ActivityNotFoundException if no Play Store is
installed on device (e.g. emulator)
---
AppRate/src/com/tjeannin/apprate/AppRate.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
You can’t perform that action at this time.