from ais.common import Nmea, mmsi_to_strmmsi
+class UserMessageCategory(models.Model):
+ id = models.CharField(max_length=10, primary_key=True)
+ class Meta:
+ db_table = u'user_message_category'
+
+class UserMessage(models.Model):
+ id = models.AutoField(primary_key=True)
+ user = models.ForeignKey('User')
+ category = models.ForeignKey(UserMessageCategory, db_column='user_message_category_id')
+ txt = models.TextField()
+ class Meta:
+ db_table = u'user_message'
+
class User(models.Model):
id = models.AutoField(primary_key=True)
login = models.CharField(max_length=16, unique=True)
salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5]
hsh = get_hexdigest(algo, salt, raw_password)
self.password_hash = '%s$%s$%s' % (algo, salt, hsh)
+ self.info('Password changed')
def check_password(self, raw_password):
algo, salt, hsh = self.password_hash.split('$')
return False
return self.father.is_admin_by(user_id)
+ def get_messages(self):
+ messages = UserMessage.objects.filter(user__id = self.id)
+ messages_dict = \
+ [ {'category': message.category, \
+ 'txt': message.txt} \
+ for message in messages \
+ ]
+ messages.delete()
+ return messages_dict
+
+ def info(self, message):
+ UserMessage(user_id = self.id, category_id='info', txt=message).save()
+
+
class Vessel(models.Model):
mmsi = models.IntegerField(primary_key=True)
name = models.CharField(max_length=20)
message = u'User %s already has access.' % user.login
except FleetUser.DoesNotExist:
FleetUser(fleet=fleet, user=user).save()
- message = u'Granted access to user %s.' % user.login
+ #TODO log
+ request.user.info(u'Granted access to user %s.' % user.login)
elif action == u'revoke':
try:
fu = FleetUser.objects.get(fleet=fleet, user=user)
fu.delete()
- message = u'Revoked access to user %s.' % user.login
+ #TODO log
+ request.user.info(u'Revoked access to user %s.' % user.login)
except FleetUser.DoesNotExist:
message = u'User %s didn\'t have access.' % user.login
else:
{% block breadcrumbs %}
You are here: <a href='/'>home</a>
{% endblock %}
+
+
<div style="padding:1ex;">
-{% block content %}{% endblock %}
-</div>
+ {% for message in user.get_messages %}
+ <div class=message>
+ {{ message.category.id }}: {{ message.txt }}
+ </div>
+ {% endfor %}
+ {% block content %}{% endblock %}
+ </div>
</div>
<div id=footer>
{% block content %}
<h3>Delete user acccount {{ auser.name }}</h3>
You are about to delete acount {{ auser.name }}. <br>
-This will also delete sub-accounts.<br>
+<b>This will also delete sub-accounts.</b><br>
Are you sure?<br>
-<a href="?confirm=yes">Yes, delete it</a><br>
+<a href="?confirm=yes" class=button>Yes, delete it</a><br>
{% endblock %}
);
+--
+-- Name: news; Type: TABLE; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE TABLE news (
+ id integer NOT NULL,
+ updated timestamp without time zone DEFAULT now() NOT NULL,
+ title text NOT NULL,
+ txt text NOT NULL,
+ created timestamp without time zone DEFAULT now() NOT NULL
+);
+
+
+--
+-- Name: news_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE news_id_seq
+ INCREMENT BY 1
+ NO MAXVALUE
+ NO MINVALUE
+ CACHE 1;
+
+
+--
+-- Name: news_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE news_id_seq OWNED BY news.id;
+
+
--
-- Name: plane; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
id integer NOT NULL,
father_id integer,
creation_datetime timestamp without time zone DEFAULT now() NOT NULL,
- phone character varying(20) DEFAULT ''::character varying NOT NULL
+ phone character varying(20) DEFAULT ''::character varying NOT NULL,
+ access_datetime timestamp without time zone
);
ALTER SEQUENCE user_id_seq OWNED BY "user".id;
+--
+-- Name: user_message; Type: TABLE; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE TABLE user_message (
+ id integer NOT NULL,
+ user_id integer NOT NULL,
+ user_message_category_id character varying(10) NOT NULL,
+ txt text DEFAULT ''::text NOT NULL
+);
+
+
+--
+-- Name: user_message_category; Type: TABLE; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE TABLE user_message_category (
+ id character varying(10) NOT NULL
+);
+
+
+--
+-- Name: user_message_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE user_message_id_seq
+ INCREMENT BY 1
+ NO MAXVALUE
+ NO MINVALUE
+ CACHE 1;
+
+
+--
+-- Name: user_message_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE user_message_id_seq OWNED BY user_message.id;
+
+
--
-- Name: vessel; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE mi_source ALTER COLUMN id SET DEFAULT nextval('mi_source_id_seq'::regclass);
+--
+-- Name: id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE news ALTER COLUMN id SET DEFAULT nextval('news_id_seq'::regclass);
+
+
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE "user" ALTER COLUMN id SET DEFAULT nextval('user_id_seq'::regclass);
+--
+-- Name: id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE user_message ALTER COLUMN id SET DEFAULT nextval('user_message_id_seq'::regclass);
+
+
--
-- Name: fleet_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ADD CONSTRAINT user_login_unique UNIQUE (login);
+--
+-- Name: user_message_category_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
+--
+
+ALTER TABLE ONLY user_message_category
+ ADD CONSTRAINT user_message_category_pkey PRIMARY KEY (id);
+
+
+--
+-- Name: user_message_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
+--
+
+ALTER TABLE ONLY user_message
+ ADD CONSTRAINT user_message_pkey PRIMARY KEY (id);
+
+
--
-- Name: user_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ADD CONSTRAINT vessel_pkey PRIMARY KEY (mmsi);
+--
+-- Name: user_message_user_idx; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX user_message_user_idx ON user_message USING btree (user_id);
+
+
--
-- Name: fleet_user_fleet_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ADD CONSTRAINT user_father_id_fkey FOREIGN KEY (father_id) REFERENCES "user"(id);
+--
+-- Name: user_message_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY user_message
+ ADD CONSTRAINT user_message_user_id_fkey FOREIGN KEY (user_message_category_id) REFERENCES user_message_category(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+
+--
+-- Name: user_message_user_message_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY user_message
+ ADD CONSTRAINT user_message_user_message_category_id_fkey FOREIGN KEY (user_message_category_id) REFERENCES user_message_category(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+
--
-- PostgreSQL database dump complete
--
ul.errorlist li {
list-style-image: url('/errorbullet.png');
}
+
+div.message {
+ background:#ffffd0;
+ border: 1px solid yellow;
+ -moz-border-radius: 3px;
+ -webkit-border-radius: 3px;
+ padding: 0.5ex;
+}