These are chat archives for django/django

22nd
Jun 2017
Samuel Spencer
@LegoStormtroopr
Jun 22 2017 06:56
Adding themes to Django that are user-editable - (screencast included)
https://twitter.com/legostormtroopr/status/877769382599958528
:]
@elcolie
Jun 22 2017 09:13
Hi. I am doing a unittesting
class CarDataViewSetTestCase(APITestCase):
    def setUp(self):
        mommy.make(User, _quantity=1, username='sivabudh')
        mommy.make(CarData, _quantity=3,
                   brand='Ferrari',
                   color='black')
        self.client.force_login((User.objects.get(username='sivabudh')))

    def test_create(self):
        import pdb; pdb.set_trace()
        file_path = str(settings.ROOT_DIR.path('static_files/images/logo-eneos.png'))
        with open(file_path) as fp:
            data = {
                'brand': 'Ferrari',
                'model': 'LaFerrari Aperta',
                'color': 'Red',
                "attachment": fp
            }
            response = self.client.post(reverse('api:car-list'), data)
        assert 200 == response.status_code
My error is:
(Pdb) n
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
> /Users/el/Code/eneos-pos-web/eneos/apps/cars/tests.py(34)test_create()
-> response = self.client.post(reverse('api:car-list'), data)
Models.py
class CarData(AbstractSoftModelController):
    front_photo = models.ImageField(upload_to=RandomFileName('upload/cars'),
                                    blank=True,
                                    verbose_name=_('Front photo'))
    brand = models.CharField(max_length=255, db_index=True, verbose_name=_('Brand'))
    model = models.CharField(max_length=255, db_index=True, verbose_name=_('Model'))
    color = models.CharField(max_length=255,
                             blank=True,
                             db_index=True,
                             verbose_name=_('Color'))
Nicolas Couture
@ncouture
Jun 22 2017 09:52
@elcolie python2 ?
:]
@elcolie
Jun 22 2017 09:52
3.6.1 @ncouture
Nicolas Couture
@ncouture
Jun 22 2017 09:54
what happens if you post only the `fp' variable ?
:]
@elcolie
Jun 22 2017 10:02
One moment
    def test_create(self):
        file_path = str(settings.ROOT_DIR.path('static_files/images/logo-eneos.png'))
        with open(file_path, "r", encoding='utf-8', errors='ignore') as fp:
            data = {
                # 'brand': 'Ferrari',
                # 'model': 'LaFerrari Aperta',
                # 'color': 'Red',
                # 'license_plate': LicensePlate.objects.first().id,
                'front_photo': fp
            }
            response = self.client.post(reverse('api:car-list'), data, content_type='multipart')
        import pdb; pdb.set_trace()
        assert 200 == response.status_code
(Pdb) response.data
{'detail': 'Unsupported media type "multipart" in request.'}
@ncouture
Nicolas Couture
@ncouture
Jun 22 2017 10:06
awesome
:]
@elcolie
Jun 22 2017 10:08
@ncouture ???
Pavel Burns
@63phc
Jun 22 2017 10:49
How to test caching ?? Does he even work now?
:]
@elcolie
Jun 22 2017 11:45
@63phc Django ORM works by default and I normally reset_queries() to flush out the memory by myself. Otherwise I got Database is in recovery mode
Hubert
@hubert10
Jun 22 2017 15:39
hello I am faceting the following server error
TypeError: init() takes 1 positional argument but 2 were given
[22/Jun/2017 15:32:39] "POST /en/documents/37db83e7-6a81-4b6c-80ad-78baaab9ecf3/add/ HTTP/1.1" 500 102046
after method Post with Api here is mu view:
class DocumentAddView(generics.CreateAPIView):
""" A view that allows users to upload their documents"""
serializer_class = DocumentAddSerializer
lookup_field = 'profile_id'

def post(self, request, *args, **kwargs):

    serializer = DocumentAddSerializer(data=request.data)
    if not serializer.is_valid():
        return Response({_("invalid data")}, status=status.HTTP_400_BAD_REQUEST)
    serializer.save(created_by=request.user)
    return Response(serializer.data, status=status.HTTP_201_CREATED)
The document is well saved in the database but i get this error : Internal Server Error:
:]
@elcolie
Jun 22 2017 15:43
@hubert10 Try put import pdb; pdb.set_trace() to debug your code
Or send me your teleconsole code
Hubert
@hubert10
Jun 22 2017 15:44
image.png
:]
@elcolie
Jun 22 2017 15:45
line 39
Hubert
@hubert10
Jun 22 2017 15:46
image.png
yes i added line 39
:]
@elcolie
Jun 22 2017 15:48
How do you import Response? I can not see the entire header
Hubert
@hubert10
Jun 22 2017 15:48
this is my imports
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import F
from django.shortcuts import render
from rest_framework import status
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from django.shortcuts import render
from django.http import HttpResponse
from rest_framework.parsers import JSONParser
from django.http import JsonResponse
from documentsapp.serializers import
from django.views.decorators.csrf import csrf_exempt
from rest_framework import viewsets
from rest_framework import filters
from rest_framework import generics, mixins, exceptions
from documentsapp.models.document import Document
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.generics import GenericAPIView
from .serializers import

from drf_haystack.viewsets import HaystackViewSet
from profilesapp.views import ResultsSetPagination, SearchResultsPagination
from django.utils.translation import ugettextlazy as
import requests
from rest_framework.response import Response
:]
@elcolie
Jun 22 2017 15:49
Hmm
Hubert
@hubert10
Jun 22 2017 15:50
what am i missing?
:]
@elcolie
Jun 22 2017 15:56
@hubert10 https://www.teleconsole.com/
Can I remote your terminal?
I see it, but I have to make sure with pdb
s13g3lb4um
@s13g3lb4um
Jun 22 2017 16:47
Hi!
I want know how acces to mediafiles on production
Philip Eckert
@pae4557
Jun 22 2017 21:09

I have an interesting error: "form_valid() missing 1 required positional argument: 'form'" but I'm calling form_valid

self.form_valid(form)

where form is:

form:    <django.forms.formsets.FixtureCountFormFormSet object at 0x10a706630>
Why would it think I'm missing the positional argument 'form'? This is getting called from django.views.generic.edit in the post method
Marco Schanz
@fuuman
Jun 22 2017 23:33
Hey guys, I am a Rails Developer but In really love python and enjoying implement private projects with it. After all long time In finally found some time to take a look at Django. Is there any nice app template or boilerplate project that u can suggest? Would be awesome :)