Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update test cases after rebase from master

  • Loading branch information...
commit 137d90339fe2ff1b2cc16f7662986a07a76291e8 1 parent 2670723
@visiblegovernment authored
View
40 mainapp/forms.py
@@ -57,7 +57,8 @@ def __init__(self, ward=None,required=True, widget=None, label=None,
initial=None, help_text=None, *args, **kwargs):
# assemble the opt groups.
choices = []
- choices.append( ('', ugettext_lazy("Select a Category")) )
+ self.ward = ward
+ choices.append( ('', _("Select a Category")) )
if ward:
categories = ward.city.get_categories()
categories = categories.order_by('category_class')
@@ -76,6 +77,11 @@ def __init__(self, ward=None,required=True, widget=None, label=None,
super(CategoryChoiceField,self).__init__(choices=choices,required=required,widget=widget,label=label,initial=initial,help_text=help_text,*args,**kwargs)
def clean(self, value):
+ if not self.ward:
+ # don't bother validating if we couldn't resolve
+ # the ward... this will be picked up in another error
+ return None
+
super(CategoryChoiceField,self).clean(value)
try:
model = ReportCategory.objects.get(pk=value)
@@ -114,48 +120,24 @@ class Meta:
model = Report
fields = ('lat','lon','title', 'address', 'category','photo')
-# category = CategoryChoiceField()
lat = forms.fields.CharField(widget=forms.widgets.HiddenInput)
lon = forms.fields.CharField(widget=forms.widgets.HiddenInput)
-# address = forms.fields.CharField(widget=forms.widgets.HiddenInput)
- def __init__(self,data=None,files=None,initial=None):
+ def __init__(self,data=None,files=None,initial=None,freeze_email=False):
if data:
d2p = DictToPoint(data,exceptclass=None)
else:
d2p = DictToPoint(initial,exceptclass=None)
-<<<<<<< HEAD:mainapp/forms.py
self.pnt = d2p.pnt()
- self.ward = d2p.ward()
- self.update_form = ReportUpdateForm(data)
+ self.ward = d2p.ward()
+ self.update_form = ReportUpdateForm(data=data,initial=initial,freeze_email=freeze_email)
super(ReportForm,self).__init__(data,files, initial=initial)
self.fields['category'] = CategoryChoiceField(self.ward)
def clean(self):
- if not self.ward:
+ if self.pnt and not self.ward:
raise forms.ValidationError("lat/lon not supported")
-=======
- def _get_pnt(self):
- lat = self.cleaned_data.get("lat")
- lon = self.cleaned_data.get("lon")
- pnt = fromstr("POINT(" + lon + " " + lat + ")", srid=4326)
- return(pnt)
-
- def _get_ward(self):
- pnt = self._get_pnt()
- try:
- ward = Ward.objects.get(geom__contains=pnt)
- return(ward)
- except:
- return( None )
-
- def clean(self):
- if self.cleaned_data.has_key('lat') and self.cleaned_data.has_key('lon'):
- ward = self._get_ward()
- if not ward:
- raise forms.ValidationError("lat/lon not supported")
->>>>>>> support open311v2 API:mainapp/forms.py
# Always return the full collection of cleaned data.
return self.cleaned_data
View
34 mainapp/models.py
@@ -259,6 +259,31 @@ def __str__(self):
prefix = "TO:"
return( "%s - %s (%s)" % (self.city.name,rule_behavior.describe(self),prefix) )
+class ApiKey(models.Model):
+
+ WIDGET = 0
+ MOBILE = 1
+
+ TypeChoices = [
+ (WIDGET, 'Embedded Widget'),
+ (MOBILE, 'Mobile'), ]
+
+ organization = models.CharField(max_length=255)
+ key = models.CharField(max_length=100)
+ type = models.IntegerField(choices=TypeChoices)
+ contact_email = models.EmailField()
+ approved = models.BooleanField(default=False)
+
+ def save(self):
+ if not self.key or self.key == "":
+ m = md5.new()
+ m.update(self.contact_email)
+ m.update(str(time.time()))
+ self.confirm_token = m.hexdigest()
+ super(ApiKey,self).save()
+
+ def __unicode__(self):
+ return( str(self.organization) )
class Report(models.Model):
title = models.CharField(max_length=100, verbose_name = ugettext_lazy("Subject"))
@@ -294,6 +319,12 @@ class Report(models.Model):
is_confirmed = models.BooleanField(default=False)
+ # what API did the report come in on?
+ api = models.ForeignKey(ApiKey,null=True,blank=True)
+
+ # this this report come in from a particular mobile app?
+ device_id = models.CharField(max_length=100,null=True,blank=True)
+
objects = models.GeoManager()
def is_subscribed(self, email):
@@ -781,6 +812,9 @@ class Meta:
objects = CityAdminManager()
+
+
+
class DictToPoint():
''' Helper class '''
View
1  mainapp/tests/account.py
@@ -76,6 +76,7 @@ def test_user2(self):
'lon': '-75.6870889663999975',
'category': 5,
'desc': 'The description',
+ 'address': 'Some street',
}
View
1  mainapp/tests/base_cases.py
@@ -10,6 +10,7 @@
CREATE_PARAMS = { 'title': 'A report from our API',
'lat': '45.4043333270000034',
'lon': '-75.6870889663999975',
+ 'address': 'Some Street',
'category': 5,
'desc': 'The description',
'author': 'John Farmer',
View
12 mainapp/tests/open311/v2.py
@@ -5,11 +5,12 @@
import xml.dom.minidom
from django.core import mail
-PATH = os.path.dirname(__file__)
+PATH = os.path.dirname(__file__)
-ANON_CREATE_PARAMS = { 'lat': '45.4301269580000024',
- 'lon': '-75.6824648380000014',
+ANON_CREATE_PARAMS = { 'lat': '45.4198266',
+ 'lon': '-75.6943189',
'service_code': 5,
+ 'location': 'Some Street',
'first_name': 'John',
'last_name':'Farmer',
'title': 'Submitted by our mobile app',
@@ -21,6 +22,7 @@
LOGGEDIN_CREATE_PARAMS = { 'title': 'A report from our API from a logged in user',
'lat': '45.4301269580000024',
'lon': '-75.6824648380000014',
+ 'location': 'Some Street',
'service_code': 5,
'description': 'The description'
}
@@ -34,7 +36,7 @@
'title': None,
'description': ['description:This field is required.'],
'email': ['email:This field is required.'],
- 'phone': ['phone:This field is required.'] }
+ 'phone': None }
class Open311v2(TestCase):
@@ -93,7 +95,7 @@ def _create_request(self, params,expected_errors=None, anon=True):
self.assertEquals( request_id, '6', "we've created a new request" )
else:
self.assertEquals( response.status_code, 400 )
- errors = doc.getElementsByTagName('error')
+ errors = doc.getElementsByTagName('error')
self.assertEquals(len(errors),len(expected_errors))
for error in errors:
error_text = error.childNodes[0].data
View
3  mainapp/views/mobile/open311v2.py
@@ -39,8 +39,7 @@ def _get_category(self):
if len(categories) == 0:
return None
return(categories[0])
-
-
+
def clean_title(self):
data = self.cleaned_data.get('title',None)
if data:
View
1  settings.py
@@ -116,7 +116,6 @@
'mainapp.tests.testsocial_auth.dummy_socialauth.DummyBackend',
)
-SESSION_COOKIE_SECURE = True
SOCIAL_AUTH_USER_MODEL = 'mainapp.FMSUser'
SOCIAL_AUTH_ASSOCIATE_BY_MAIL = True
ACCOUNT_ACTIVATION_DAYS = 14
Please sign in to comment.
Something went wrong with that request. Please try again.