Skip to content

Instantly share code, notes, and snippets.

View AndreasDickow's full-sized avatar
🎯
Focusing

BIZ Factory GmbH AndreasDickow

🎯
Focusing
View GitHub Profile
@AndreasDickow
AndreasDickow / settings.component.ts
Created August 9, 2017 10:07
Ionic2 File Upload to Django Rest Framework
let options: FileUploadOptions = {
fileKey: 'image',
fileName: this.result.substr(this.result.lastIndexOf('/') + 1),
mimeType : 'image/jpeg',
httpMethod : "PUT",
headers: {Authorization: this._variableService.getToken(),}
}
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.upload(this.result, encodeURI(this._variableService.getBaseUrl() + '/api/v2/profile_image/'+this.result.substr(this.result.lastIndexOf('/') + 1)), options)
@AndreasDickow
AndreasDickow / views.py
Created August 9, 2017 10:08
Ionic2 file Upload to Django Rest Framework
class ProfileImageUploadView(views.APIView):
parser_classes = (FileUploadParser,)
permission_classes = (IsAccountOwner,)
def put(self, request, filename, format=None):
file_obj = request.data['file']
if not request.user.is_anonymous():
profile = request.user.profile
profile.profile_image = file_obj
profile.save()
@AndreasDickow
AndreasDickow / settings.component.ts
Created August 9, 2017 10:15
Angular2 Image Upload to Django Rest Framework
let header = this._variableService.getToken();
let input = new FormData();
input.append("username", this.profileForm.controls['username'].value);
input.append("status", this.profileForm.controls['status'].value);
input.append("city", this.profileForm.controls['city'].value);
input.append("want_news", this.profileForm.controls['want_news'].value);
input.append("want_notifications", this.profileForm.controls['want_notifications'].value);
if (this.result !== null) {
@AndreasDickow
AndreasDickow / UploadService.ts
Created August 9, 2017 10:16
Angular2 Image Upload to Django Rest Framework with Form Data
@Injectable()
export class UploadService {
/**
* @param Observable<number>
*/
private progress$: Observable<number>;
/**
* @type {number}
*/
@AndreasDickow
AndreasDickow / views.py
Created August 9, 2017 10:19
Angular2 Image Upload to Django Rest Framework with FormData
class ProfileViewSet(viewsets.ModelViewSet):
parsers = [parsers.MultiPartParser, parsers.FormParser]
queryset = Profile.objects.all()
serializer_class = ProfileSerializer
permission_classes = [
user_permissions.IsProfileOwner
]
@AndreasDickow
AndreasDickow / imagetools.py
Created August 11, 2017 08:59
PIL EXIF Fix for all 9 orientations
EXIF_ORIENTATION = 0x0112
def _orientation(image):
ret = {}
try:
info = image._getexif()
if info:
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
@AndreasDickow
AndreasDickow / filters.py
Created August 18, 2017 09:36
Django Rest Filter exclude CSV in url
class NumberInFilter(django_filters.BaseInFilter, django_filters.NumberFilter):
pass
class UsernameFilter(filters.FilterSet):
username = django_filters.CharFilter(lookup_expr='icontains')
id = NumberInFilter(name='id', lookup_expr='in',exclude=True)
class Meta:
model = User
fields = ['username','id']
@AndreasDickow
AndreasDickow / app.scss
Created August 18, 2017 16:15
Fix IOS ionic2 app flicker when ion-input focused and keyboard typing
ion-app > .app-root > ion-nav > registerview > ion-content > .scroll-content,
ion-app > .app-root > ion-nav > creategroupview > ion-content > .scroll-content{
-webkit-overflow-scrolling: initial;
will-change: initial;
}
@AndreasDickow
AndreasDickow / variable.service.ts
Created September 12, 2017 10:01
Ionic2 check if Component is already in Navigation Stack
isAlready(name:string):number{
if(name in this.viewcomponents)
{
let comp = this.viewcomponents[name];
let views = this.nav.getViews();
return views.map(function(x) {return x.component; }).indexOf(comp);
}
return -1;
@AndreasDickow
AndreasDickow / Apache FOP Maven Dependency Issues.md
Last active April 3, 2019 15:21
Solves dependency issues when adding apache fop to maven project

If you get errors like serializer.jar (No such file or directory) or xbean.jar (No such file or directory) when running a maven project with Apache FOP Usage , then try to change

<dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>fop</artifactId>
            <version>2.3</version>
</dependency>

to