22# -*- coding: utf-8 -*-
33from __future__ import unicode_literals
44
5- from datetime import datetime
6-
7- from django .conf import settings
5+ from django .contrib .auth import get_user_model
86from django .db import models
7+ from django .utils import timezone
98
9+ from tigaserver_app .models import Fix as TigaserverAppFix , Notification , NotificationContent , Report
1010
11- class UserfixesManager (models .Manager ):
12- """a."""
13-
14-
15- class Userfixes (models .Model ):
16- """Userfixes model."""
17-
18- id = models .IntegerField (primary_key = True )
19- fix_time = models .DateTimeField (blank = True , null = True )
20- masked_lon = models .FloatField (blank = True , null = True )
21- masked_lat = models .FloatField (blank = True , null = True )
22-
23- def _get_the_type (self ):
24- """a."""
25- return 'Feature'
26-
27- thetype = property (_get_the_type )
28-
29- class Meta :
30- """Meta information."""
31-
32- db_table = 'tigaserver_app_fix'
33- managed = False
34-
11+ AuthUser = User = get_user_model ()
12+ Userfixes = TigaserverAppFix
3513
3614class NotificationImageFormModel (models .Model ):
3715 """NotificationImageFormModel."""
@@ -107,46 +85,6 @@ class Meta:
10785 db_table = 'municipis_4326'
10886
10987
110- class AuthUserManager (models .Manager ):
111- """AuthUser manager. Ordering by username."""
112-
113- def get_queryset (self ):
114- """Just ordering province name."""
115- return super (AuthUserManager , self ).get_queryset ().order_by ('username' )
116-
117-
118- class AuthUser (models .Model ):
119- """Users who can get authenticated at the map."""
120-
121- id = models .IntegerField (primary_key = True )
122- password = models .CharField (max_length = 128 )
123- last_login = models .DateTimeField ()
124- is_superuser = models .BooleanField ()
125- username = models .CharField (max_length = 30 )
126- first_name = models .CharField (max_length = 30 )
127- last_name = models .CharField (max_length = 30 )
128- email = models .CharField (max_length = 75 )
129- is_staff = models .BooleanField ()
130- is_active = models .BooleanField ()
131- date_joined = models .DateTimeField ()
132- province = models .ManyToManyField (Province , blank = True )
133- municipalities = models .ManyToManyField (Municipalities , blank = True )
134-
135- objects = AuthUserManager ()
136-
137- def __str__ (self ):
138- """Convert this object into a string."""
139- return self .username
140-
141- class Meta :
142- """Meta."""
143-
144- managed = False
145- db_table = 'auth_user'
146- verbose_name = 'User (municipalities)'
147- verbose_name_plural = 'User (provinces and municipalities)'
148-
149-
15088class ReportsMapData (models .Model ):
15189 """All mosquito observations."""
15290
@@ -173,8 +111,8 @@ class Meta:
173111class MapAuxReports (models .Model ):
174112 """All mosquito observations."""
175113
176- id = models .IntegerField (primary_key = True )
177- version_uuid = models .CharField ( max_length = 36 , blank = True , unique = True )
114+ id = models .AutoField (primary_key = True )
115+ version_uuid = models .OneToOneField ( Report , db_column = 'version_uuid' , related_name = 'map_aux_report' , on_delete = models . CASCADE )
178116 user_id = models .CharField (max_length = 36 , blank = True )
179117 observation_date = models .DateTimeField (null = True , blank = True )
180118 lon = models .FloatField (blank = True , null = True )
@@ -207,7 +145,7 @@ class MapAuxReports(models.Model):
207145 class Meta :
208146 """Meta."""
209147
210- managed = True
148+ managed = False
211149 db_table = 'map_aux_reports'
212150
213151
@@ -228,8 +166,8 @@ class StormDrain(models.Model):
228166 code = models .CharField (max_length = 50 , blank = True , null = True )
229167 lon = models .DecimalField (max_digits = 9 , decimal_places = 6 )
230168 lat = models .DecimalField (max_digits = 9 , decimal_places = 6 )
231- user = models .ForeignKey (AuthUser , on_delete = models .CASCADE )
232- date = models .DateTimeField (default = datetime .now , blank = True , null = True )
169+ user = models .ForeignKey (User , on_delete = models .CASCADE )
170+ date = models .DateTimeField (default = timezone .now , blank = True , null = True )
233171 original_lon = models .FloatField (blank = True , null = True )
234172 original_lat = models .FloatField (blank = True , null = True )
235173 size = models .CharField (max_length = 5 , blank = True , null = True )
@@ -242,36 +180,6 @@ class Meta:
242180 managed = False
243181
244182
245- class NotificationContent (models .Model ):
246- """Notification content."""
247-
248- id = models .AutoField (help_text = 'Unique identifier of the notification.'
249- 'Automatically generated by server when notification'
250- 'created.' , primary_key = True )
251- body_html_es = models .TextField (help_text = 'Expert comment, expanded and'
252- 'allows html, in spanish' )
253- body_html_ca = models .TextField (help_text = 'Expert comment, expanded and'
254- 'allows html, in catalan' , default = None ,
255- blank = True , null = True )
256- body_html_en = models .TextField (help_text = 'Expert comment, expanded and'
257- 'allows html, in english' , default = None ,
258- blank = True , null = True )
259- title_es = models .TextField (help_text = 'Title of the comment, shown in'
260- 'non-detail view, in spanish' )
261- title_ca = models .TextField (help_text = 'Title of the comment, shown in'
262- 'non-detail view, in catalan' , default = None ,
263- blank = True , null = True )
264- title_en = models .TextField (help_text = 'Title of the comment, shown in'
265- 'non-detail view, in english' , default = None ,
266- blank = True , null = True )
267-
268- class Meta :
269- """Meta."""
270-
271- db_table = 'tigaserver_app_notificationcontent'
272- managed = False
273-
274-
275183class PredefinedNotificationManager (models .Manager ):
276184 """PredefinedNotification manager. Ordering."""
277185
@@ -287,7 +195,7 @@ class PredefinedNotification(models.Model):
287195 id = models .AutoField (primary_key = True , help_text = 'Unique identifier of'
288196 'the notification. Automatically generated by server'
289197 'when notification created.' )
290- user = models .ForeignKey (AuthUser , on_delete = models .CASCADE )
198+ user = models .ForeignKey (User , on_delete = models .CASCADE )
291199 body_html_es = models .TextField (help_text = 'Expert comment, expanded and'
292200 'allows html, in spanish' )
293201 body_html_ca = models .TextField (help_text = 'Expert comment, expanded and'
@@ -318,44 +226,13 @@ class Meta:
318226 db_table = 'tigaserver_app_notificationpredefined'
319227
320228
321- class Notification (models .Model ):
322- """Notifications."""
323-
324- report = models .ForeignKey (MapAuxReports , to_field = 'version_uuid' ,
325- on_delete = models .CASCADE )
326- user_id = models .CharField (max_length = 36 , blank = False )
327- expert = models .ForeignKey (AuthUser , on_delete = models .CASCADE )
328- date_comment = models .DateTimeField (auto_now_add = True )
329- expert_comment = models .TextField ('Expert comment' ,
330- help_text = 'Text message sent to user' )
331- expert_html = models .TextField ('Expert comment, expanded and allows html' ,
332- help_text = 'Expanded message information'
333- 'goes here. This field can contain HTML' )
334- photo_url = models .TextField ('Url to picture that originated the comment' ,
335- help_text = 'Relative url to the public report'
336- 'photo' , null = True , blank = True )
337- acknowledged = models .BooleanField (help_text = 'This is set to True through'
338- 'the public API, when the user signals'
339- 'that the message has been received' ,
340- default = False )
341- public = models .BooleanField (default = False )
342- notification_content = models .ForeignKey (NotificationContent ,
343- on_delete = models .CASCADE )
344-
345- class Meta :
346- """Meta."""
347-
348- db_table = 'tigaserver_app_notification'
349- managed = False
350-
351-
352229class ObservationNotifications (models .Model ):
353230 """Observation notifications."""
354231
355232 report = models .ForeignKey (MapAuxReports , to_field = 'version_uuid' ,
356233 on_delete = models .CASCADE )
357234 user_id = models .CharField (max_length = 36 , blank = False )
358- expert = models .ForeignKey (AuthUser , on_delete = models .CASCADE )
235+ expert = models .ForeignKey (User , on_delete = models .CASCADE )
359236 date_comment = models .DateTimeField (auto_now_add = True )
360237 expert_comment = models .TextField ('Expert comment' ,
361238 help_text = 'Text message sent to user' )
@@ -379,9 +256,9 @@ class StormDrainUserVersions(models.Model):
379256 """Storm drain user versions."""
380257
381258 id = models .AutoField (primary_key = True )
382- user = models .ForeignKey (AuthUser , on_delete = models .CASCADE )
259+ user = models .ForeignKey (User , on_delete = models .CASCADE )
383260 version = models .IntegerField ()
384- published_date = models .DateTimeField (default = datetime .now )
261+ published_date = models .DateTimeField (default = timezone .now )
385262 style_json = models .TextField ()
386263 visible = models .BooleanField ()
387264 title = models .CharField (max_length = 50 , blank = True )
@@ -427,7 +304,7 @@ class Epidemiology(models.Model):
427304 default = None ,
428305 blank = True ,
429306 null = True )
430- user = models .ForeignKey (AuthUser , on_delete = models .CASCADE )
307+ user = models .ForeignKey (User , on_delete = models .CASCADE )
431308
432309 class Meta :
433310 """Meta."""
0 commit comments