Re: Crazy Idea: OOP for "Hyperlink"

2018-04-25 Thread guettli
Thank Adrien for sharing your knowledge.

Our use cases have some parts that are common and some
parts that are distinct.

You want actions, I want static attributes.

You define them on the model.

I use URLs. In my case sometimes there is a 1:1 relationship between URL 
and model,
but sometimes not.

In my use case I have reports. I want a report to have a preview html 
snippet.

There are N reports (N URLs) for one model.

But I think there are more common things than distinct things.

One URL can have N attributes.

Some are actions, some static ones.

Where these attributes come from is a different topic.

If the URL  represents a model, the attributes (in your case "actions") of 
the model
can be propagated up to the URL.

I  hope you undestand what I wrote. If not, then tell me.

Up to now these are just basic thoughts. I won't do any coding
during the next days. If someone likes this idea and implements it,
please let me know. I am always curious.

Regards,
  Thomas



Am Montag, 23. April 2018 12:22:32 UTC+2 schrieb Adrien Cossa:
>
> Hi,
> On 04/23/2018 10:59 AM, guettli wrote:
>
> I have a vague idea to use OOP for a hyperlink.
>
> A hyperlink has these attributes for me:
>
> - href
> - verbose name
> - Permission: Is the current user allowed to follow the link?
> - Preview (on-mouse-over tooltip)
>
>
> We have developed something similar in the company I work for. The use 
> case is not exactly the same as yours, but we end up with some "Action" 
> object that are similar to your "Hyperlink".
>
> We have a mechanism based on mixins to define actions on our models, for 
> example let's say "create child node". Now each action has some attributes 
> telling what to display (e.g. "Create new child node") and what should 
> happen when we click on it (e.g. POST to an URL). Now the interesting part 
> is that we can also define some restrictions for every action (e.g. "forbid 
> if user is not part of the manager group, or if a child already exist for 
> the current object, or ... etc") and we have a serializer mixin that would 
> automatically embed our actions information when serializing the model 
> object.
>
> It is then the frontend's job to display whatever you like (description or 
> restriction) when the mouse is over, and to make the link clickable or not. 
> If the user tries to trick us with a manual request, we will not allow the 
> action because the view / model method execution is protected with the same 
> restriction set.
>
> That is to say, after having defined a list of actions in a model field, 
> and a list of restriction for each action, we have a fully working action 
> description and restriction mechanism to manipulate our objects. It looks a 
> bit like this:
>
> class X(ModelWithActionsMixin, Model):
> actions = [ Action(id="create_child", ..., 
> restrictions=[Restriction(...), ...], ]
>
> @protect(action_id="create")
> def add_child(self):
> ...
>
> or if you want to check the restrictions directly in your view instead of 
> protecting the method:
>
> class NodeCreateView(...):
>
> def post(self, ...):
> obj = self.get_object()
> try:
> protect_action(obj, "add_child")
> except ProtectedActionError as e:
> raise Error400(...)
> else:
> obj.add_child()
>
>
> Maybe you can use some similar mechanism for your implementation?
>
> PS: we are willing to make a proper package for our stuff and the idea 
> behind would be to release it as free module, but I can't tell if that will 
> really happen or when... but to see that you need something similar will 
> probably push us :-)
>
>
> I like Django because it handles the "href" part very smart (via 
> reverse()).
>
> My current use case is the preview tooltip.
>
> The app I develop has roughly ten different report types.
>
> I can't remember the name, but I can remember how the report looked like.
>
> I recall the shape and colors of the report.
>
> That's why I would like to have a on-mouse-over tooltip for the hyperlink.
>
> For example look at these chart types: 
> https://developers.google.com/chart/interactive/docs/gallery
>
> The tooltip should show a small version of the report/chart if I move the 
> mouse over the hyperlink.
>
> I don't want to automate the creation of the preview images.  It is enough 
> if I am able to attach a small HTML snippet to
> each Django-URL. This HTML snippet should be used for the preview tooltip.
>
> What do you think?
>
> Regards,
>   Thomas
> -- 
> 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 django...@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/c1df

Re: Django Setup Challenges

2018-04-25 Thread Kamil Dębowski
What is your problem exactly? What have you already done? Do you see some 
errors in console?

W dniu wtorek, 24 kwietnia 2018 13:34:46 UTC+2 użytkownik Nana Kwabena 
Kwarteng napisał:
>
> Hi All,
>
> I'm new here and I'm having getting my django to run... Any help?
>

-- 
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/c8a7c5b6-2422-40fc-985e-c18a5f1bf1be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Crazy Idea: OOP for "Hyperlink"

2018-04-25 Thread 'Anthony Flury' via Django users
Interestingly, I am thinking on something similar too - having a 
report/notifications/actions view that have an auto generated URL. The 
idea (on my concept) is that by getting this unique URL via email, a 
user can access the report/action without needing to actually login - 
the fact that a user accesses the url is authenticaton - it could 
optionally require a password, since the userid is effectively part of 
the URL


My thoughts :

Either a specific

   A Notification/Report Model where one of the fields will be the
   unique URL id
    An incoming URL with the right path would search for the
   notification model with the extracted URL id
    My views would search my models for the incoming Id, and
   confirm expected users, permissions etc.
    I would only have one view that needs this so my specific
   solution would be highly specific


Or a  generic solution

   A model for URLs and that model can have a one to one or one to one
   to many relationship with other models; clearly this relationship is
   dynamic so - I see this :

   In the Model :

   from hrefgeneric.models import HRefModel

   class Notification(models.Model)
    href = models.OneToOne(HRefModel, ...)
    ...

   In the views

   from hrefgeneric.views import HRefRequiredMixin

   class NotificationView(HRefRequiredMixin, View):
    class HREFRequired:
        login_url = '/login/'
        redirect_field_name='redirect_to'
        user_name_field = 'username'

     def get(self, HRef):
                # HRef is now the HRef instance relevant to the
   incoming request (not just any text extracted from the URL
                      pass
       def post(self, HRef):
                # HRef is now the HRef instance relevant to the
   incoming request (not just any text extracted from the URL
                      pass


   If login_url is set to anything truthy, then the mixin will enforce
   some form of authentication form, with 'user_name_field' set to the
   expected user name of the HRef (assuming the expected user on the
   HRef is not None).

   For the generic solution it would be great if there a decorator for
   non class based views which does something similar.

    The HRef instance needs the following fields

        field_name =  # The name of any URL field that 
this HREF should be matched on
        field_value =  # The value that the above field 
should have for this HREF
            user =  # The user that is allowed to 
access this HREF - can be None
            group =  # The permission Group that the 
user - can be None
            permission =  # One or more permissions that 
the user - can be None


    On creation, field_name & field_value must be set

    Example:
          a pattern like this :
           path('/notification/', my_view)

      and a href instance :
                HRef(field_name='id', field_value='aabbccddeeff')

     would match against an incoming path of
                http://host/notification/aabbccddeeff

    It might be that we need to match multiple fields on a url - not 
sure how we do this.


I would happily contribute to an Django appropriate plugin etc - it 
seems like there is a lot of commonality between the use cases.


--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *


On 25/04/18 09:30, guettli wrote:

Thank Adrien for sharing your knowledge.

Our use cases have some parts that are common and some
parts that are distinct.

You want actions, I want static attributes.

You define them on the model.

I use URLs. In my case sometimes there is a 1:1 relationship between 
URL and model,

but sometimes not.

In my use case I have reports. I want a report to have a preview html 
snippet.


There are N reports (N URLs) for one model.

But I think there are more common things than distinct things.

One URL can have N attributes.

Some are actions, some static ones.

Where these attributes come from is a different topic.

If the URL  represents a model, the attributes (in your case 
"actions") of the model

can be propagated up to the URL.

I  hope you undestand what I wrote. If not, then tell me.

Up to now these are just basic thoughts. I won't do any coding
during the next days. If someone likes this idea and implements it,
please let me know. I am always curious.

Regards,
  Thomas



Am Montag, 23. April 2018 12:22:32 UTC+2 schrieb Adrien Cossa:

Hi,

On 04/23/2018 10:59 AM, guettli wrote:

I have a vague idea to use OOP for a hyperlink.

A hyperlink has these attributes for me:

- href
- verbose name
- Permission: Is the current user allowed to follow the link?
- Preview (on-mouse-over tooltip)


We have developed something similar in the company I work for. The
use case is not exactly the same as yours, but we end 

Re: Filter_horizontal, applying filter on the right box - chosen items

2018-04-25 Thread dario . figueira
Hi all, 
Are you aware of a standard solution that has been added to django in the 
meanwhile?

Or adding Dustin's solution to my code is the way to go?

Cheers :)

On Wednesday, 6 April 2016 18:57:54 UTC+1, Dustin Dobernig wrote:
>
> I know this is question is old but I was looking for the solution myself 
> and couldn't find an quick answer so I ended up just doing it myself. My 
> solution is here https://djangosnippets.org/snippets/10560/ 
> 
>

-- 
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/3dbacd62-e26b-4a0f-b4f3-b7b8674d8d24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Crazy Idea: OOP for "Hyperlink"

2018-04-25 Thread Jani Tiainen
Hi.

Most probably you get there by creating custom template tag and bunch of
other code.

It would be easier to grasp your idea if you have some kind of an
implementation to reference.

Or is there something that stops you from proceeding?


ma 23. huhtikuuta 2018 klo 12.00 guettli  kirjoitti:

> I have a vague idea to use OOP for a hyperlink.
>
> A hyperlink has these attributes for me:
>
> - href
> - verbose name
> - Permission: Is the current user allowed to follow the link?
> - Preview (on-mouse-over tooltip)
>
> I like Django because it handles the "href" part very smart (via
> reverse()).
>
> My current use case is the preview tooltip.
>
> The app I develop has roughly ten different report types.
>
> I can't remember the name, but I can remember how the report looked like.
>
> I recall the shape and colors of the report.
>
> That's why I would like to have a on-mouse-over tooltip for the hyperlink.
>
> For example look at these chart types:
> https://developers.google.com/chart/interactive/docs/gallery
>
> The tooltip should show a small version of the report/chart if I move the
> mouse over the hyperlink.
>
> I don't want to automate the creation of the preview images.  It is enough
> if I am able to attach a small HTML snippet to
> each Django-URL. This HTML snippet should be used for the preview tooltip.
>
> What do you think?
>
> Regards,
>   Thomas
>
> --
> 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/c1df4a33-d077-42c4-8fd0-94902b4fad69%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/CAHn91ocEskC_8iZBcO9ZJ4xURd-f%3DH%3DppLZbqkpPQZR%2B7SMyWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Dynamically altering a (ForeignKey) ModelChoiceField’s values

2018-04-25 Thread Jim Illback
I wondered if anyone has had to alter the queryset behind a model form’s 
foreign key field which presents as a model choice field?
Briefly, I have a client attribute table with the foreign key to a chore/time 
table. For an add of the client attribute table, I want to limit entries to 
unassigned chore/time combinations only. This works perfectly during my 
CreateView. Here are some extracts to show specifics:
Models.py:
class ChoreTime(models.Model):
chore = models.ForeignKey(Chore, on_delete=models.CASCADE)
time = models.ForeignKey(TimePeriod, on_delete=models.CASCADE)
priority = models.BooleanField(default=False)
…
class Checkin(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE)
choretime = models.ForeignKey(ChoreTime, on_delete=models.CASCADE)
…
Forms.py:
class CheckinForm(forms.ModelForm):
assigned_qs = 
Checkin.objects.values(‘choretime').filter(choretime_id__isnull=False)
choretime = 
forms.ModelChoiceField(queryset=ChoreTime.objects.exclude(pk__in=assigned_qs))
…
However, I cannot get the any design to work on an UpdateView form. Using the 
same form as above, the current value does not even show up – it is blank – 
because, of course, that entry is already assigned so is excluded.
What I’d like is to have the above exclusions BUT be able to also add in the 
single entry assigned to the client being updated – so the entry will show that 
specific assignment (as well as limiting any possible change options to 
unassigned values - just like on the Create).
The problems with various approaches I’ve tried are:

1. Anything done before the form is fully assembled won’t have the existing 
form’s Checkin ID value (which is part of the URL, just BTW). This is needed to 
look up and add the existing entry. So, having a database view won’t work 
without being able to communicate the existing person’s assignment ID to the 
view. Similarly, using an override queryset on the form, like done above for 
the Create, needs that ID, too.

2. If I do the queries in the class's GET method routine as ORM objects, I 
must use UNION (a union of the exclusions as above plus the existing update 
client’s assignment). That union option keeps giving an error that one of the 
ORM querysets is not a queryset. However, they are both using 
“.objects.filter…”. It seems like complex queries don’t work with the 
union command. If I use raw SQL, the query works but the assignment to the 
choretime field’s queryset fails.
Does anyone have experience with this sort of behavior and be willing to give 
guidance?

-- 
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/F0B95720-C669-4CE5-912E-5167E3B89DFE%40hotmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: database update after paypal payment

2018-04-25 Thread mab . mobile . 01
Hello Michael, 

I am having the same problem. I have no problems submitting the data from 
my website to paypal. I am using Django 2.0.x and just need the django 
IPN-listener code in an easy to understand way. I want to receive data back 
from paypal IPN and be able to store it in my database ie customer name, 
product_id, transaction_date etc. 

I have read http://django-paypal.readthedocs.io but it is difficult to 
follow and incomplete when it comes to returning the IPN completion. 

Thanks

Marc

On Wednesday, March 22, 2017 at 9:32:51 PM UTC-5, Michael Goytia wrote:
>
> Hello, 
>
> If you still need help please email me and I can assist you. also look at 
> this page 
> 
>
> Michael Goytia
>
> On Wednesday, March 1, 2017 at 7:11:08 PM UTC-7, Agoulou Zegouna wrote:
>>
>> Thanks all ! I tried to Use django-paypal. can you please give me a 
>> concrete example after from step 5 to 6? I have no idea of what to do?
>> https://django-paypal.readthedocs.io/en/stable/standard/ipn.html
>>
>>
>> On Wed, Mar 1, 2017 at 1:46 PM, Mario Gudelj  wrote:
>>
>>> You should use Django-PayPal app. It has views for IPN and PDT, stores 
>>> transaction details in DB, does TX verification and it fires of a signal 
>>> when when a successful transaction comes in to your webhook. 
>>>
>>> All you have to do is specify some URLs and settings. It'll even render 
>>> that front end form for you using a Django form. It really is a bomb. 
>>>
>>> Cheers,
>>>
>>> M
>>>
>>>
>>>
>>> On Wed, 1 Mar 2017 at 11:10 pm, Melvyn Sopacua  
>>> wrote:
>>>
 On Tuesday 28 February 2017 21:13:39 agoulou...@gmail.com wrote:

 > hello! I am trying to update my database after paypal has received 

 > the payment from customer. The problem is that I don't really know to

 > do it. This is what I am doing now

  

 This code is all irrelevant. This is the important URL:

 > >>>
 > name="return" type="hidden" value="http://www.example.com/thank-you";>

  

 Wouldn't name it "thank-you" either. That would be the final page, but 
 the flow is:

  

 - Submit to PayPal

 - At above return_url, receive data from PayPal:

 - Check for success / failure

 - If success:

 set paid to True, redirect to /thank-you

 - else:

 display error and cart

  

 -- 

 Melvyn Sopacua

 -- 
 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 django...@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/3452662.H3dCPjKHmD%40devstation
  
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>> -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/django-users/ZUBd-vcyjrs/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> django-users...@googlegroups.com.
>>> To post to this group, send email to django...@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/CAHqTbjmeT%3D8U0wPqLTPBcb6FxSPnECiaFR0Y99-%2B0ooZhKQK6Q%40mail.gmail.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/54beedf2-3d07-4c5f-8fd6-af1a7cc6a23f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django and Fullcalendar.

2018-04-25 Thread Elias Coutinho
Good afternoon my friends.

Anyway, I do not make a living, and someday some day maybe.
My knowledge of Django is intermediate so do not be surprised if I make a 
mistake.

I have the FULLCALENDAR 
 project.
It is using DRF and ajax for some actions like drag and drop, my problem is 
that I can not do an insert in this CODE LINE 

.

For me I would call a jquery dialog and send the data to the DRF via ajax, 
but as I have no experience I am counting on your help in this endeavor.

I tried several ways and the closest I got was this BLOG 
,
 
downloaded and tested, the example works but when I step into my reality it 
saves (POST) but returns a whole messy template with information about tags 
sent.

1 - I would like to know if anyone knows a better way to perform CRUD using 
Django, DRF and FullCalendar.
2 - Casoo example of the blog in your eyes is a good way would like someone 
help me to discover this mystery.

Below I will post all the way of the codes related to the problem.

A) views.py 

B) forms.py 

C) models.py 

D) [1] urls.py 

 and [2] urls.py from API 

 and [3] urls.py that I was testing on the above mentioned blog 

E) ajax code 

F) Template index.html 

G) Template Forms 


Thank you.

-- 
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/6117ec35-9c44-4ddd-8aee-4c500ed598a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django.forms -- unable to display default values in form fields for edit form

2018-04-25 Thread Alex Volkov
Hello everyone,

I'm having some problem with django.forms edit dialog and I believe it 
might be a bug in django that's causing this.

I created a project with Django 2.0.4 running on Python 3.6.5 with 
cookiecutter django template.

I created an app (survey) then created a form using a model with model form 
interface view and template. Everything works except when I added a form 
for editing existing model values, the form fields with default values 
don't get populated. Here's a snippet from my implementation:

#models.py

from django.db import models

class Survey(models.Model):

class Meta:
"""Set composite key for file_number/location fields"""
unique_together = (('file_number', 'court_location', ))

file_number = models.CharField(max_length=127)
location = models.ForeignKey(Location, on_delete=models.PROTECT)

# forms.py
from django import forms

class SurveyForm(forms.ModelForm):
"""Survey Form along with customizations"""

def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user', None)
super().__init__(*args, **kwargs)
# Only show locations available to the user
locations = Location.objects.filter(contract__user_id=self.user.id)
self.fields['location'].queryset = locations

class Meta:
model = Survey
fields = '__all__'

# views.py

class SurveyEdit(View):
"""Edit form for SurveyForm class"""

def get(self, request, survey_id):
survey_obj = Survey.objects.get(id=survey_id)
survey_form = SurveyForm(
request.GET, user=request.user, instance=survey_obj)
return render(
request,
'survey_edit_form.html',
{'survey_form': survey_form, 'survey_id': survey_id}
)

def post(self, request, survey_id):
sf = SurveyForm(
request.POST,
user=request.user,
instance=Survey.objects.get(id=survey_id))
if sf.is_valid():
sf.save()
messages.add_message(
request,
messages.SUCCESS,
"Survey {} was 
updated".format(sf.cleaned_data['file_number'])
)
return HttpResponseRedirect('/survey/list')
error_message(sf, request)
return render(
request,
'survey_edit_form.html',
{'survey_form': sf, 'survey_id': survey_id}
)

# survey_edit_form.html template

{% extends "base.html" %}

{% block title %}
  {% block head_title %}
  Edit Survey
  {% endblock head_title %}
{% endblock title %}

{% block content %}

  

  {% csrf_token %}
  {% for field in survey_form %}

  {{ field.label }}
  {{ field }}

  {% endfor %}
  

  

{% endblock %}

# urls.py

path('edit/', login_required(SurveyEdit.as_view()), 
name='edit'),

I also have the following test case, which verifiees that the data is 
loaded into the form

def test_006_edit_data_is_loaded(self):
"""When editing a survey through SurveyForm, verify Survey data is 
loaded"""
client = Client()
client.force_login(self.user)
# create survey object from generated data
edit_survey_data = copy(gen_survey_data(self))
edit_survey = Survey(**edit_survey_data)
edit_survey.save()
# go to edit page
edit_url = '/survey/edit/{}'.format(edit_survey.id)
resp = client.get(edit_url)
# verify that field values were loaded 
content = str(resp.content)
self.assertIn(edit_survey_data['file_number'], content)


The problem seems to be somewhere either in django.forms.boundfield

https://github.com/django/django/blob/c591bc3ccece1514d6b419826c7fa36ada9d9213/django/forms/boundfield.py#L126

def value(self):
data = self.initial
if self.form.is_bound:
data = self.field.bound_data(self.data, data)
return self.field.prepare_value(data)

Where data is correctly assigned from self.initial value (which is taken 
from instance param passed to SurveyForm). However, self.field.bound_data 
method seems to return wrong value,

https://github.com/django/django/blob/c591bc3ccece1514d6b419826c7fa36ada9d9213/django/forms/fields.py#L161

In this code snippet:

if self.disabled:
return initial
return data

The initial value returned only when the field is disabled, which should 
not be the case, I want default data to be displayed when request.GET is 
passed to render ModelForm, in my case the check should be, if there's no 
updated data, return initial data i.e.

if data:
return data
return initial


This seems to fix the issue I have and when I make the change the default 
values are displayed in edit field, however I looked at history of these 
two files (git blame) and didn't find anything that's been changed recently 
(all the changes are from 2-3 years ago), so I'm not sure if this is 
something I'm doing wrong or there was a bug introduced in django.forms in 
some other way.

Please help.

-- 

Django--Making query use part of the matching name

2018-04-25 Thread shawnmhy
Hello everyone!

Currently I am working on Django.

I defined a 'Search' function in views.py:

def search(request):
q = request.GET.get("q")
if q:
ReactResul = Reactionsmeta.objects.filter(id__contains=q)
MetaResul = Metabolites.objects.filter(id__contains=q)
GeneResul = Genes.objects.filter(id__contains=q)

else:
# you may want to return Customer.objects.none() instead
ReactResul= Reactionsmeta.objects.all()
GeneResul = Genes.objects.all()
MetaResul = Metabolites.objects.all()
context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
GeneResul)
return render(request, "Recon/search.html", context)


And now I want to make it more powerful.

If I want to search '10FTH86RSK' but I cannot remember the whole name, I 
can just use part of the string to make query. For example, if I type 
'10FTK', '10FTH86RSK' should be returned as result.
In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
results.

So how could I achieve this function?

-- 
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/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django--Making query use part of the matching name

2018-04-25 Thread James Farris
I believe you want to use icontains rather than contains. It’s case 
insensitive. 

I’m not sure without using regex it’s possible to return the results based on 
any character in any order in the search string. 

> On Apr 25, 2018, at 5:13 PM, shawn...@gmail.com wrote:
> 
> Hello everyone!
> 
> Currently I am working on Django.
> 
> I defined a 'Search' function in views.py:
> 
> def search(request):
> q = request.GET.get("q")
> if q:
> ReactResul = Reactionsmeta.objects.filter(id__contains=q)
> MetaResul = Metabolites.objects.filter(id__contains=q)
> GeneResul = Genes.objects.filter(id__contains=q)
> 
> else:
> # you may want to return Customer.objects.none() instead
> ReactResul= Reactionsmeta.objects.all()
> GeneResul = Genes.objects.all()
> MetaResul = Metabolites.objects.all()
> context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
> GeneResul)
> return render(request, "Recon/search.html", context)
> 
> And now I want to make it more powerful.
> 
> If I want to search '10FTH86RSK' but I cannot remember the whole name, I can 
> just use part of the string to make query. For example, if I type '10FTK', 
> '10FTH86RSK' should be returned as result.
> In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
> results.
> 
> So how could I achieve this function?
> -- 
> 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/793b8999-cac4-4c2d-94cc-eabb80f4e702%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/9EC3A76F-EE60-47DC-B4DD-9092D8321EC1%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


convert range of date from julian to gregorian date

2018-04-25 Thread sum abiut
Hi ,
I am trying to convert a range of date from julian to gregorian date

here is what i have try
stmt=stmt.where(and_(rate.columns.journal_ctrl_num==fund.columns.journal_ctrl_num,fund.columns.account_code==selected_acc,rate.columns.date_entered.between(convert,convert1)))
result_proxy=connection.execute(stmt).fetchall()
for a in result_proxy:
test=datetime.date.fromordinal(int(a.date_entered))

the two date ranges  are (convert and convert1)

but when i pass test parameter  to the template it only display the start
date which is convert. I was wondering how to pass to date range to the
date_applied in  test=datetime.date.fromordinal(int(a.date_entered))

i know from sql its done like this
rate.columns.date_entered.between(convert,convert1)




cheers

-- 
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/CAPCf-y4ZN8VgUQSbF90QE20ec7Qg5qbof8mnwYEQGTmEawkELw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.