Case insensitive regular expression filter in MariaDB

2017-11-14 Thread Afshin Mehrabani
Hello,

I have noticed an issue in my local machine and wanted to open a PR but I 
thought it's better to confirm this with you guys first.

I'm using MariaDB and tried to use iregex but noticed that it doesn't work 
at all. After adding `(?i)` to the beginning of the regex, I managed to 
filter the results in a case-insensitive way.

See https://mariadb.com/kb/en/library/pcre/ for more Regex options.

I'm using:

mysql  Ver 15.1 Distrib 10.2.10-MariaDB, for debian-linux-gnu (x86_64) 
> using readline 5.2


Let me know what you think. I can open a PR.

Thanks

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/10348a66-6427-4dbd-b1c6-fb882dc88241%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Download a file on Django and delete it after return

2017-11-14 Thread Ruifeng Hu
Hi All,

I am now writing a web service which can generate a file and download it 
automatically for users, but I want to delete it after the file has been 
downloaded(after return the HttpResponse). What should I do ?

Thank You!

Ruifeng Hu

 

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/508fcace-efc8-42c0-a667-b760fec4c141%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Download a file on Django and delete it after return

2017-11-14 Thread Juan Hernandez
well, we could see the use case to see the correct approach but, what comes
to mind is using try/except/finally

On Nov 14, 2017 17:56, "Ruifeng Hu"  wrote:

> Hi All,
>
> I am now writing a web service which can generate a file and download it
> automatically for users, but I want to delete it after the file has been
> downloaded(after return the HttpResponse). What should I do ?
>
> Thank You!
>
> Ruifeng Hu
>
>
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/508fcace-efc8-42c0-a667-b760fec4c141%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Bx7b_HHguaxu9di0xcJadKpJv%3D1eJZKFuHELzt5RR%3D6n5jvLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: Download a file on Django and delete it after return

2017-11-14 Thread Matthew Pava
We can download PDFs in our project.
We start out generating the PDF on the server.  We read the contents of it into 
a variable to put it into memory.  Then we delete the file on the server (it’s 
still in memory), and the response is itself the PDF document.

I’ll share the last bit of code that we use:
with open(file_and_path, 'rb') as f:
pdf_contents = f.read()

os.remove(file_and_path)
response = HttpResponse(pdf_contents, content_type='application/pdf')
response['Content-Disposition'] = "%sfilename=%s" % ('attachment; ' if download 
else '', filename)
return response


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Ruifeng Hu
Sent: Tuesday, November 14, 2017 4:56 PM
To: Django users
Subject: Download a file on Django and delete it after return

Hi All,

I am now writing a web service which can generate a file and download it 
automatically for users, but I want to delete it after the file has been 
downloaded(after return the HttpResponse). What should I do ?

Thank You!

Ruifeng Hu


--
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 post to this group, send email to 
django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/508fcace-efc8-42c0-a667-b760fec4c141%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c1c42116948e47ed926312adf4a87853%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Download a file on Django and delete it after return

2017-11-14 Thread Ruifeng Hu
Many thanks for your reply ! ! !

On Tuesday, November 14, 2017 at 5:05:20 PM UTC-6, Matthew Pava wrote:
>
> We can download PDFs in our project.
>
> We start out generating the PDF on the server.  We read the contents of it 
> into a variable to put it into memory.  Then we delete the file on the 
> server (it’s still in memory), and the response is itself the PDF document.
>
>  
>
> I’ll share the last bit of code that we use:
>
> with open(file_and_path, 'rb') as f:
> pdf_contents = f.read()
>
> os.remove(file_and_path)
> response = HttpResponse(pdf_contents, content_type='application/pdf')
> response['Content-Disposition'] = "%sfilename=%s" % ('attachment; ' if 
> download 
> else '', filename)
> return response
>
>  
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Ruifeng Hu
> *Sent:* Tuesday, November 14, 2017 4:56 PM
> *To:* Django users
> *Subject:* Download a file on Django and delete it after return
>
>  
>
> Hi All,
>
>  
>
> I am now writing a web service which can generate a file and download it 
> automatically for users, but I want to delete it after the file has been 
> downloaded(after return the HttpResponse). What should I do ?
>
>  
>
> Thank You!
>
>  
>
> Ruifeng Hu
>
>  
>
>  
>
> -- 
> 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...@googlegroups.com .
> To post to this group, send email to djang...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/508fcace-efc8-42c0-a667-b760fec4c141%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/25e6cbae-fe0b-4c6c-98d7-c2f879b26a90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Download a file on Django and delete it after return

2017-11-14 Thread James Schneider
On Nov 14, 2017 3:04 PM, "Matthew Pava"  wrote:

We can download PDFs in our project.

We start out generating the PDF on the server.  We read the contents of it
into a variable to put it into memory.  Then we delete the file on the
server (it’s still in memory), and the response is itself the PDF document.


Note that this strategy has two potentially negative side effects:

1. The original file is no longer available for a second attempt to
download in the event the first attempt fails. This may be fine if the file
is generated every time as part of the request.

2. Loading the file in to memory is usually find for smaller sites, but
high traffic sites can run in to memory resource issues.

You can also have a cron job delete files every so often based on their
age, rather than deleting them as part of the immediate response cycle.
That would save on memory, if that's a concern.

-James

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWOUxKzDDbLezw23ABE1Q%3DapYVJR3gU4TAtvEb0RvGFOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Are time zone definitions actually required/used in MySQL?

2017-11-14 Thread Michael Lenaghan
For MySQL the Django docs say 

:

If you plan on using Django’s timezone support 
> , use 
> mysql_tzinfo_to_sql 
>  to load 
> time zone tables into the MySQL database. This needs to be done just once 
> for your MySQL server, not per database.


I can't find any evidence that Django actually uses those tables?

Here 
,
 
for example, is a snippet from adapt_datetimefield_value():

# MySQL doesn't support tz-aware datetimes
> if timezone.is_aware(value):
> if settings.USE_TZ:
> value = timezone.make_naive(value, 
> self.connection.timezone)
> else:
> raise ValueError("MySQL backend does not support 
> timezone-aware datetimes when USE_TZ is False.")


adapt_timefiled_value() is even simpler 

:

# MySQL doesn't support tz-aware times
> if timezone.is_aware(value):
> raise ValueError("MySQL backend does not support 
> timezone-aware times.")


What am I missing? 

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a3584f88-bd35-44b2-a5aa-2da201c50ae3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Strange query when using annotate and count

2017-11-14 Thread Cristiano Coelho
I'm getting some very odd query when combining annotate with count. See the 
following:

>>> q = 
> Vulnerability.objects.annotate(score=WordTrigramCustomSimilarity('test','summary'))
> >>> q.count()
> 3094
> >>> print connection.queries[-1]
> 'SELECT COUNT(*) 
> FROM (
> SELECT "vulnerabilities_vulnerability"."id" AS Col1, 
> custom_word_similarity(\'test\', "vulnerabilities_vulnerability"."summary") 
> AS "score" 
> FROM "vulnerabilities_vulnerability" 
> GROUP BY "vulnerabilities_vulnerability"."id", 
> custom_word_similarity(\'test\', "vulnerabilities_vulnerability"."summary")
> ) subquery
> >>> q2 = Vulnerability.objects.filter(summary__icontains='test')
> >>> q2.count()
> 33
> >>> print connection.queries[-1]
> 'SELECT COUNT(*) AS "__count" 
> FROM "vulnerabilities_vulnerability" 
> WHERE UPPER("vulnerabilities_vulnerability"."summary"::text) LIKE 
> UPPER(\'%test%\')



Custom function code, is this what's causing the odd count behavior? Did I 
miss anything?

class WordTrigramCustomSimilarity(Func):
> function = 'custom_word_similarity' 
> def __init__(self, string, expression, **extra):
> if not hasattr(string, 'resolve_expression'):
> string = Value(string)
> super(WordTrigramCustomSimilarity, self).__init__(string, 
> expression, output_field=FloatField(), **extra)


I would expect for the query to be a simple count, rather than a nested 
query with a useless group by (correct me if I'm wrong).
The issue gets even worse if the function is expensive, since it gets 
called when it's not needed at all, more than once.
Also the issue behaves pretty much the same if the queryset includes 
filtering and ordering but I didn't include it here for simplicity.

Using Django 1.11.7 + postgres (psycopg) backend.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a8ef80d5-26a5-40b4-b2b1-5cbf3bfa8c64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Two forms in one template.

2017-11-14 Thread Mike Ru
How can I pass two forms(registration and login) in one template? I'm using 
'registration' and it's using different templates. For registration it's 
using 'registration_form.html and for login it's using login.html. How can 
I pass a login form in modal window inside registration_form.html. In 
short, I have a page for registration. It has a modal window. I need to 
pass in modal window only form for login. How can I make it ?

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/65c476e9-cfe6-4bf8-b8f2-30901db03e92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.