Unable to add token headers to graphene-django test using pytest

2021-10-04 Thread Muhammad Shehzad
*I am trying to add a token to graphene-django headers using pytest. But
It always return that user is anonymous as shown at the end but it
should return user as token is added in fixture@pytest.fixture def
client_query(client): def func(*args, **kwargs): return
graphql_query(*args, **kwargs, client=client) return func @pytest.fixture
def create_candidate(candidate_factory): candidate = [] for _ in range(5):
can = candidate_factory.create() token, __ =
Token.objects.get_or_create(user=can.user) candidate.append(can) return
candidate **This is the test** @pytest.mark.django_db def
test_get_login_candidate(client_query, create_candidate): headers =
{"Authorization": f"Token {create_candidate[0].user.auth_token}"} response
= client_query( """ query { loginCandidate{ id, } } """, headers=headers, )
result = json.loads(response.content) print(result) This is the output
{'errors': [{'message': "'AnonymousUser' object is not iterable",
'locations': [{'line': 3, 'column': 11}], 'path': ['loginCandidate']}],
'data': {'loginCandidate': None}}*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGv3YND402MKNs6w2iFxEoHsMdMBhOwAKLtZy%3DQ2gZ6h9D-%2Bbw%40mail.gmail.com.


Embedded Images in emails

2021-10-04 Thread Bit Rate
I recently change my email from plain text to html.
This includes the registration verification email, as well as any other 
email regarding updates and notifications.

It works fine in development, but not in production.
In my production setting, django is unable to find the image and gives me 
the following error:
Exception Type:
FileNotFoundErrorException Value:
[Errno 2] No such file or directory: '/media/logo256.png'

I have tried everything and is now out of ideas, hoping someone here ran 
into the same issue and can help me please.

Here is my code from the views.py file:

def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
if form.is_valid():

user = form.save(commit=False)
user.user_email = user.email
user.is_active = False # Deactivate account till it is confirmed
user.save()

# Email with html template
from_email = settings.DEFAULT_FROM_EMAIL
to_email = user.email
subject = 'Activate Your Telos Central Account'

image_path = 'media'
image_name = 'logo256.png'
file_path = os.path.join(image_path, image_name)

text_content = "Text content: Hi {{ user.username }}, Please click 
on the link to confirm your registration, https://{{ domain }}{% url 'activate' 
uidb64=uid token=token %}  If you think, it's not you, then just ignore this 
email."
html_tmp  = get_template('email/account_activation_email.html')

ctx = {
'user': user,
'domain': 'teloscentral.com',
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
}
html_content = html_tmp.render(ctx)

msg = EmailMultiAlternatives(subject,
 text_content,
 from_email,
 [to_email])

msg.attach_alternative(html_content, 'text/html')
msg.content_subtype = 'html'  # set the primary content to be 
text/html
msg.mixed_subtype = 'related' # it is an important part that 
ensures embedding of an image

# attached image to the message before sending the mail
with open(file_path, mode='rb') as f:
image = MIMEImage(f.read())
msg.attach(image)
image.add_header('Content-ID', 
'<{name}>'.format(name=image_name))
image.add_header('Content-Disposition', 'inline', 
filename=image_name)


msg.send()

# Show message that mail has been sent
messages.success(request, ('Please Confirm your email to complete 
registration.'))

# Go to login page
return redirect('login')

return render(request, self.template_name, {'form': form})

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/52bd056e-421c-4e5e-8777-ee4288899f06n%40googlegroups.com.


Re: Where are you deploying Django App? How much does it cost for a hobby project

2021-10-04 Thread MR INDIA
*Since it is a hobby project *i would recommend *heroku free hosting*

On Sunday, 3 October 2021 at 21:57:25 UTC+5:30 avi.me...@gmail.com wrote:

> Hello! I am building a prototype Django app and would like to deploy it so 
> that people can use it.
> What would be the most cost-effective and cheapest deployment solution to 
> host a django backend? How much would it cost?
> Any ideas, help is most welcomed and appretiated
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0a2ad21f-b549-41ca-94f2-7e13936e03aen%40googlegroups.com.


Re: Embedded Images in emails

2021-10-04 Thread Kasper Laudrup

On 04/10/2021 12.30, Bit Rate wrote:

[Errno 2] No such file or directory: '/media/logo256.png'

I have tried everything and is now out of ideas, hoping someone here ran 
into the same issue and can help me please.




Have you tried checking if there is a file located at '/media/logo256.png'?

Is that part of "everything"?

Kind regards,

Kasper Laudrup

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4b12317e-de36-61f0-c720-7c17c5ccff6f%40stacktrace.dk.


OpenPGP_0xE5D9CAC64AAA55EB.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


Re: Where are you deploying Django App? How much does it cost for a hobby project

2021-10-04 Thread Paul Tiplady
You can deploy to Heroku, there's a free tier and it's very low maintenance.

https://devcenter.heroku.com/articles/deploying-python

I've had a free Django app running there that I set up almost 10 years ago 
without any work required to keep it up since then.

Heroku is somewhat expensive if you actually get enough traffic that you 
need to start paying them, but it's ideal for the MVP / proof-of-concept 
phase of a project. If you're price-conscious and want to scale up a bit 
more, you can rent a dedicated VM for $5/month (for example, Digital Ocean 
droplets https://www.digitalocean.com/pricing/) and that will get you a lot 
more capacity per $. That said, you may find that the convenience of Heroku 
is worth paying for.

On Sunday, October 3, 2021 at 9:27:25 AM UTC-7 avi.me...@gmail.com wrote:

> Hello! I am building a prototype Django app and would like to deploy it so 
> that people can use it.
> What would be the most cost-effective and cheapest deployment solution to 
> host a django backend? How much would it cost?
> Any ideas, help is most welcomed and appretiated
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7fdd43b6-5bca-4cc1-90df-7e277d19b5d7n%40googlegroups.com.


Django Query

2021-10-04 Thread Eugene TUYIZERE
Team,

Assume you have 3 tables PROVINCES, DISTRICTS, and SECTORS and you have
Province, District and Sector field names respectively in each table.

How can you display in the Django template the following table?

Province District Sectors
A A1 A11
A12
A2 A21
A22
A3 A31
A32

Any assistance will be appreciated
-- 
*TUYIZERE Eugene*



*Msc Degree in Mathematical Science*

*African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
Garden-Lime, Cameroon*

Bsc in Computer Science

*UR-Nyagatare Campus*

Email: eugene.tuyiz...@aims-cameroon.org
   eugenetuyiz...@gmail.com

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABxpZHsGxujwVUp3NEXBWjBnOahYuPOBZccU8O%2BvejowDYxxvg%40mail.gmail.com.


Re: Django Query

2021-10-04 Thread Sebastian Jung
Hello Eugene,

I think that django mptt can Store and display such a tree.

Regards

Eugene TUYIZERE  schrieb am Mo., 4. Okt. 2021,
20:29:

> Team,
>
> Assume you have 3 tables PROVINCES, DISTRICTS, and SECTORS and you have
> Province, District and Sector field names respectively in each table.
>
> How can you display in the Django template the following table?
>
> Province District Sectors
> A A1 A11
> A12
> A2 A21
> A22
> A3 A31
> A32
>
> Any assistance will be appreciated
> --
> *TUYIZERE Eugene*
>
>
>
> *Msc Degree in Mathematical Science*
>
> *African Institute for Mathematical Sciences (AIMS Cameroon)Crystal
> Garden-Lime, Cameroon*
>
> Bsc in Computer Science
>
> *UR-Nyagatare Campus*
>
> Email: eugene.tuyiz...@aims-cameroon.org
>eugenetuyiz...@gmail.com
>
> Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHsGxujwVUp3NEXBWjBnOahYuPOBZccU8O%2BvejowDYxxvg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9mwz%3D0FA27Yr8xxiZPK6O4v9t1CwVFXNtr3DMK-xxobmKw%40mail.gmail.com.


Proposed bug in Admin

2021-10-04 Thread Mike Dewhirst
The following error message is reproducible from different Django 
website admin systems used from Safari on an iPad. It is an old iPad so 
that might be the issue.


Saving the substance does not produce a 500 error. The record gets saved 
and the page redisplays correctly except the success message loses its 
little green tick


It doesn't happen with Mozilla Firefox or Google Chrome on Windows 10.

The actual problem is the error message itself clogging up the 
webmaster's mailbox. I think the workaround would be to override the css



 ValueError at /admin/substance/substance/1426/img/icon-yes.svg/change/

Field 'id' expected a number but got '1426/img/icon-yes.svg'.

Request Method: GET
Request URL: 
https:///admin/substance/substance/1426/img/icon-yes.svg/change/

Django Version: 3.2.7
Exception Type: ValueError
Exception Value:

Field 'id' expected a number but got '1426/img/icon-yes.svg'.

Exception Location: 
/usr/local/lib/python3.6/dist-packages/django/db/models/fields/__init__.py, 
line 1827, in get_prep_value

Python Executable:  /usr/bin/python3
Python Version: 3.6.9
Python Path:

['/var/www/ssds',
 '/usr/lib/python36.zip',
 '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload',
 '/usr/local/lib/python3.6/dist-packages',
 '/usr/lib/python3/dist-packages']

Server time:Mon, 04 Oct 2021 07:26:42 +



Cheers

Mike

--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/09fa9f09-adf2-fc7d-1b3b-52c16518e24e%40dewhirst.com.au.


OpenPGP_signature
Description: OpenPGP digital signature


from excel to postgesql

2021-10-04 Thread Nader Elsisi
I have a site on heroku up and running, database postgresql, the models 
have a lot of relations.
I want to add data from excel file about 400 excel rows by code in django.

How can I access the excel file to read the data? or suggest another way 
for the job to be done.

Thanks for your help.

Nader

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0605e42d-66fe-4ca8-b967-b9691a0b4bf1n%40googlegroups.com.


How to port a Django web app in mobile (iOS & Android)

2021-10-04 Thread Ram
Hi,

We have a working WebApp developed with Django, Python and Vue.Js. The
application is working ok when it is opened in Mobile devices but we need
to do lot of tweaking UI to make it compatible to mobile devices everytime.
So we are looking for a way to create a mobile app and also need to update
the data irrespective of device that users use. Please let us know whether
this can be achievable?

Best regards,
~Ram

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BOi5F1ieftwss1cJya3asLcJ_OpSbBm-OrwDtQPuKTA-ESq7A%40mail.gmail.com.