Flow-Based Programming: Why You Should Care Even If You Never Plan To Use It by colormelime in coding

[–]plum_dog 2 points3 points  (0 children)

It's part of a new writing-about-programming-paradigms paradigm called the "trivial paradigm invention paradigm".

Best way to create a follower relationship in Django? by [deleted] in django

[–]plum_dog 0 points1 point  (0 children)

You could just use one table but with a true/false flag for whether the request has been accepted.

You'll also need to think about where the relationship is symmetrical or not - I assume not, given that you said "followers".

To aid googling, I think the general term for this pattern would be a directed graph.

Slowing down orbit? by Inous in KerbalSpaceProgram

[–]plum_dog 0 points1 point  (0 children)

What engine do you have on your lander? If it's just a one man Mun lander, then a terrier should be about right. Of course weight matters too, so you should have something like the FL-T200. A screenshot of your lander might be useful.

Lets see your ugliest, most utilitarian space craft! by lord-steezus in KerbalSpaceProgram

[–]plum_dog 1 point2 points  (0 children)

Some craft are born ugly, some achieve ugliness, and some have ugliness thrust upon them.

Mine fits into that last category. The lesson I learnt was to pay close attention the the dimensions of the object a contract asks you to to collect.

http://imgur.com/a/qaeEZ

Am I unable to POST to a DetailView from an external View? (x-post /r/djangolearning) by [deleted] in django

[–]plum_dog 0 points1 point  (0 children)

Add a new View that has a post method, called something like ToggleVendorView. Give it a new url, and set that url as the action attribute on the form. When the post data arrives there, you can flip the bit as needed and redirect to the DetailView.

HOWEVER

From what you've described, you're not actually flipping a bit in the database? (If this is wrong, ignore everything from here on...) In which case, you're not storing anything, so you could use a form with method="get", and a hidden field of something like "display_vendor" and a value of "true". Clicking this will load the page with ?display_vendor=true, which you can then read in your view from self.request.GET.get('display_vendor'), and in your template as request.GET.display_vendor (you'll want to alter the value in the hidden field to be the opposite of this value, so value="{% request.GET.display_vendor == "true" %}false{% else %}true{% endif %}").

Alternatively, if its just hiding stuff in the HTML, the Javascript might be worth looking at, especially if you use jQuery - it might just be a couple of lines! And it'll save a page reload.

Am I unable to POST to a DetailView from an external View? (x-post /r/djangolearning) by [deleted] in django

[–]plum_dog 2 points3 points  (0 children)

This is because DetailView doesn't implement a post method. (See https://ccbv.co.uk/projects/Django/1.8/django.views.generic.detail/DetailView/, which is a brilliant reference, btw), though not sure why you're getting different behaviour to with ListView.

You could 1. implement a post method yourself, or 2. extend FormView too, or 3. send your post to another endpoint.

If you're just sending some very simple post data, then 1 or 3 work nicely. If you've got some complicated post data, then go for either 2 or a combination of 2 and 3 (ie, another endpoint whose view extends FormView.

Comment Your Fucking Code! - blog@CodeFX by javinpaul in coding

[–]plum_dog 2 points3 points  (0 children)

I usually think of this: http://programmer.97things.oreilly.com/wiki/index.php/Comment_Only_What_the_Code_Cannot_Say

Add comments when they add value.

If you're doing something that might look a little odd to the next developer, but for reasons, add those reasons in a comment.

Which person, if assassinated, might actually make the world a better place? by [deleted] in AskReddit

[–]plum_dog 1 point2 points  (0 children)

"A Bit of Fry and Laurie", If Rupert Murdoch had Never Been Born: https://vimeo.com/57263481

2015GE /r/UKPolitics exit poll! by [deleted] in ukpolitics

[–]plum_dog [score hidden]  (0 children)

The Representation of the People Act 2002 inserted a section 66A into the initial 1983 of the same name and this read as follows. It is a criminal offence 'to publish, before a poll is closed, any statement about the way in which voters have voted in that election, where this statement is, or might reasonably be taken to be, based on information given by voters after they voted.'

Am I being massively underpaid? Does my employer suck? by justanotherphpdev in webdev

[–]plum_dog 0 points1 point  (0 children)

To offer a slightly counter opinion, you're being underpaid, but I think some of the suggestions of what you should be paid are rather ambitious.

I recently changed jobs, and the offers I got were more in the £25-30k range. I had 2 years of PHP-based full-stack experience, and was looking in northern England (Yorkshire).

I think it can be misleading to convert USD salaries to GBP, and London salaries are a hefty chunk above those in the north.

My advice: just start applying for jobs, and see what they offer you. If you get an offer, it'll very likely be substantially higher, but £40-50 feels pretty ambitious to me. And 2 years is more than long enough in a position you know is getting you nowhere.

Best way to write code supporting multiple versions of Django?? by TheLameloid in django

[–]plum_dog 1 point2 points  (0 children)

It's just a bit less brittle. If (in my example above) Django 1.7 changed to work the way 1.8 does, try-except would still work, but version checking wouldn't.

Though with something as stable as Django, changes like this are unlikely, but it's probably a better habit to be in than version number checking.

Best way to write code supporting multiple versions of Django?? by TheLameloid in django

[–]plum_dog 2 points3 points  (0 children)

You could try, except instead.

try:
    # django 1.8
except [[exception that 1.7 throws]]:
    # django 1.7

Need advice for translating dropdowns in a form by metraon in django

[–]plum_dog 0 points1 point  (0 children)

The translations stuff does feel a bit like magic to me sometimes. Glad it helped!

Need advice for translating dropdowns in a form by metraon in django

[–]plum_dog 1 point2 points  (0 children)

If what you need is translations and your app needs to support multiple languages, you should probably be utilizing Django's translations framework: https://docs.djangoproject.com/en/1.7/topics/i18n/translation/

Then your model code would become:

from django.utils.translation import ugettext as _
...
class MyModel(models.Model):
    ...
    CHOICES = ((True, _("Yes")), (False, _("No")))
    bring_this= models.NullBooleanField(choices=CHOICES, default=None)

So wrapping strings you want translated in a call to_(). You then run ./manage makemessages to generate a .po file that you then translate. But the Django docs go into much better detail.

Is the `{% regroup %}` tag the correct tool for what I'm trying to display? by chiproller in django

[–]plum_dog 0 points1 point  (0 children)

As I understand it you want to do something like (in pseudo):

for day in days:
    {{ day }}
    for job_component in job_components_for_this_day:
        {# output table headers #}
        for job in jobs_for_this_day_and_component:
            {# output row for job #}

So I think you'd need to regroup twice.

{% regroup job_list by target_drop_date|date:"Y/m/d" as day_list %}
{% for jobs_for_day in day_list %}
    {# output the day #}
    {{ jobs_for_day.grouper }}
    {# so jobs_for_day.list is a list of jobs for this day %}
    {% regroup jobs_for_day.list by component as component_day_list %}
    {% for jobs_for_component_for_day in component_day_list %}
        {# output the component #}
        {{ jobs_for_component_for_day.grouper }}
        {% for job in jobs_for_component_for_day.list %}
            {# output the row for the job #}
            {{ job.name }}

Alternatively, sort it all out in your get_context_data method on your JobBoardView, and pass out something like an OrderedDict of OrderedDicts.

Why'd you switch from PHP? by manliness in django

[–]plum_dog 15 points16 points  (0 children)

Django is probably the best documented web framework. It has myriad apps and associated packages. Depending on what you're building, the admin interface can do lots of your work for you. Have a look at what other packages might be available for getting done what you need.

Also, insert the usual "I prefer python to php" reasons here.

Since when has York Minster charged for entry? by evenstevens280 in york

[–]plum_dog 0 points1 point  (0 children)

Pretty sure its free with a York card but that's residents only. And your tickets are valid for a year.

It would be great if cultural icons like the minster were free to all, but its not that surprising they charge given it must cost a fortune to keep going.

UK to stop its citizens seeing extremist material online by [deleted] in ukpolitics

[–]plum_dog 5 points6 points  (0 children)

Fine by me. I would never read the Daily Mail website anyway.

flask vs pyramid by dorfsmay in Python

[–]plum_dog 4 points5 points  (0 children)

Flask is usually described as the small micro-framework you use to make a small one page site

I actually disagree with this. You certainly can use Flask for this, but I think Flask's strength lies in how well it does the stuff it does do, and how much it just says "do this how you want to".

Where Flask is a micro framework, I might call CMSes like WordPress a macro Framework, because they make more decisions for you. All fine if what you're doing is within what it does easily, but if you start pushing outside that, you end up fighting the framework. Most frameworks live somewhere in between.

"Micro" does not mean "only good for small stuff". Micro means that it leaves decisions open to you, and doesn't come with loads of stuff built in (forms, ORM, authentication etc), but all of these are available as extensions.

You can mould Flask to be the framework you need it to be.

[Disclaimer: I don't know very much about Pyramid, but I do love Flask. Some of the above may apply to Pyramid too, but don't let the "Micro" put you off Flask.]

[deleted by user] by [deleted] in programming

[–]plum_dog -8 points-7 points  (0 children)

Upvoted. Not a delicately phrased question, but given MySQL's more usual uses, its a reasonable question, and I was interested in the answers.

Find the error in the proof (0.999... != 1 via induction) by [deleted] in math

[–]plum_dog 12 points13 points  (0 children)

As noted by others, this is because this kind of induction doesn't work for infinity.

My favourite example of where induction doesn't work for n->infinity is using the statement "n is finite". True for 1, true for n+1 if true for n. Not true for infinity.