How to create a multi valued field in the model?

2015-03-23 Thread Daniel Grace
How to create a field with multiple values? For example an integer field that takes on particular values: state = models.IntegerField() ... where state=0 represents 'pending', state=1 represents 'accepted' and state=2 represents 'rejected'. Is it possible to put these values / constants into t

Why the extra minute in PostgreSQL when using time zone info?

2015-05-28 Thread Daniel Grace
I am creating some test data for a DateTimeField using the following function: def rndDtTm(self): uktz = timezone('Europe/London') year = 2015 month = 6 day = randint(1, 30) hour = randint(0, 23) minute = 30 * randint(0, 1) return dateti

Re: Why the extra minute in PostgreSQL when using time zone info?

2015-05-28 Thread Daniel Grace
I used this function, seemed to tidy up the problem: from datetime import datetime from pytz import timezone def utcDtTm(self, dt_tm): tz = timezone('Europe/London') return tz.normalize(tz.localize(dt_tm)).astimezone(timezone('UTC')) -- You received this message because you

How to serialize one record with Django / REST?

2015-06-14 Thread Daniel Grace
I can serialize all objects using the following. In views: class ProductDetail(generics.ListAPIView): serializer_class = ProductSerializer def get_queryset(self): return Product.objects.all() In serializers: class ProductSerializer(serializers.ModelSerializer): class Meta:

Preferred way of adding social authorization to a Django / REST app?

2015-06-18 Thread Daniel Grace
What is the preferred way of adding social authorization to a Django / REST app? I see that there are at least two packages: django-rest-framework-social-oauth2 (see https://pypi.python.org/pypi/django-rest-framework-social-oauth2/0.0.4) and django-rest-auth (see http://django-rest-auth.readt

Errors with django-rest-auth and django-allauth

2015-06-20 Thread Daniel Grace
I have installed Django (1.8), django-allauth (0.20.0) django-rest-auth (0.4.0). I added to INSTALLED_APPS in settings.py: 'rest_framework', 'rest_framework.authtoken', 'rest_auth' 'allauth', 'allauth.account', 'rest_auth.registration', 'allauth.socialaccount', 'al

django-rest-auth with django-allauth not what I was expecting

2015-06-23 Thread Daniel Grace
I am trying to write a Django / REST API back end with Facebook authentication, for use with a phone app front end. I installed and configured both django-rest-auth and django-allauth. When testing I can log into Facebook and authorise my app to access my Facebook account, OK. But then I am f

Error using django-rest-framework-social-oauth2

2015-06-23 Thread Daniel Grace
I have installed and set up django-rest-framework-social-oauth2, as per instructions on: https://pypi.python.org/pypi/django-rest-framework-social-oauth2/0.0.4 I did makemigrations and migrate, but there were no extra tables... when I go to "Django administration - Site administration" and click

Re: Error using django-rest-framework-social-oauth2

2015-06-23 Thread Daniel Grace
OK, my mistake, I ran migrate again and got the neccessary tables. -- 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

Error when adding application record for django-rest-framework-social-oauth2

2015-06-25 Thread Daniel Grace
I am following the instructions for django-rest-framework-social-oauth2 at https://pypi.python.org/pypi/django-rest-framework-social-oauth2/0.0.4 When I attempt to add an application record via "Home › Oauth2_Provider › Applications › Add application", I get the error message "Select a valid ch

Re: Error when adding application record for django-rest-framework-social-oauth2

2015-06-25 Thread Daniel Grace
OK, I sussed this. I entered "1" for the user field, the form was then valid and the record saved to the database. -- 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

How to protect a REST API view with token authentication using django-rest-framework-social-oauth2?

2015-06-27 Thread Daniel Grace
I have installed and setup the django-rest-framework-social-oauth2 package. Now I need to protect my REST API views with the appropriate token authentication. Do I follow the method at: http://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication or is another method app

How to restrict update of a record to the record owner in Django REST?

2015-07-04 Thread Daniel Grace
I want to restrict update of a record to the record owner in an UpdateAPIView with Django REST, but I don't know how to code the method. For example, something like this: from rest_framework import generics from testapp.serializers import UserProfileSerializer from rest_framework.renderers impor

Re: How to restrict update of a record to the record owner in Django REST?

2015-07-04 Thread Daniel Grace
I found a solution based on the example in REST API guide: http://www.django-rest-framework.org/api-guide/permissions/#examples -- 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, sen

Where does django-rest-framework-social-oauth2 create Django user accounts?

2015-07-05 Thread Daniel Grace
Where in the source code does django-rest-framework-social-oauth2 (which uses django-oauth-toolkit and python-social-auth) auto create Django user accounts? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and sto

How to protect a view with client ID and client secret in REST / oauth toolkit?

2015-07-06 Thread Daniel Grace
Say I have a REST view: class CreateUserView(generics.CreateAPIView): serializer_class = CreateUserSerializer queryset = User.objects.all() ...how is it possible to protect the view with the client ID and client secret from the oauth toolkit? So that I can invoke the view via a special

Re: How to protect a view with client ID and client secret in REST / oauth toolkit?

2015-07-07 Thread Daniel Grace
I guess there are more standard ways of protecting a view. -- 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

Error when checking owner in REST API CreateAPIView

2015-07-09 Thread Daniel Grace
With CreateAPIView from the REST API I am trying to stop users from creating data in another users name. In models.py: class UserData(models.Model): user = models.OneToOneField(User, db_index=True, related_name='userdata', blank=False, null=False) textdata = models.TextField(blank=True,

Not getting create table statements as described in the tutorial

2014-08-09 Thread Daniel Grace
I am following the tutorial at https://docs.djangoproject.com/en/1.6/intro/tutorial01/ I typed in the command: python manage.py sql polls but there were no messages, and I did not get the create statements that are mentioned in the tutorial. I'm not sure what is going on. -- You received this m

Error in shell when following Django tutorial

2014-08-09 Thread Daniel Grace
I get an error in the shell when following the tutorial https://docs.djangoproject.com/en/1.6/intro/tutorial01/ C:\Users\Daniel\My Documents\Python\DjangoTest\mysite>python manage.py shell Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AM D64)] on win32 Type "help",

Error in shell when following Django tutorial

2014-08-09 Thread Daniel Grace
I get an error in the shell when following the tutorial https://docs.djangoproject.com/en/1.6/intro/tutorial01/ C:\Users\Daniel\My Documents\Python\DjangoTest\mysite>python manage.py shell Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AM D64)] on win32 Type "help",

How to run Python script? (configure settings error)

2014-08-13 Thread Daniel Grace
I have a Python script as follows: from django.db import transaction from django.contrib.auth.models import User from flow.models import States, Types, Docs, Logs if __name__ == '__main__': with transaction.atomic(): models.Logs.objects.all().delete() models.Docs.objects.all()

Re: How to run Python script? (configure settings error)

2014-08-13 Thread Daniel Grace
I used this method and got my script working OK. On Wednesday, 13 August 2014 15:37:30 UTC+1, Andrew Farrell wrote: > > Note: this is much better documented at > https://docs.djangoproject.com/en/dev/howto/custom-management-commands/ > > You want to move this file to the management.commands modul

How to disable application / project?

2014-08-14 Thread Daniel Grace
I have two projects "djangotest" (from the django tutorial) and "cresta". When I start the server with the "runserver" command in the cresta directory and go to http://127.0.0.1:8000/admin/ ... I see "Polls Tutorial". I can't login with any users from the cresta database. How do I disable the Po

I can't load fixtures

2014-08-14 Thread Daniel Grace
I created a fixtures file called testdata.xml in a fixtures folder, but I can't load the fixtures file into the database. I placed an __init__.py file in the fixtures folder (not sure about this step, is it needed?) I put the fixtures directory in settings.py: FIXTURE_DIRS = ( '/myapp/fixtur

Cannot import in admin.py

2014-08-14 Thread Daniel Grace
I get an error after editing my admin.py file as follows: from django.contrib import admin from flow.models import Flow admin.site.register(Flow) ... here is the error: ImportError at / cannot import name 'Flow' Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.6.5 Excepti

How to set block variable in view code?

2014-08-18 Thread Daniel Grace
I am struggling to understand block variables. I have two block variables in my HTML template as follows: {% block side_hdr %}{% endblock%} {% block content %}{% endblock %} How (if possible) do I set these variables in my class based view? class TestView(TemplateView): template_name = "

How to set block variable in view code?

2014-08-18 Thread Daniel Grace
I am struggling to understand block tags. I have two block tags in my HTML template as follows: {% block side_hdr %}{% endblock%} {% block content %}{% endblock %} How (if possible) do I set these tags in my class based view? class TestView(TemplateView): template_name = "base.html" Tha

Re: How to set block variable in view code?

2014-09-14 Thread Daniel Grace
Thanks for the info. I am beginning to see the power of these substitutions. -- 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...@googlegro

syncdb error with Mysql database on Windows 7

2014-09-24 Thread Daniel Grace
I have a virtualenv with Python 3.4, Django 1.7 and MySQL installed on Windows 7. I also have the MySQL / Python adapter installed and the database settings in settings.py: DATABASES = { 'default': { 'NAME': 'mydb', 'ENGINE': 'mysql.connector.django', 'USER': 'root',

Re: syncdb error with Mysql database on Windows 7

2014-09-27 Thread Daniel Grace
For the record I solved this, I was mistaken there was no "mydb" schema in MySQL. I created this schema and ran the "syncdb" command without any problems. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop

Error installing psycopg2-2.5.4 on Windows 7

2014-09-27 Thread Daniel Grace
Hi, I have Python 3.4, Django 1.7 and Postgresql 9.3 installed. I get the following error when installing pscyopg2-2.5.4 on Windows 7: Python version 3.4 required, which was not found in the registry. Any ideas? Thanks. -- You received this message because you are subscribed to the Google Gr

Re: Error installing psycopg2-2.5.4 on Windows 7

2014-09-27 Thread Daniel Grace
I solved this. I was using the wrong version of psycopg2, I needed the 64 bit version. On Saturday, 27 September 2014 14:35:43 UTC+1, Daniel Grace wrote: > > Hi, > I have Python 3.4, Django 1.7 and Postgresql 9.3 installed. I get the > following error when installing pscyopg2-2.5.

Problems with psycopg2 on Windows 7 64 bit

2014-09-27 Thread Daniel Grace
I have installed Python 3.4, Django 1.7, Postgresql 9.3 and psycopg2-2.5.4 (using the Windows installer at http://www.stickpeople.com/projects/python/win-psycopg/) When I try a syncdb command from my virtualenv I get the following error: (landy) C:\landy\cresta>python manage.py syncdb Traceback

Re: Problems with psycopg2 on Windows 7 64 bit

2014-09-27 Thread Daniel Grace
I got around this particular problem. The Windows installer for psycopg (at http://www.stickpeople.com/projects/python/win-psycopg/ ) installs f

Problem with populate script

2014-09-29 Thread Daniel Grace
I am trying to follow the tutorial at http://www.tangowithdjango.com/ I am stuck in section 5.8 where it shows how to create a script to populate the database. I created a script called "populate.py" as shown (except I added brackets for the Python 3 print statements), and saved it in the root di

Re: Problem with populate script

2014-10-01 Thread Daniel Grace
I got this working, I had to do two things. 1. add the following line at the top of the script: import django 2. add the following line after "os.environ.setdefault...": django.setup() -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscri

Python question about positioning of "from... import" statement

2014-10-01 Thread Daniel Grace
Hi, this is more of a Python question but here is something I don't understand in a Django script. The following script works fine: import os import django if __name__ == '__main__': print("Starting Rango delete data script...") os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tango.sett

Re: Python question about positioning of "from... import" statement

2014-10-01 Thread Daniel Grace
OK, I should have read the warning on the Tango with Django page section 5.8: "When importing Django models, make sure you have imported your project’s settings by that stage. If you don’t, an exception will be raised. This is why we import Category and Page towards the end of the population sc

How to get user ID and ID of newly created record in a CreateView?

2014-10-10 Thread Daniel Grace
Hi, I am using a CreateView. I want to create some related data on a table ("Log" model), so I need the ID of the record being created for the related field (see "flow" below). Also I need the ID of the user creating the record. Something like the following: from django.utils import timezone

Re: How to get user ID and ID of newly created record in a CreateView?

2014-10-12 Thread Daniel Grace
I get the error: 'CreateFlow' object has no attribute 'user' How do I get the id of the record just created? -- 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 dja

Problem when getting the ID of the record just created

2014-10-13 Thread Daniel Grace
Hi, I have problem when getting the ID of the record just created. class CreateFlow(CreateView): model = Flow fields = ['state'] template_name = 'create_flow.html' def form_valid(self, form): user = User.objects.get(pk=self.request.user.id) flow = Flow.objects.get(pk=self.kwargs['pk']) log = Log(u

Re: How to get user ID and ID of newly created record in a CreateView?

2014-10-13 Thread Daniel Grace
I made a different approach after getting help, which I now have working: https://groups.google.com/forum/#!topic/django-users/eYDfCEZ0eQQ On Monday, 13 October 2014 14:45:09 UTC+1, Collin Anderson wrote: > > Hi Daniel, > > Interesting. Could you post a traceback? > > Thanks, > Collin > > -- You

Re: Problem when getting the ID of the record just created

2014-10-13 Thread Daniel Grace
Thanks for the help. I got the ID working and I used the "self.user.request". -- 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...@googlegr

What is the correct way to set a field value in the form_valid method of a CreateView?

2014-10-13 Thread Daniel Grace
Hi, What is the correct way to set a field value in the form_valid method of a CreateView? Note the field is not on the form and I don't want to use a default value in the model. For example: def get_state(type_desc, state_desc): type = Type.objects.get(description=type_desc) return State.objec

Naive datetime / time zone warning

2014-10-13 Thread Daniel Grace
Hi. Here is my model: class Flow(models.Model): state = models.ForeignKey(State) created = models.DateTimeField(default=datetime.now) modified = models.DateTimeField(db_index=True, default=datetime.now) def __str__(self): return str(self.id) I am getting warnings about time zone support such as t

Re: Naive datetime / time zone warning

2014-10-13 Thread Daniel Grace
I changed "datetime.now" to "timezone.now" and I get the exact same warning. What is going on? -- 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+uns

Re: Naive datetime / time zone warning

2014-10-13 Thread Daniel Grace
I used "auto_now_add=True" in the model and the warning went away. -- 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

Re: What is the correct way to set a field value in the form_valid method of a CreateView?

2014-10-14 Thread Daniel Grace
I found the way to do this is with the "form.save" method, for example in the form_valid: state = get_state("test type", "test state") obj = form.save(commit=False) obj.state = state obj.save() -- You received this message because you are subscribed to the Google Groups "Django users" group. To

Problem with a token in my custom template tag

2014-10-15 Thread Daniel Grace
Hi, I'm encountering the following problem with a token in my custom template tag: Request Method: GET Request URL: http://127.0.0.1:8000/flows/ Django Version: 1.7 Exception Type: ValueError Exception Value: need more than 2 values to unpack Exception Location: C:\landy\cresta\flow\templatetags\

Re: Problem with a token in my custom template tag

2014-10-15 Thread Daniel Grace
I got it working thanks. My template tag file is as follows: from django import template from django.utils import timezone register = template.Library() @register.simple_tag def rowcolour(dt): diff = timezone.now() - dt if diff.days > 14: return "pinkrow" else: return "greyrow" -- You receive

How to display BST (British Summer Time)?

2014-10-17 Thread Daniel Grace
Hi, I have the time zone set as follows: TIME_ZONE='Europe/London' USE_TZ = True This is the same as GMT. But what I want is BST (British Summer Time) for display purposes, which is UTC + 1 for the "summer" and UTC for the rest of the year. How do I convert to this the value in my templates?

Re: How to display BST (British Summer Time)?

2014-10-17 Thread Daniel Grace
The date function can only display the offset, it does not actually add the offset to the date time. -- 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-user

Re: How to display BST (British Summer Time)?

2014-10-17 Thread Daniel Grace
I installed pytz and this problem went away. 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 gr

NoReverseMatch error

2014-10-18 Thread Daniel Grace
Hi, I get the following error on one of my view forms: Request Method: GET Request URL: http://127.0.0.1:8000/test/test_type_1/test_state_1/ Django Version: 1.7 Exception Type: NoReverseMatch Exception Value: Reverse for 'create-flow-params' with arguments '()' and keyword arguments '{}' not foun

Re: NoReverseMatch error

2014-10-19 Thread Daniel Grace
You were right Vijay. I worked this out. I needed to set type and state via the context as follows: def get_context_data(self, **kwargs): context = super(TestFlow, self).get_context_data(**kwargs) context.update({'type': self.kwargs['type'], 'state': self.kwargs['state']}) return c

Best way to display master detail data, with class based view or function based view?

2014-10-19 Thread Daniel Grace
I have implemented a model where one flow has many events as follows: class Event(models.Model): flow = models.ForeignKey(Flow) ... I need a page to display one or two fields from a single flow and a list of all related events. Should I implement this with a DetailView, a ListView (if either

Re: Best way to display master detail data, with class based view or function based view?

2014-10-19 Thread Daniel Grace
I found the following thread at stackoverflow: http://stackoverflow.com/questions/9777121/django-generic-views-when-to-use-listview-vs-detailview I may want to paginate the list so it would seem to make sense to use the list view (for the events) and just display the flow fields at the top of th

How do I display list of pages with a ListView object?

2014-10-22 Thread Daniel Grace
Hi, How do I display list of pages with a ListView object? For example display a link for each page (except maybe the current page): previous 1 2 3 4 next Currently I use the following in a view to display "previous" and "next": {% if page_obj.has_previous %} previous {% endif %} Page {{ page_ob

Re: How do I display list of pages with a ListView object?

2014-10-22 Thread Daniel Grace
I found a solution by writing a custom template tag, passing in the current page and number of pages from page_obj. Is that an acceptable solution or can this be done without a custom tag? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsu

Is there a way to supress blank lines in the HTML?

2014-10-22 Thread Daniel Grace
Hi, Is there a way to suppress blank lines in the HTML? I tried using the spaceless tag but it is overkill for what I want. I just want to suppress the blank lines from the HTML and not all space. Any ideas? Thanks -- You received this message because you are subscribed to the Google Groups "D

Re: Is there a way to supress blank lines in the HTML?

2014-10-24 Thread Daniel Grace
Thanks people for the info. I was looking for a way to beautify the code, rather than for performance / compression. In particular I came across this when I implemented a template tag which, under certain circumstances returns an empty string. This works well but causes blank lines in the co

Problem with Pillow image resize and save

2014-10-24 Thread Daniel Grace
Hi, I am trying to put together some code for resizing an image and storing the resized image on the database, but I am running into some problems having struggled to find some decent examples online. Here is what I have come up with so far, in the model: class UserProfile(models.Model): u

Re: Problem with Pillow image resize and save

2014-10-25 Thread Daniel Grace
I need to include the following steps, but I don't know how: 1. copy the 'picture' file 2. resize it (the copy) 3. save it to the upload directory 4. store it in the 'thumb' field ... continue as before and save the 'profile'. -- You received this message because you are subscribed to the Google

How to get related data on one to one field of a foreign key?

2014-10-25 Thread Daniel Grace
Hi, I have a log table with a foreign key to the user table, and a userprofile table with a one to one field to the user table: class Log(models.Model): user = models.ForeignKey(User) ... class UserProfile(models.Model): user = models.OneToOneField(User) picture = models.ImageFie

Re: How to get related data on one to one field of a foreign key?

2014-10-25 Thread Daniel Grace
I just used the following: {{ log.user.userprofile.picture }} ... and I didn't need the select_related. -- 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-us

How to get rid of help text on a ModelForm?

2014-10-27 Thread Daniel Grace
Hi, I have a ModelForm for creating users, but it shows some help text "Required. 30 characters..." next to the username field. How do I get rid of this text? I tried the following, but the text remains on the form: class UserForm(forms.ModelForm): password = forms.CharField(widget=forms.Pa

Re: How to get rid of help text on a ModelForm?

2014-10-28 Thread Daniel Grace
Oops, too much indentation on the "def ..." line. -- 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 grou

What is the purpose of the include function?

2014-10-28 Thread Daniel Grace
Hi, In reference to urls.py what is the purpose of the include function? For example what is the difference between these two lines? url(r'^admin/', admin.site.urls), url(r'^admin/', include(admin.site.urls)), -- You received this message because you are subscribed to the Google Groups "Djang

Calling a function for a url tag parameter

2014-10-30 Thread Daniel Grace
Hi, I am trying to use the url tag on some parameters, one of which needs to come from a function. For example as follows: {% with state_url=encode_url flow.state.description %} advance encode_url is defined as follows: @register.simple_tag def encode_url(link_text): return link_text.replace(

How to generally handle exceptions in function based and class based views?

2014-11-02 Thread Daniel Grace
Hi, I'm looking for some information / examples of how to generally handle exceptions and show a message to the user, in function based and class based views. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and s

Re: How to generally handle exceptions in function based and class based views?

2014-11-03 Thread Daniel Grace
OK, say if I have a function based view then how do I handle the exception? try: context = RequestContext(request) context_dict = {} ... return render_to_response('my_file.html', context_dict, context) except Exception as e: # what to do here? What about class based views (in

How to handle exceptions in RequestContext?

2014-11-03 Thread Daniel Grace
Say I have the following code: try: context_dict = {} context = RequestContext(request) ... except Exception as e: return render_to_response('error.html', context_dict, context) ...then how do I handle the exception without a context? Should I use the render function instead of

Re: How to generally handle exceptions in function based and class based views?

2014-11-03 Thread Daniel Grace
Thanks for the information Aliane and Steven, although I still don't know what to do when handling exceptions in say form_valid of a CBV. How to render the error in this case? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe fro

How to handle exceptions if RequestContext fails?

2014-11-03 Thread Daniel Grace
Say I have the following code: logger = logging.getLogger(__name__) def render_error(scr_msg, err_msg, context): logger.debug(err_msg) return render_to_response('error.html', {'message': scr_msg}, context) ... def some_view(): try: context = RequestContext(request) ...

Re: How to handle exceptions in RequestContext?

2014-11-05 Thread Daniel Grace
I see where you are coming from Carl, thanks for the information. Do you have a suitable example of where one might put error handling in the view code? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop r

How to restrict a class based view to one user group?

2014-11-05 Thread Daniel Grace
Hi, Say I have a function as follows: def is_supervisor(user): return user.groups.filter(name='supervisor').exists() ...and a CBV for deleting records: class DeleteFlow(DeleteView): # etc... How can I restrict access to this view using the function? I understand that this may be possibl

Re: How to restrict a class based view to one user group?

2014-11-06 Thread Daniel Grace
I solved this using a "method_decorator" and "user_passes_test". -- 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 po

Re: How to restrict a class based view to one user group?

2014-11-06 Thread Daniel Grace
Thanks Bruno, I was decorating the 'post' method. I've got it right now. -- 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.c

Forms / pages and CSS like Django admin

2014-11-06 Thread Daniel Grace
Hi, OK, I know how to import CSS into a template. I would like to get forms / pages that look like those on Django admin site. What is a good strategy to achieve this? Copy the CSS? Looking at "inspect element" in Google Chrome I see that the styling on the forms in the Django admin site do n

Database "postgres" does not exist error when running test command

2014-11-14 Thread Daniel Grace
Hi, I get an error when running the test command: >python manage.py test flow Creating test database for alias 'default'... Traceback (most recent call last): File "C:\landy\lib\site-packages\django\db\backends\__init__.py", line 133, in ensure_connection self.connect() File "C:\landy\li

Re: Database "postgres" does not exist error when running test command

2014-11-15 Thread Daniel Grace
On Saturday, 15 November 2014 00:58:32 UTC, Aliane Abdelouahab wrote: > > how about this > http://stackoverflow.com/a/19426770/861487 > > That link, what is that about? Anyway, I manually created a database called "postgres" and the error went away. -- You received this message because you are

Runtime warning about a naive datetime when running the test command

2014-11-15 Thread Daniel Grace
Hi, I get a runtime warning about a naive datetime when running the test command: >python manage.py test flow Creating test database for alias 'default'... C:\landy\lib\site-packages\django\db\models\fields\__init__.py:1278: RuntimeWarn ing: DateTimeField Flow.created received a naive datetime (

Re: Runtime warning about a naive datetime when running the test command

2014-11-16 Thread Daniel Grace
I understand the problem. Why doesn't the Django tester provide time zone aware date times? I know if I set "USE_TZ = False" the warnings will disappear. I was looking for another solution. Could I conditionally set "USE_TZ = False" only when testing? -- You received this message because y

Re: Runtime warning about a naive datetime when running the test command

2014-11-16 Thread Daniel Grace
Is this a bug in the Django tester? -- 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

Re: Runtime warning about a naive datetime when running the test command

2014-11-17 Thread Daniel Grace
On Monday, 17 November 2014 11:33:40 UTC, Bruno Barcarol Guimarães wrote: > > > $ python -W error manage.py test > > Hi Bruno, I get another warning / error with that command: >python -W error manage.py test flow Traceback (most recent call last): File "manage.py", line 8, in from django.c

Warning / Error when testing with W flag

2014-11-18 Thread Daniel Grace
Hi, I get another warning / error with a test command as follows: >python -W error manage.py test flow Traceback (most recent call last): File "manage.py", line 8, in from django.core.management import execute_from_command_line File "C:\landy\lib\site-packages\django\core\management\__init

What on earth is causing this "naive datetime" warning?

2014-11-19 Thread Daniel Grace
Hi, Here is my model: class Flow(models.Model): ref = models.CharField(max_length=32) state = models.ForeignKey(State) flow_type = models.ForeignKey(Type) created = models.DateTimeField(db_index=True, auto_now_add=True) modified = models.DateTimeField(db_index=True, auto_now=Tr

Re: What on earth is causing this "naive datetime" warning?

2014-11-19 Thread Daniel Grace
I have already installed pytz (2014.17) and I have set USE_TZ=True. I don't use any naive datetimes in my application. This error is caused by something that the Django test command is doing automatically, if you look at the traceback you will see that it is something to do with migrations.

Re: What on earth is causing this "naive datetime" warning?

2014-11-19 Thread Daniel Grace
On Wednesday, 19 November 2014 15:11:27 UTC, Carl Meyer wrote: > > Hi Daniel, > > On 11/19/2014 08:07 AM, Daniel Grace wrote: > > I have already installed pytz (2014.17) and I have set USE_TZ=True. I > > don't use any naive datetimes in my application. This erro

Re: What on earth is causing this "naive datetime" warning?

2014-11-19 Thread Daniel Grace
> > > But based on your traceback, it seems like at some point in the past > when you made a migration, the field might have had a default value > which was a naive datetime. Is that possible? > > It might be necessary to look through your existing migrations for this > app to find the culprit

How to make a subscription form for use with Stripe / dj-stripe?

2017-12-04 Thread Daniel Grace
I have set up a Stripe account and installed dj-stripe, but I can't find information on how to set up a subscription form. I understand that dj-stripe looks for a template in the djstripe directory, but I don't know what should be in the template. -- You received this message because you are

How to hook into the admin site to count login attempts with REST API / proxy?

2016-11-04 Thread Daniel Grace
Hello, I have a REST API which is not publicly accessible as it is behind a proxy. However the admin site is publicly available through an NGINX server. The REST API already has functionality to count failed login attempts and I would like to duplicate that functionality on the admin login pa

How do you access the HTTP data in a view derived from the generic View class?

2015-08-20 Thread Daniel Grace
Suppose I have a view as follows: from django.views.generic import View from django.http import HttpResponse from braces.views import CsrfExemptMixin class TestView(CsrfExemptMixin, View): def post(self, request, *args, **kwargs): # how to access the HTTP data here? return Htt

Re: How do you access the HTTP data in a view derived from the generic View class?

2015-08-20 Thread Daniel Grace
I found the answer to this is to look at request.POST. -- 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