These are chat archives for django/django

11th
Apr 2016
Filip Figiel
@megapctr
Apr 11 2016 05:19
Just restart the server
Alexey Rogachev
@arogachev
Apr 11 2016 06:29
Hi all. I am trying to use this library https://github.com/jonasundderwolf/django-image-cropping with some custom javascript
I included it according readme, custom js is included like this:
class PostAdmin(ImageCroppingMixin, admin.ModelAdmin):
    exclude = ('views_count',)
    list_display = ('name', 'category', 'published_at')

    class Media:
        js = ('js/jcrop_custom.js',)
the problem is custom.js is included before jcrop and library js. How to solve it? I saw some advices about overriding template, but is it possible via class level?
Alexey Rogachev
@arogachev
Apr 11 2016 06:40
I need to include it after since it depends on jcrop
Filip Figiel
@megapctr
Apr 11 2016 06:58
You can wrap custom js code in
setTimeout(function() {}, 0)
I never liked delegating asset handling to django though
I just include the asset in the pages that need it
Puneet Aggarwal
@puneetagg
Apr 11 2016 07:49
@bittner Ok. Thanks!! Also, what should I prefer to use to get data from social site like Facebook, JavaScript SDK or backend CURL requests?
Alexey Rogachev
@arogachev
Apr 11 2016 08:03
@megapctr Thanks for advice, I found something similar, but this looks like a hack
What the alternatives are?
I found the place where these files are included, this class is called CropWidget. Maybe it's possible somehow to set the dependency on it or merge media in right order
@puneetagg If site has API, then use it. If not - this is task for web scraping / parsing
Alexey Rogachev
@arogachev
Apr 11 2016 08:10
@megapctr Could you share in this case the method you are using and prefer?
In admin for example?
in framework I used before there are asset bundles for working with assets, we can set list of dependent assets such as links and other bundles, I expected something similar in Django
Alexey Rogachev
@arogachev
Apr 11 2016 08:15
@megapctr Do you create a template for every page and then include it here? Or include all in main layout (template)?
Filip Figiel
@megapctr
Apr 11 2016 08:37
@arogachev I put page-specific js files in their respective templates
Alexey Rogachev
@arogachev
Apr 11 2016 08:39
Could you provide an example how to do it for admin?
Filip Figiel
@megapctr
Apr 11 2016 08:40
I don't use admin, sorry
hmm, you could add some data-* html attribute to the elements that need to be cropped
and update the js to select only such elements
Alexey Rogachev
@arogachev
Apr 11 2016 08:41
Why?
Filip Figiel
@megapctr
Apr 11 2016 08:41
then you can run the script globally
@arogachev because it's not relevant in my app :)
Alexey Rogachev
@arogachev
Apr 11 2016 08:42
Do you use other extension?
Filip Figiel
@megapctr
Apr 11 2016 08:42
that's not what I meant
Alexey Rogachev
@arogachev
Apr 11 2016 08:42
I thought the admin is the main advantage of django
Filip Figiel
@megapctr
Apr 11 2016 08:42
yes, django admin is pretty awesome
Alexey Rogachev
@arogachev
Apr 11 2016 08:42
that will not help
because I need to change minSize option
Filip Figiel
@megapctr
Apr 11 2016 08:43
though my django app is rather a frontend + utils for external library
as you can see it's hardcoded
no way to change that without adding custom js
as an alternative to media setting
it loads all my custom files at the very beginning of head section, right after title
I realize that including in frontend is easier, but usually it does not make sense in production because all assets are compiled into single file
{% block extrahead %}
    {{ extrahead.super }}
    <script src="1.js"></script>
{% endblock %}
Alexey Rogachev
@arogachev
Apr 11 2016 08:48
this doesn't help too
adding super I mean
Alexey Rogachev
@arogachev
Apr 11 2016 09:01
ah, it's empty by default
Alexey Rogachev
@arogachev
Apr 11 2016 09:08
Still I can't find solution for such a trivial task
for frontend it's kind of obvious
but for backend :worried:
Alexey Rogachev
@arogachev
Apr 11 2016 09:18
{% block blockbots %}
    <script src="1.js"></script>
    {{ block.super }}
{% endblock %}
Only this works for me
if anyone can suggest better solution - I will appreciate that
samkurma
@samkurma
Apr 11 2016 11:08
hi everyone, i have created a custom-user-model, and i added it in my settings file. when i try to register with django-registration, i am getting 'NoneType' object has no attribute '_insert'. please help me on this....

my custom-user-model: from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager

class MyUserManager(BaseUserManager):
def create_user(self, email, password=None):
if not email:
raise ValueError('Users must have an email address')

    user = self.model(
        email=MyUserManager.normalize_email(email),
    )

    user.set_password(password)
    user.save(using=self._db)
    return user

def create_superuser(self, email, password):
    user = self.create_user(email,
        password=password,
    )
    user.is_admin = True
    user.save(using=self._db)
    return user

class MyUser(AbstractBaseUser):
"""
Custom user class.
"""
email = models.EmailField('email address', unique=True, db_index=True)
joined = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

objects = MyUserManager()

USERNAME_FIELD = 'email'

def __unicode__(self):
    return self.email
where am i doing things wrong please.........
Puneet Aggarwal
@puneetagg
Apr 11 2016 11:50
@arogachev I didn't get you. Can you please elaborate?
samkurma
@samkurma
Apr 11 2016 11:54
@puneetagg Can you please suggest me on the above problem, i am just struckup with that problem....
Adam Collins
@adc82
Apr 11 2016 11:54
@samkurma I beleive your suppose to define it's superuser, it's a field in the abstract class. In the create superuser method you should at least have user. is_ superuser = True. I believe by default it's False though, and I don't know why not specifying it would cause an error.
samkurma
@samkurma
Apr 11 2016 12:02
@adc82 i have giver isadmin=True. even though i have tried with is superuser = True, same error i am getting
Filip Figiel
@megapctr
Apr 11 2016 12:07
@samkurma paste the traceback
without it, you can as well use a crystal ball to solve your problem :)
I'd guess that self._db is none
why do you specify using= explicitly?
Puneet Aggarwal
@puneetagg
Apr 11 2016 16:25
@samkurma Adding to @megapctr points, you must also provide functions get_full_name() and get_short_name() as specified here https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#specifying-a-custom-user-model
Ben
@Quantumke
Apr 11 2016 16:35
Hi everyone i wanted to fetch resources passed in a url e.g http://mydomain.com/?q=abc&a=123. In my example i want to fetch the variable q. Thanks.
How would i fetch the variable q?
obswork
@obswork
Apr 11 2016 17:04
@Quantumke presumably your django view would respond to the request based on the regex in your urls module, but to answer more directly: you can use urlparse & to get the output as a dict - urlparse + parse_qs
@all any tips on solving a reverseurlmatch error? my stack looks like: nginx, gunicorn, django + wagtailcms. here's the traceback: https://gist.github.com/anonymous/7711cb7582c027f4f99241eb3d1044cb & my nginx.conf: https://gist.github.com/anonymous/0f5ffbc141897a5ccc8067f8b1179569
Filip Figiel
@megapctr
Apr 11 2016 17:24
@Quantumke request.GET.get('q')
@obswork no need to post your config, the error is simple
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
this means that django could not find an url with name home
check if your urlpatterns contain the url named 'home'
also check if your urls.py file is included, if it's not in the root urlconf
also check if your urls.py include is not namespaced (in such case you'd do myapp:home)
obswork
@obswork
Apr 11 2016 19:01
@megapctr i think you're on the right track, but I'm not sure how exactly to configure my urls. i'm using wagtailcms which has its own routing mechanism i'm passing most requests off to. my urls.py for ref: https://gist.github.com/anonymous/69fcc7ccc85637bc8b6317def1f7da5c
Bruno F Souza
@varnion
Apr 11 2016 20:25

hi guys! I'd like to create an django app that:

  1. allows people to upload some file;
  2. run analysis on that file (using a pure python script I wrote)
  3. display the result of the analysis (and allow the user to download em)

can anyone point me some directions on how to get there?

I found helpful information about how to upload files on django documentation but for the other stuff I'm still lost.

thanks in advance!

gmwill92
@gmwill92
Apr 11 2016 21:32
Anyone knows how can I hide the "recent actions" box on 1.9?
Adam Collins
@adc82
Apr 11 2016 21:57
@varnion the easiest way that I can think to do that, would be to import the python script and call the necessary methods in the django view, and then return a file with the results.
cs89gr
@cs89gr
Apr 11 2016 23:26
can you tell me someone how to install geodjango step by step in windows10 ?i like to use pip if i can for that,it is easy pip.
mpachas
@mpachas
Apr 11 2016 23:40
@gmwill92 template override