diff options
-rw-r--r-- | locale/fr/LC_MESSAGES/django.po | 115 | ||||
-rw-r--r-- | main/admin.py | 13 | ||||
-rw-r--r-- | main/forms.py | 37 | ||||
-rw-r--r-- | main/models.py | 20 | ||||
-rw-r--r-- | main/widgets.py | 76 |
5 files changed, 206 insertions, 55 deletions
diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 514ca13..bcecb7e 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-01-16 12:14+0100\n" +"POT-Creation-Date: 2009-01-20 00:20+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -27,108 +27,120 @@ msgstr "Ajout d'un point remarquable" msgid "Add a new route" msgstr "Ajout d'un nouveau trajet" -#: main/models.py:36 main/models.py:49 main/models.py:61 main/models.py:73 -#: main/models.py:111 main/models.py:179 main/models.py:247 +#: main/models.py:35 main/models.py:48 main/models.py:60 main/models.py:72 +#: main/models.py:110 main/models.py:178 main/models.py:246 main/models.py:265 msgid "Name" msgstr "Nom" -#: main/models.py:37 main/models.py:50 main/models.py:74 main/models.py:117 -#: main/models.py:185 main/models.py:249 +#: main/models.py:36 main/models.py:49 main/models.py:73 main/models.py:116 +#: main/models.py:184 main/models.py:248 main/models.py:267 msgid "Available" msgstr "Disponible" -#: main/models.py:38 +#: main/models.py:37 msgid "Date" msgstr "Date" -#: main/models.py:44 +#: main/models.py:43 msgid "News" msgstr "Nouvelle" -#: main/models.py:51 main/models.py:77 main/models.py:248 +#: main/models.py:50 main/models.py:76 main/models.py:247 main/models.py:266 msgid "Order" msgstr "Ordre" -#: main/models.py:56 main/models.py:72 templates/edit.html:18 +#: main/models.py:55 main/models.py:71 templates/edit.html:18 #: templates/edit_route.html:18 msgid "Category" msgstr "Catégorie" -#: main/models.py:62 main/models.py:114 main/models.py:182 +#: main/models.py:61 main/models.py:113 main/models.py:181 #: templates/edit.html:37 templates/edit_route.html:38 msgid "Image" msgstr "Image" -#: main/models.py:67 main/models.py:75 +#: main/models.py:66 main/models.py:74 msgid "Icon" msgstr "Icone" -#: main/models.py:78 +#: main/models.py:77 msgid "Marker" msgstr "Point d'intérêt" -#: main/models.py:79 main/models.py:181 main/models.py:198 +#: main/models.py:78 main/models.py:180 main/models.py:197 #: templates/edit_route.html:32 msgid "Route" msgstr "Trajet" -#: main/models.py:80 +#: main/models.py:79 msgid "Both" msgstr "Mixte" -#: main/models.py:81 +#: main/models.py:80 msgid "Item type" msgstr "Type d'élément" -#: main/models.py:86 main/models.py:112 main/models.py:180 +#: main/models.py:85 main/models.py:111 main/models.py:179 msgid "Subcategory" msgstr "Sous-catégorie" -#: main/models.py:113 +#: main/models.py:112 msgid "Localisation" msgstr "Localisation" -#: main/models.py:116 main/models.py:184 +#: main/models.py:115 main/models.py:183 msgid "Submited" msgstr "Soumis" -#: main/models.py:118 main/models.py:186 +#: main/models.py:117 main/models.py:185 msgid "Disabled" msgstr "Désactivé" -#: main/models.py:122 main/models.py:190 +#: main/models.py:121 main/models.py:189 msgid "Status" msgstr "État" -#: main/models.py:130 main/models.py:271 +#: main/models.py:129 main/models.py:289 msgid "Point of interest" msgstr "Point d'intérêt" -#: main/models.py:250 +#: main/models.py:249 +msgid "Upper left corner" +msgstr "Coin en haut à gauche" + +#: main/models.py:251 +msgid "Lower right corner" +msgstr "Coin en bas à droite" + +#: main/models.py:260 +msgid "Area" +msgstr "Zone" + +#: main/models.py:268 msgid "Text" msgstr "Texte" -#: main/models.py:251 +#: main/models.py:269 msgid "Long text" msgstr "Texte long" -#: main/models.py:252 +#: main/models.py:270 msgid "Password" msgstr "Mot de passe" -#: main/models.py:256 +#: main/models.py:274 msgid "Type" msgstr "Type" -#: main/models.py:261 main/models.py:273 +#: main/models.py:279 main/models.py:291 msgid "Property model" msgstr "Modèle de propriété" -#: main/models.py:274 +#: main/models.py:292 msgid "Value" msgstr "Valeur" -#: main/models.py:278 +#: main/models.py:296 msgid "Property" msgstr "Propriété" @@ -140,57 +152,62 @@ msgstr "Latitude" msgid "Longitude" msgstr "Longitude" -#: main/widgets.py:139 +#: main/widgets.py:117 +msgid "Invalid point" +msgstr "Point invalide" + +#: main/widgets.py:143 msgid "Creation mode" msgstr "Mode création" -#: main/widgets.py:140 +#: main/widgets.py:144 msgid "" "To start drawing the route click on the toggle button : \"Start drawing\"." -msgstr "Pour commencer le dession cliquez sur le bouton : « Commencer le tracé » " +msgstr "" +"Pour commencer le dession cliquez sur le bouton : « Commencer le tracé » " -#: main/widgets.py:141 +#: main/widgets.py:145 msgid "Then click on the map to begin the drawing." msgstr "Puis cliquez sur la carte pour commencer le dessin." -#: main/widgets.py:142 +#: main/widgets.py:146 msgid "You can add points by clicking again." msgstr "Vous pouvez ajouter des points en cliquant de nouveau." -#: main/widgets.py:143 +#: main/widgets.py:147 msgid "" "To finish the drawing double click. When the drawing is finished you can " "edit it." msgstr "" -"Pour finir le tracé double-cliquez. Quand le tracé est fini vous " -"pouvez toujours l'éditer." +"Pour finir le tracé double-cliquez. Quand le tracé est fini vous pouvez " +"toujours l'éditer." -#: main/widgets.py:145 +#: main/widgets.py:149 msgid "" "While creating to undo a drawing click again on the toggle button \"Stop " "drawing\"." msgstr "" -"En mode création vous pouvez annuler un tracé en appuyant sur le bouton " -"« Arrêter le tracé »" +"En mode création vous pouvez annuler un tracé en appuyant sur le bouton « " +"Arrêter le tracé »" -#: main/widgets.py:150 +#: main/widgets.py:154 msgid "Modification mode" msgstr "Mode modification" -#: main/widgets.py:151 +#: main/widgets.py:155 msgid "To move a point click on it and drag it to the desired position." msgstr "" -"Pour bouger un point, cliquez dessus, maintenez le click pour le " -"déposer à la position désirée" +"Pour bouger un point, cliquez dessus, maintenez le click pour le déposer à " +"la position désirée" -#: main/widgets.py:152 +#: main/widgets.py:156 msgid "" "To delete a point move the mouse cursor over it and press the \"d\" key." msgstr "" "Pour supprimer un point, mettez le curseur de la souris sur celui-ci et " "appuyez sur le touche « d »" -#: main/widgets.py:153 +#: main/widgets.py:157 msgid "" "To add a point click in the middle of a segment and drag the new point to " "the desired position" @@ -199,11 +216,11 @@ msgstr "" "maintenez le bouton appuyé et déplacez le nouveau point à la position " "désirée." -#: main/widgets.py:162 +#: main/widgets.py:166 msgid "Start drawing" msgstr "Commencer le tracé" -#: main/widgets.py:162 +#: main/widgets.py:166 msgid "Stop drawing" msgstr "Arrêter le tracé" @@ -242,8 +259,7 @@ msgstr "Zoomer sur" #: templates/main_map.html:22 msgid "Display markers and routes waiting for validation" msgstr "" -"Afficher les points remarquables et les trajets en attente de " -"validation" +"Afficher les points remarquables et les trajets en attente de validation" #: templates/main_map.html:32 msgid "Permalink" @@ -283,4 +299,3 @@ msgstr "" #: templates/welcome.html:15 msgid "Close" msgstr "Fermer" - diff --git a/main/admin.py b/main/admin.py index 21ba3cb..dc5ff06 100644 --- a/main/admin.py +++ b/main/admin.py @@ -22,8 +22,8 @@ Settings for administration pages """ from chimere.main.models import Category, Icon, SubCategory, Marker, \ - PropertyModel, Property, News, Route -from chimere.main.forms import MarkerAdminForm, RouteAdminForm + PropertyModel, Property, News, Route, Area +from chimere.main.forms import MarkerAdminForm, RouteAdminForm, AreaAdminForm from django.contrib import admin class MarkerAdmin(admin.ModelAdmin): @@ -35,7 +35,6 @@ class MarkerAdmin(admin.ModelAdmin): list_filter = ('status', 'subcategory') form = MarkerAdminForm - class RouteAdmin(admin.ModelAdmin): """ Specialized the Route field. @@ -45,6 +44,13 @@ class RouteAdmin(admin.ModelAdmin): list_filter = ('status', 'subcategory') form = RouteAdminForm +class AreaAdmin(admin.ModelAdmin): + """ + Specialized the area field. + """ + form = AreaAdminForm + exclude = ['upper_left_corner', 'lower_right_corner'] + class SubCategoryAdmin(admin.ModelAdmin): """ Specialized the subcategory admin @@ -59,5 +65,6 @@ admin.site.register(Category) admin.site.register(SubCategory, SubCategoryAdmin) admin.site.register(Marker, MarkerAdmin) admin.site.register(Route, RouteAdmin) +admin.site.register(Area, AreaAdmin) admin.site.register(PropertyModel) admin.site.register(Property) diff --git a/main/forms.py b/main/forms.py index 2343869..6c03c7d 100644 --- a/main/forms.py +++ b/main/forms.py @@ -22,8 +22,10 @@ Forms """ from django import forms from django.contrib.gis.db import models +from django.utils.translation import ugettext as _ -from chimere.main.models import Marker, Route, PropertyModel, Property +from chimere.main.models import Marker, Route, PropertyModel, Property, Area +from chimere.main.widgets import AreaField, PointField class MarkerAdminForm(forms.ModelForm): """ @@ -160,3 +162,36 @@ class RouteForm(RouteAdminForm): class Meta: model = Route exclude = ('status',) + +class AreaAdminForm(forms.ModelForm): + """ + Admin page to create an area + """ + area = AreaField(label=_("Area"), fields=(PointField(), PointField())) + class Meta: + model = Area + + def __init__(self, *args, **keys): + """ + Custom initialization method in order to manage area + """ + if 'instance' in keys and keys['instance']: + instance = keys['instance'] + dct = {'area':(instance.upper_left_corner, + instance.lower_right_corner)} + if 'initial' in keys: + keys['initial'].update(dct) + else: + keys['initial'] = dct + super(AreaAdminForm, self).__init__(*args, **keys) + + def save(self, *args, **keys): + """ + Custom save method in order to manage area + """ + new_area = super(AreaAdminForm, self).save(*args, **keys) + area = self.cleaned_data['area'] + new_area.upper_left_corner = 'POINT(%s %s)' % (area[0][0], area[0][1]) + new_area.lower_right_corner = 'POINT(%s %s)' % (area[1][0], + area[1][1]) + return new_area diff --git a/main/models.py b/main/models.py index ee44a84..a607084 100644 --- a/main/models.py +++ b/main/models.py @@ -24,7 +24,6 @@ from django.utils.translation import ugettext_lazy as _ from django.contrib.gis.db import models from django.contrib import admin -from django.db.models import Q from chimere import settings from chimere.main.widgets import PointField, RouteField @@ -241,6 +240,25 @@ class Route(models.Model): "color":"%(color)s"}}""" % {'id':self.id, 'name':self.name, 'color':color, 'geometry':self.route.geojson,} +class Area(models.Model): + """Rectangular area of the map + """ + name = models.CharField(_("Name"), max_length=150) + order = models.IntegerField(_("Order")) + available = models.BooleanField(_("Available")) + upper_left_corner = models.PointField(_("Upper left corner"), + default='POINT(0 0)') + lower_right_corner = models.PointField(_("Lower right corner"), + default='POINT(0 0)') + objects = models.GeoManager() + + def __unicode__(self): + return self.name + + class Meta: + ordering = ('order', 'name') + verbose_name = _("Area") + class PropertyModel(models.Model): '''Model for a property ''' diff --git a/main/widgets.py b/main/widgets.py index 21dd464..53f365a 100644 --- a/main/widgets.py +++ b/main/widgets.py @@ -112,6 +112,11 @@ class PointField(models.PointField): keys.update(defaults) return super(PointField, self).formfield(**keys) + def clean(self, value): + if len(value) != 2 and self.required: + raise ValidationError(_("Invalid point")) + return value + class RouteChooserWidget(forms.TextInput): """ Manage the edition of route on a map @@ -191,3 +196,74 @@ class RouteField(models.LineStringField): defaults = {'widget': RouteChooserWidget} keys.update(defaults) return super(RouteField, self).formfield(**keys) + +class AreaWidget(forms.TextInput): + """ + Manage the edition of an area on the map + """ + class Media: + css = { + "all": URL_OSM_CSS + ["%sforms.css" % settings.MEDIA_URL,] + } + js = URL_OSM_JS + ["%sedit_area.js" % settings.MEDIA_URL, + "%sbase.js" % settings.MEDIA_URL,] + + def render(self, name, value, attrs=None): + """ + Render a map + """ + upper_left_lat, upper_left_lon = 0, 0 + lower_right_lat, lower_right_lon = 0, 0 + if value: + if len(value) == 2: + upper_left = value[0] + lower_right = value[1] + if hasattr(upper_left, 'x') and hasattr(upper_left, 'y'): + upper_left_lon, upper_left_lat = upper_left.x, upper_left.y + if hasattr(lower_right, 'x') and hasattr(lower_right, 'y'): + lower_right_lon, lower_right_lat = lower_right.x, \ + lower_right.y + tpl = getMapJS() + tpl += u"""<div id='map_edit'></div> +<input type='hidden' name='upper_left_lat' id='upper_left_lat' value='%f'/> +<input type='hidden' name='upper_left_lon' id='upper_left_lon' value='%f'/> +<input type='hidden' name='lower_right_lat' id='lower_right_lat' value='%f'/> +<input type='hidden' name='lower_right_lon' id='lower_right_lon' value='%f'/> +""" % (upper_left_lat, upper_left_lon, lower_right_lat, lower_right_lon) + tpl += """<script type='text/javascript'><!-- +init();""" + if value: + tpl += """var extent = new OpenLayers.Bounds(%f, %f, %f, %f); +map.zoomToExtent(extent, true);""" % (upper_left_lat, upper_left_lon, lower_right_lat, + lower_right_lon) + tpl += """// --></script> +<hr class='spacer'/> +""" + return mark_safe(tpl) + + def value_from_datadict(self, data, files, name): + """ + Return the appropriate values + """ + values = [] + for keys in (('upper_left_lat', 'upper_left_lon',), + ('lower_right_lat', 'lower_right_lon')): + value = [] + for key in keys: + val = data.get(key, None) + if not val: + return [] + value.append(val) + values.append(value) + return values + +class AreaField(forms.MultiValueField): + ''' + Set the widget for the form field + ''' + widget = AreaWidget + + def compress(self, data_list): + if not data_list: + return None + return data_list
\ No newline at end of file |