-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Django 1.8(.3) #167
Changes from all commits
0758d03
e9ef43b
d328187
4e9c826
2520408
8a41d85
897e5f2
a00c45c
cc463bb
fcafb75
af7adc7
0ef5014
c849e07
e85f995
df9e470
4f3d50a
a0b117a
56af630
d428418
1695579
101289d
64257db
3b3488e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,7 @@ | |
We try to keep all manual transaction management in clearinghouse to within | ||
this module. The general idea is that the default behavior of django is | ||
what we want in most places (to commit any time data-altering functions | ||
are called, such as .save() or .delete()). However, in a few cases we | ||
want multiple data-altering functions to be committed atomically, so we | ||
use @transaction.commit_manually. | ||
are called, such as .save() or .delete()). | ||
""" | ||
|
||
# It is a bit confusing to just import datetime because then you have to use | ||
|
@@ -159,7 +157,6 @@ def init_maindb(): | |
|
||
|
||
|
||
@transaction.commit_manually | ||
@log_function_call_and_only_first_argument | ||
def create_user(username, password, email, affiliation, user_pubkey, user_privkey, donor_pubkey): | ||
""" | ||
|
@@ -219,21 +216,22 @@ def create_user(username, password, email, affiliation, user_pubkey, user_privke | |
# We're committing manually to make sure the multiple database writes are | ||
# atomic. (That is, regenerate_api_key() will do a database write.) | ||
try: | ||
# Generate a random port for the user's usable vessel port. | ||
port = random.sample(ALLOWED_USER_PORTS, 1)[0] | ||
|
||
# Create the GeniUser (this is actually records in two different tables | ||
# underneath because of model inheretance, but django hides that from us). | ||
geniuser = GeniUser(username=username, password='', email=email, | ||
affiliation=affiliation, user_pubkey=user_pubkey, | ||
user_privkey=user_privkey, donor_pubkey=donor_pubkey, | ||
usable_vessel_port=port, | ||
free_vessel_credits=DEFAULT_FREE_VESSEL_CREDITS) | ||
# Set the password using this function so that it gets hashed by django. | ||
geniuser.set_password(password) | ||
geniuser.save() | ||
|
||
regenerate_api_key(geniuser) | ||
with transaction.atomic(): | ||
# Generate a random port for the user's usable vessel port. | ||
port = random.sample(ALLOWED_USER_PORTS, 1)[0] | ||
|
||
# Create the GeniUser (this is actually records in two different tables | ||
# underneath because of model inheretance, but django hides that from us). | ||
geniuser = GeniUser(username=username, password='', email=email, | ||
affiliation=affiliation, user_pubkey=user_pubkey, | ||
user_privkey=user_privkey, donor_pubkey=donor_pubkey, | ||
usable_vessel_port=port, | ||
free_vessel_credits=DEFAULT_FREE_VESSEL_CREDITS) | ||
# Set the password using this function so that it gets hashed by django. | ||
geniuser.set_password(password) | ||
geniuser.save() | ||
|
||
regenerate_api_key(geniuser) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM, |
||
|
||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw. our code-guidelines urge to use Class-based exceptions (I know this is not part of this PR). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Well-spotted! I've added issue #175 for this.) |
||
transaction.rollback() | ||
|
@@ -575,7 +573,6 @@ def create_vessel(node, vesselname): | |
|
||
|
||
|
||
@transaction.commit_manually | ||
@log_function_call | ||
def set_vessel_ports(vessel, port_list): | ||
""" | ||
|
@@ -604,13 +601,14 @@ def set_vessel_ports(vessel, port_list): | |
# We're committing manually to make sure the multiple database writes are | ||
# atomic. | ||
try: | ||
# Delete all existing VesselPort records for this vessel. | ||
VesselPort.objects.filter(vessel=vessel).delete() | ||
|
||
# Create a VesselPort record for each port in port_list. | ||
for port in port_list: | ||
vesselport = VesselPort(vessel=vessel, port=port) | ||
vesselport.save() | ||
with transaction.atomic(): | ||
# Delete all existing VesselPort records for this vessel. | ||
VesselPort.objects.filter(vessel=vessel).delete() | ||
|
||
# Create a VesselPort record for each port in port_list. | ||
for port in port_list: | ||
vesselport = VesselPort(vessel=vessel, port=port) | ||
vesselport.save() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM, see comment above. |
||
|
||
except: | ||
transaction.rollback() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,18 @@ | |
|
||
from clearinghouse.website import settings | ||
|
||
# Beginning of part of fix for Issue #152 | ||
# Perform django setup (required in Django 1.7+ (possibly 1.6.?+)) to make | ||
# db/models available. We need to do this if we are using a django version | ||
# that has django.setup() (1.7+?) This should happen before the repy patching | ||
# of builtins, which likely occurs in the add_dy_support call in the next line | ||
# of code. django.setup() expects to be able to use the builtin keyword | ||
# 'type', which is patched by repy, so we should do this here, before that | ||
# patching. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider grooming the comment:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above --- don't provide backwards compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In contrast to |
||
if hasattr(django, 'setup'): | ||
django.setup() | ||
# end of Issue #152 fix | ||
|
||
# Import all the repy files. | ||
add_dy_support(locals()) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
<Author> | ||
Justin Samuel | ||
Sai Kaushik Borra | ||
|
||
<Purpose> | ||
This module provides classes that tell django how to represent the models | ||
|
@@ -17,14 +18,15 @@ | |
|
||
from clearinghouse.common.api import maindb | ||
|
||
from clearinghouse.website.control.models import Donation | ||
from clearinghouse.website.control.models import GeniUser | ||
from clearinghouse.website.control.models import Node | ||
from clearinghouse.website.control.models import Vessel | ||
from clearinghouse.website.control.models import VesselPort | ||
from clearinghouse.website.control.models import VesselUserAccessMap | ||
from clearinghouse.website.control.models import ActionLogEvent | ||
from clearinghouse.website.control.models import ActionLogVesselDetails | ||
from models import Donation | ||
from models import GeniUser | ||
from models import Node | ||
from models import Vessel | ||
from models import VesselPort | ||
from models import VesselUserAccessMap | ||
from models import ActionLogEvent | ||
from models import ActionLogVesselDetails | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not seem like a deprecation/removal related change but looks fine, because models is in the same directory. |
||
|
||
from django.contrib import admin | ||
from django.contrib.auth.forms import AdminPasswordChangeForm | ||
|
@@ -244,3 +246,4 @@ class ActionLogVesselDetailsAdmin(admin.ModelAdmin): | |
admin.site.register(VesselUserAccessMap, VesselUserAccessMapAdmin) | ||
admin.site.register(ActionLogEvent, ActionLogEventAdmin) | ||
admin.site.register(ActionLogVesselDetails, ActionLogVesselDetailsAdmin) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,22 @@ | |
|
||
Jason Chen | ||
[email protected] | ||
|
||
Sai Kaushik Borra | ||
[email protected] | ||
<Purpose> | ||
|
||
<Usage> | ||
For more information on forms in django see: | ||
http://docs.djangoproject.com/en/dev/topics/forms/ | ||
""" | ||
|
||
|
||
from clearinghouse.website.control.models import GeniUser | ||
|
||
# from control.models import GeniUser, Sensor, SensorAttribute, ExperimentInfo, ExperimentSensor, ExperimentSensorAttribute | ||
|
||
|
||
from django.contrib.auth.forms import UserCreationForm as DjangoUserCreationForm | ||
import django.forms as forms | ||
|
||
|
@@ -30,6 +38,7 @@ | |
MAX_PUBKEY_UPLOAD_SIZE = 2048 | ||
|
||
class PubKeyField(forms.FileField): | ||
|
||
def clean(self,value,initial): | ||
forms.FileField.clean(self,value,initial) | ||
if value is None: | ||
|
@@ -46,6 +55,8 @@ def clean(self,value,initial): | |
|
||
|
||
|
||
|
||
|
||
class GeniUserCreationForm(DjangoUserCreationForm): | ||
|
||
affiliation = forms.CharField(error_messages={'required': 'Enter an Affiliation'}) | ||
|
@@ -95,8 +106,7 @@ def clean_email(self): | |
|
||
|
||
|
||
|
||
def gen_edit_user_form(field_list=None, *args, **kwargs): | ||
def gen_edit_user_form(field_list='__all__', *args, **kwargs): | ||
""" | ||
<Purpose> | ||
Dynamically generates a EditUserForm depending on field_list. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
<a href="{% url 'mac_installer' username %}">Download installer for Mac</a> | ||
<p> | ||
<strong>Instructions:</strong> | ||
<br />(Note: You must have Python 2.5 installed) | ||
<br />(Note: You must have Python 2.5, 2.6, or 2.7 installed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
</p> | ||
<ol> | ||
<li>Download the {{ TESTBED }} tarball to your computer</li> | ||
|
@@ -61,7 +61,7 @@ | |
<a href="{% url 'linux_installer' username %}">Download installer for Linux</a> | ||
<p> | ||
<strong>Instructions:</strong> | ||
<br />(Note: You must have Python 2.5 installed) | ||
<br />(Note: You must have Python 2.5, 2.6, or 2.7 installed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
</p> | ||
<ol> | ||
<li>Download the {{ TESTBED }} tarball to your computer</li> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY! Maybe we could put this mysterious piece of code into a function. See comment above for why it's mysterious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above --- we require a suitable Django version with
django.setup
from now on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also addressed in e85f995, see above for caveats.