Didn’t write for awhile. Want…

Didn’t write for awhile. Want to test and see how this site/templates work.



My goal for today was to:

  1. Start the new kidsintown project, based on the django tutorial (mysite). Namely to turn all the poll models and views into events.
  2. Find a package that will help me with recurring events


Moving from mysite to kidsintown

  • It took me a lot of time to transition from the poll app to the events. The main issue was around urls and naming of views (that will be a reccuring theme…)
  • This didn’t take long to figure out, but I django yelled at me that I need to add the events app to the INSTALLED_APPS in my setting.py. But I didn’t have to do it with the django tutorial project… I still don’t understand what’s the different between the two projects.

Implementing django-recurrence

  • Implemented the django-reccuring package. I had an issue with getting it to work with my simple Event model, because I kept getting errors when trying to make a migration. Here’s how my model was looking like, according to the documentation:
from recurrence.fields import RecurrenceField

class Course(models.Model):
    title = models.CharField(max_length=200)
    recurrences = RecurrenceField()

I kept getting an error saying that I try to create a non-nullable field (recurrences) with a null value. After looking for code examples in github, I found one that worked:

class Event(models.Model):

    event_name = models.CharField(max_length=200)
    event_time = models.DateField()
    recurrence = RecurrenceField(blank=True, null=True)

    def __str__(self):
        return self.event_name
  • Documentation for packages in general, and that one in particular, isn’t good. There is now step-by-step tutorials, and you should figure out how the fragments of code integrating into your project. I found that looking for code examples in gitgub was helpful.
  • I had hard time implementing the form for creating recurrance in my templates. For example, in the documentation to the package, it is said that you should create a form like that:
from django import forms
from .models import Course

class EventForm(forms.ModelForm):
   class Meta:
      model = Event
      fields = ('event_name', 'recurrences',)

That didn’t work, and returned an error. After more github searches, I found that decleration that worked:

from django import forms
from .models import Event

class EventForm(forms.ModelForm):

    class Meta:
        model = Event
        exclude = []

Again, the documentation just show limited code examples, and I was left to figure some new concepts, such as forms. Fortunatly I found this great tutorial about creating forms a to z.

  • While the above tutorial was great, I still had issues – the redirect from the event creation to an event detail page after creation didn’t work. After many trails and errors, I found that the way I need to call a view accross the project is not only using it name, but also the app name, in the form of :.
  • Now to be honest, there is a section in the django tutorial that speaks into that previous point…


Preparing a pull request:

  1. Go to master and run

git pull origin master (to fetch all the recent changes from remote)

  1. Go to [branch-name] and run

git merge master (to merge the changes I did into your branch)

  1. now run

git push origin [branch-name] (to update remote with your branch after the merge with master)

Don’t be confuse 🙂 You are merging master into your branch to be synced with master, pull request (once approved) does the other way around.


How do I turn off the flymake, or alternativly find way to fix the warnings it shows me?

Here’s what I found about

  • Flymake to check format of the code, and make sure it adhears to python standards
  • Yapf is a package that reformat the code according to the standard.

To get Flymake to work, I needed to enable flymake-mode Then run C-c C-v to get the list of errors. I can go error by error and fix. But I can also do C-c C-r f to run auto refactoring. In this case Elpy is using the refactoring package (Yapf) to reformat the code.

At first I had an error, and although I had Yapf installed, Emacs kept telling me that it’s not. I found the solution in this issue: Elpy error: yapf not installed

I needed to restart the RPC process, by running M-x elpy-rpc-restart

Ok, with that out of the way, I need to get back to the code.

Accepting, merging and deploying a pull request

Checklist for merging a push request and deploying to heroku:
1. Accept the PR request
2. Merge PR request into master
3. Pull the version to my local:
~/path/to/project(master)$ git pull [remote] master

This will override my local with the current version in the remote (either GitHub or bitbucket).

  1. Push master to heroku:
    ~/path/to/project(master)$ git push heroku master


Back to working on the project. I want to add simple db support, so when I get a request from Alexa, I’ll check if the user is new or returned. If new – store the uuid in the db. If returning, give a returned user message.

Later I can also add context to the db, so I can manage contexts and states not only within session, but also accross sessions.

So, connecting to db – that’s something I did in the “My Clipboard” skill. I’ll go and look there how I did it.

Ok, I copied the set of functions from the clipboard app, but I now get an error when trying to call from Alexa – the entries table isn’t exsit… I remember that I had to do some manual creation of tables, but I don’t recall what exactly I needed to do.

Oh, I see what I’ve missed. I needed to create a schema.sql file, that defines the table I would like to create.

Here’s an article that is a good reference: Intro to Flask: Creating and Writing to Databases

And by the way, I’m moving to use Sublime for now… I spend too much time tinkering with Emacs, and not doing productive work… I will keep writing this in Emacs though, because it’s an org file.

Ok, back to Emacs. I guesse I’m more used to it than I thought…

I added the db support. I now want to check if a user is new or return. First time I see a user, I add the user to the db. Then I fetch from the db to check new or return. I had a problem with checking if I get a row from the db. Used this stack-overflow answer. The gist:

  • Excecute the query with count(*)
  • Grab the fetchone() with index 0
  • Test if I get 1 or 0. If 0, then there was no result from the query.
def launched():
    # check if the user is new or return
    db = get_db()    
    c = db.execute('select count(*) from users where user_id = ?',

    data = c.fetchone()[0]
    if data == 0:
        # new user - insert to db and play new user welcome
        db.execute('insert into users (user_id) values (?)',
        return question('Welcome to out brain! I will be your personal editor. To start, say headlines, sites, topics or categories')
        return question('Welcome back! What do topic are you interested in today?')

Many times I need to…

Many times I need to suggest times when I’m available. What I then need to do is go to my calendar, see what slots are available and manually get the dates and times and put it together in a reply. Very often I’m making a mistake, getting the date or the time wrong.

I want to be able to see my calendar, click on a certain time slot, and have it ready in my clipboard, so I can paste it wherever I want.

I would like to be able to do it in Python.

There’s a workflow in the workflows app, called “share availability”, that’s doing something similar. I might be able to use it as reference.