Azd325@Github

I wanted to customize the default theme of Pelican but didn’t want to copy single
template files or to edit the files in the python path.

In the docs you can find how you install, remove and list themes [1]

Commandline
1
pelican-themes -v -l

You’ll get some output like this

Output
1
2
/home/tim/.virtualenvs/pelican-blog/lib/python2.7/site-packages/pelican/themes/simple
/home/tim/.virtualenvs/pelican-blog/lib/python2.7/site-packages/pelican/themes/notmyidea

So what I did:

  1. Go to your root blog folder
  2. Then copy the complete "<span class="n">notmyidea</span>" folder to your current pelican root folder
Commandline
1
2
3
4
# Create themes folder
mkdir themes
# Copy the folder
cp -R /home/tim/.virtualenvs/pelican-blog/lib/python2.7/site-packages/pelican/themes/notmyidea themes/
  1. After it you have to define in your pelicanconf.py a theme variable THEME. [2]
    What gets linked to the copied theme folder!
pelicanconf.py
1
THEME = themes/notmyidea
  1. Now you are in the state to customize the default template to your style.

This is a little snippet to remove tags from a string to get the only raw textual content. I’m using the Beautiful Soup Library [1] for this job.

Install Beautifulsoup with pip:

Commandline
1
pip install beautifulsoup4

Example:

Snippet
1
2
3
from bs4 import BeautifulSoup
html = "<html><body><h1>Test</h1><body><html>"
''.join(BeautifulSoup(html).get_text())

I got a following problem that I was not be able to update my phone from my recovery mode. I’m using ClockworkMod.

So I searched around the web and found a very easy way to update my Nexus 4

  1. Connect your Nexus with the USB cabel with your computer
  2. Download the CyanogenMod package you want to install, from http://get.cm/?device=mako
  3. Boot the recovery mode
  4. Navigate to install zip
  5. Navigate then to insall zip from sideload
  6. You need now the Android Platform Tools
  7. Open your terminal now
  8. Type now "adb sideload cyanogenmod.zip" (cyanogenmod.zip is the downloaded package from the second step)
  9. After it reboot you phone

Bonus Tip:

  • If you have problems with the Wifi on your Nexus 4 try the WifiFix from kalo86 on the same way what is describe in points above
1
2
3
4
5
6
7
8
9
{% url admin:index %}
{% url admin:polls_choice_add %}
{% url admin:polls_choice_change choice.id %}
# For Django 1.5. Thanks to Kenneth Love
{% url 'admin:index' %}
{% url 'admin:polls_choice_add' %}
{% url 'admin:polls_choice_change' choice.id %}

With this Code Examples you can manage to get the right url in the templates where you want.

  1. Is the index url of the admin.

  2. Is the add url for the App Polls with the Model Choice.

  3. Is the change url for the App Polls with the Model Choice and with Parameter for that object what you want to change.

The principe is __change object_id

This help me today a lot at work.

For you interest:

Django Docs:Reversing Admin Urls
Kenneth Love

So I had to reinstall my Windows 8 in my dual boot system with Arch
Linux. After the reinstall I had the default boot manager of Windows
back in place of GRUB2.

My way to fix it, was to install on my USB key the current live CD of
archlinux Download here. Burn it to CD or copy it to your USB key with

1
dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx

After the installing of the live CD to my USB key. I was restarting my
PC to boot from it. Afterwards I got the default arch Linux shell.


  1. I was creating a root point for my root disk in /mnt/root/
1
mkdir /mnt/root/
  1. Now I can mount the root partition to this point
1
mount /dev/sdXX /mnt/root
  1. Now I had to change the root. This command also adds the necessary
    folders like (proc, dev,…)
1
arch-chroot /mnt/root
  1. I have a separate boot partition so I had to mount this also to my
    chroot system
1
mount /boot
  1. Regenerate the grub.cfg
1
grub-mkconfig -o /boot/grub/grub.cfg
  1. So, it’s nearly done! I had only to install Grub back in the MBR
1
grub-install /dev/sdXX

Last not but least. Rebooted and it was working

To rename a branch is very easy to need only the next command for it.

(-m means “Move/rename a branch and the corresponding reflog.”)

1
git branch -m old_branch_name new_branch_name

Classes are great but they are also overused. This talk will describe examples of class overuse taken from real world code and refactor the unnecessary classes, exceptions, and modules out of them.

I work currently on a rating feature, to rate some items and I want to do this
in one view to handle the methods POST and GET.

POST should handle the submit request(rate count) of the item

GET should handle the template with the right item to see the current
user/ global rate

Situation:

  • max. stars = five
  • min. stars = one
  • zero stars are not possible to vote

What we need to rate?

  • item id
  • vote result

I start to add the first version of the view and I was adding two URL’s one for GET and one for POST.
And I what to handle the parameter over the named groups in Django.

.. code-block:: django

urlpatterns += patterns('',
    url(r'^ajax/votes/(?P<item_id>\w+)/$', 'vote_for_item'),  # GET
    url(r'^ajax/votes/(?P<item_id>\w+)/(?P<vote>\d+)/$', 'vote_for_item')  # POST
)

What we can to be more explicit?

We can use re of Python and so we can set a range of allowed numbers with [1-5].
So we have only a range of URL’s for every state of the rating situation and so we get a 404 if we want to access for example the vote-URL with the vote count of six.

.. code-block:: python

urlpatterns += patterns('',
    url(r'^ajax/votes/(?P<item_id>\w+)/$', 'vote_for_item'),  # GET
    url(r'^ajax/votes/(?P<item_id>\w+)/(?P<vote>[1-5])/$', 'vote_for_item')  # POST
)

The next thing we have to two exact same URL’s the only difference is that the POST needs an extra parameter.

Can we make this parameter optional?

Yeah, we can do it again with re. We have to wrap the vote part in (?:...) and after it a single ?. More in the Python Docs.

The end solution:

I have one URL for the cases of GET and POST and we create only the URL’s what I need for the rating feature

.. code-block:: python

urlpatterns += patterns('',
    url(r'^ajax/votes/(?P<item_id>\w+)/(:?(?P<vote>[1-5])/)?$', 'vote_for_item'),
)

FYI:

Optional named groups Python re

URL dispatcher at Django Docs

re at Python Docs

comments powered by Disqus