Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
store the day migrations get sent in msg profile
Browse files Browse the repository at this point in the history
  • Loading branch information
miltontony committed Jul 16, 2014
1 parent e1a819e commit 60b5dd7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mamasbm/mamasbm/models.py
Expand Up @@ -75,12 +75,14 @@ class MessageProfile(Base):
name = Column(Text)
profile_id = Column(UUID, ForeignKey('profiles.uuid'))
messages = relationship('Message', backref='message_profile')
send_day = Column(Integer)

def to_dict(self):
return {
'uuid': str(self.uuid),
'profile_id': str(self.profile_id),
'name': self.name,
'send_day': self.send_day,
'messages': [m.to_dict() for m in self.messages]
}

Expand Down
5 changes: 3 additions & 2 deletions mamasbm/mamasbm/web/factory.py
Expand Up @@ -8,11 +8,12 @@
def build_message_profiles(name, temp_file, profile_uuid):
with transaction.manager:
profile = DBSession.query(Profile).get(profile_uuid)
num_days = len(profile.get_send_days())
days = CsvImporter(num_days).import_csv(temp_file)
send_days = profile.get_send_days()
days = CsvImporter(num_days=len(send_days)).import_csv(temp_file)
for k, v in days.items():
day_name = calendar.day_name[k]
msg_profile = MessageProfile(name='%s - %s' % (name, day_name))
msg_profile.send_day = send_days[k]
messages = [
Message(week=wk, text=txt)
for wk, txt in v.items()
Expand Down
2 changes: 2 additions & 0 deletions mamasbm/mamasbm/web/tests.py
Expand Up @@ -227,6 +227,8 @@ def test_message_profile_factory(self):
self.assertEquals(
resp.json[0]['message_profiles'][0]['name'],
'English - Monday')
self.assertEquals(resp.json[0]['message_profiles'][0]['send_day'], 1)
self.assertEquals(resp.json[0]['message_profiles'][1]['send_day'], 4)
self.assertEquals(
len(resp.json[0]['message_profiles'][0]['messages']),
36)
Expand Down
@@ -0,0 +1,27 @@
"""add send_day to message profile
Revision ID: 1c9e829abd8e
Revises: 29fb24fdc151
Create Date: 2014-07-16 14:23:04.006251
"""

# revision identifiers, used by Alembic.
revision = '1c9e829abd8e'
down_revision = '29fb24fdc151'

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column(
'message_profiles', sa.Column('send_day', sa.Integer(), nullable=True))
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('message_profiles', 'send_day')
### end Alembic commands ###

0 comments on commit 60b5dd7

Please sign in to comment.