Daily Archives

Articles indexed Sunday June 6 2010

Page 13/76 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • How Can I Populate Default Form Data with a ManyToMany Field?

    - by b14ck
    Ok, I've been crawling google and Django documentation for over 2 hours now (as well as the IRC channel on freenode), and haven't been able to figure this one out. Basically, I have a model called Room, which is displayed below: class Room(models.Model): """ A `Partyline` room. Rooms on the `Partyline`s are like mini-chatrooms. Each room has a variable amount of `Caller`s, and usually a moderator of some sort. Each `Partyline` has many rooms, and it is common for `Caller`s to join multiple rooms over the duration of their call. """ LIVE = 0 PRIVATE = 1 ONE_ON_ONE = 2 UNCENSORED = 3 BULLETIN_BOARD = 4 CHILL = 5 PHONE_BOOTH = 6 TYPE_CHOICES = ( ('LR', 'Live Room'), ('PR', 'Private Room'), ('UR', 'Uncensored Room'), ) type = models.CharField('Room Type', max_length=2, choices=TYPE_CHOICES) number = models.IntegerField('Room Number') partyline = models.ForeignKey(Partyline) owner = models.ForeignKey(User, blank=True, null=True) bans = models.ManyToManyField(Caller, blank=True, null=True) def __unicode__(self): return "%s - %s %d" % (self.partyline.name, self.type, self.number) I've also got a forms.py which has the following ModelForm to represent my Room model: from django.forms import ModelForm from partyline_portal.rooms.models import Room class RoomForm(ModelForm): class Meta: model = Room I'm creating a view which allows administrators to edit a given Room object. Here's my view (so far): def edit_room(request, id=None): """ Edit various attributes of a specific `Room`. Room owners do not have access to this page. They cannot edit the attributes of the `Room`(s) that they control. """ room = get_object_or_404(Room, id=id) if not room.is_owner(request.user): return HttpResponseForbidden('Forbidden.') if is_user_type(request.user, ['admin']): form_type = RoomForm elif is_user_type(request.user, ['lm']): form_type = LineManagerEditRoomForm elif is_user_type(request.user, ['lo']): form_type = LineOwnerEditRoomForm if request.method == 'POST': form = form_type(request.POST, instance=room) if form.is_valid(): if 'owner' in form.cleaned_data: room.owner = form.cleaned_data['owner'] room.save() else: defaults = {'type': room.type, 'number': room.number, 'partyline': room.partyline.id} if room.owner: defaults['owner'] = room.owner.id if room.bans: defaults['bans'] = room.bans.all() ### this does not work properly! form = form_type(defaults, instance=room) variables = RequestContext(request, {'form': form, 'room': room}) return render_to_response('portal/rooms/edit.html', variables) Now, this view works fine when I view the page. It shows all of the form attributes, and all of the default values are filled in (when users do a GET)... EXCEPT for the default values for the ManyToMany field 'bans'. Basically, if an admins clicks on a Room object to edit, the page they go to will show all of the Rooms default values except for the 'bans'. No matter what I do, I can't find a way to get Django to display the currently 'banned users' for the Room object. Here is the line of code that needs to be changed (from the view): defaults = {'type': room.type, 'number': room.number, 'partyline': room.partyline.id} if room.owner: defaults['owner'] = room.owner.id if room.bans: defaults['bans'] = room.bans.all() ### this does not work properly! There must be some other syntax I have to use to specify the default value for the 'bans' field. I've really been pulling my hair out on this one, and would definitely appreciate some help. Thanks!

    Read the article

  • How does Hive compare to HBase?

    - by mrhahn
    I'm interested in finding out how the recently-released (http://mirror.facebook.com/facebook/hive/hadoop-0.17/) Hive compares to HBase in terms of performance. The SQL-like interface used by Hive is very much preferable to the HBase API we have implemented.

    Read the article

  • Get a random name and number (same contact) from an iPhone users address book

    - by Sam Jarman
    Hi there, I have had only very little experience using the address book in the iPhone SDK. Does anyone have a code snippet or knows the code to get a persons name and number Eg 'Fred Smith - 027 292 2112". I haven't had much luck with the stuff I've tried. I want to achieve this programmatically, and not let the user decide (random pick of the person). I also don't want to display the contact picker either any tutorial links, or anything would be appreciated. Thanks in advance Sam

    Read the article

  • GTK+ buffer in g_input_stream_read...

    - by sterh
    Hello, I load data with function: gssize g_input_stream_read (GInputStream *stream, void *buffer, gsize count, GCancellable *cancellable, GError **error); What is ma value of buffer parameter. How can I know what should be equal to buffer? I make: #define LOAD_BUFFER_SIZE 65536 But when i try to load image, only visible part of the image. Thank you.

    Read the article

  • When to use the Flyweight Pattern

    - by elmt
    So I've just gotten on the boost train and was checking out the flyweight pattern and was interested in implementing it in my project. Obviously, it doesn't make sense to use it on any class that has only has one instance of it. However, say I have 5 instances of an class. Should I be using the flyweight pattern or should it be only used for a class that has at least N instances. I realize that many factors will influence this answer (how many fields there are, the size of the fields, etc.).

    Read the article

  • Freezing Eclipse

    - by Radek Šimko
    I use Eclipse for programming in PHP and Java(Android) and sometimes Python, unfortunately Eclipse is nowadays much more often freezing. Often when I write this bracket "[" for defining an array in PHP, Eclipse just freeze and I have to close it manualy and start again. I've noted also, that Eclipse is consuming really much of my RAM... 200-300MiB of my available memory is nothing special. :-( Is there any way to check, what is consuming the memory in Eclipse and why it's freezing? I'm running on Windows Vista, 3GB RAM.

    Read the article

  • How to tie a Hudson job to a user who has access to run MSIExec

    - by Andrew
    Hi All, I have a batch file that calls "MSIExec /X {MyGUID} /qn". This runs successfully when run with my admin user. When I run it as a Window Batch command from a Hudson job it fails with "T?h?e? ?i?n?s?t?a?l?l?a?t?i?o?n? ?s?o?u?r?c?e? ?f?o?r? ?t?h?i?s? ?p?r?o?d?u?c?t? ?i?s? ?n?o?t? ?a?v?a?i?l?a?b?l?e?.? ? ?V?e?r?i?f?y? ?t?h?a?t? ?t?h?e? ?s?o?u?r?c?e? ?e?x?i?s?t?s? ?a?n?d? ?t?h?a?t? ?y?o?u? ?c?a?n? ?a?c?c?e?s?s? ?i?t?.? " I am inclined to think that the issue is that the job is started by the "anonymous" user rather than my admin user. How in hudson do I "tie" the job to be run under the admin user? Thanks in advance. Regards, Andrew

    Read the article

  • Code Golf: Diamond Pattern

    - by LiraNuna
    The challenge The shortest code by character count to output a a pattern of diamonds according to the input. The input is composed of 3 positive numbers representing the size of the diamond and the size of the grid. A diamond is made from the ASCII characters / and \ with spaces. A diamond of size 1 is: /\ \/ The size of the grid consists from width and height of number of diamonds. Test cases Input: 1 6 2 Output: /\/\/\/\/\/\ \/\/\/\/\/\/ /\/\/\/\/\/\ \/\/\/\/\/\/ Input: 2 2 2 Output: /\ /\ / \/ \ \ /\ / \/ \/ /\ /\ / \/ \ \ /\ / \/ \/ Input 4 1 3 Output: /\ /\ /\ / \ / \ / \ / \ / \ / \ / \/ \/ \ \ /\ /\ / \ / \ / \ / \ / \ / \ / \/ \/ \/ Code count includes input/output (i.e full program).

    Read the article

  • Is there any way to make gcc print offending lines when it emits an error?

    - by Alex
    I have a large codebase that I've been tasked with porting to 64 bits. The code compiles, but it prints a very large amount of incompatible pointer warnings (as is to be expected.) Is there any way I can have gcc print the line on which the error occurs? At this point I'm just using gcc's error messages to try to track down assumptions that need to be modified, and having to look up every one is not fun.

    Read the article

  • What software is used by buy-side investment companies?

    - by user44995
    What software is used by buy-side investment companies? For educational purposes, could anyone describe IT infrastructure of a typical buy-side investment company: a hedge fund, a mutual fund or a wealth management company. No particular details are needed, just what type of software is used how different software modules interact with each other. Am I asking too much?

    Read the article

  • Sum variable range of cells using "today's" date as starting point.

    - by Jason
    How do you sum a variable range of cells based upon today's date in MS Excel 2003. Spreadsheet format: Variable range = # of days to sum Date range = listed in row 1, 1 day per cell (example A1=1/1/10, B1=1/2/10, C1=1/3/10....) Numbers to be summed - listed in row 2, X number per cell (example A2=8, B2=6, C2=1.....) example problem: IF variable range = 2 & Current Date = 1/2/10 then...Sum(b2:c2)=7 I am able to sum the entire row based upon current date using the following formula but am not able to add the variable range to the sum function. =SUMIF(A1:C1,"="&TODAY(),A2:C2)

    Read the article

  • Is it bad to use a model directly from a view in codeigniter?

    - by jason
    I know normally the data is passed thru to the view with the controller. however, currently in my view I load my model ($this-load-model('Db_model');) so i can use it in a loop to retrieve a users profile picture path from a array of IDs that is passed from controller. Will loading the db model in the view to accomplish this make my site more vulnerable or bad form? To me it seems to be outside of MVC concept but its working atm. thanks

    Read the article

  • SharePoint State Machine Workflow walkthrough

    - by d-frag
    I haven't seen an actual SharePoint state machine workflow example on here, but figured this post, How to create a SharePoint State Machine Workflow, is as thorough as it gets. Its a 6-part series. It has a step-by-step approach so even a 9 year old could just follow along and do it. It shows exactly how to use InfoPath to create the initiation form and task form, how to create the state machine workflow (with both C# and VB code), and also how to add workflow history logging and task notification emails. It does not go into modification forms, but does everything else, pretty much. Hope someone finds this useful.

    Read the article

  • Why is my GUI unresponsive while a SwingWorker thread runs?

    - by Starchy
    Hello, I have a SwingWorker thread with an IOBound task which is totally locking up the interface while it runs. Swapping out the normal workload for a counter loop has the same result. The SwingWorker looks basically like this: public class BackupWorker extends SwingWorker<String, String> { private static String uname = null; private static String pass = null; private static String filename = null; static String status = null; BackupWorker (String uname, String pass, String filename) { this.uname = uname; this.pass = pass; this.filename = filename; } @Override protected String doInBackground() throws Exception { BackupObject bak = newBackupObject(uname,pass,filename); return "Done!"; } } The code that kicks it off lives in a class that extends JFrame: public void actionPerformed(ActionEvent event) { String cmd = event.getActionCommand(); if (BACKUP.equals(cmd)) { SwingUtilities.invokeLater(new Runnable() { public void run() { final StatusFrame statusFrame = new StatusFrame(); statusFrame.setVisible(true); SwingUtilities.invokeLater(new Runnable() { public void run () { statusFrame.beginBackup(uname,pass,filename); } }); } }); } } Here's the interesting part of StatusFrame: public void beginBackup(final String uname, final String pass, final String filename) { worker = new BackupWorker(uname, pass, filename); worker.execute(); try { System.out.println(worker.get()); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } } So far as I can see, everything "long-running" is handled by the worker, and everything that touches the GUI on the EDT. Have I tangled things up somewhere, or am I expecting too much of SwingWorker?

    Read the article

  • Why won't my program terminate?

    - by Qwertie
    I have a .NET Compact Framework app that can runs on three windows machines (Desktop windows and two WinCE machines) and on the WinCE devices, the process never terminates on exit, even if I call Application.Exit(). Besides .NET, it uses one COM component (which does everything on the UI thread). If I break into the debugger after exitting, Visual Studio shows only one thread and a completely blank call stack. What could possibly cause this? Update: My process is terminating on the desktop but not the WinCE machines. I tried to force the process to terminate with the following code, but it doesn't work: [DllImport("coredll.dll")] static extern int TerminateProcess(IntPtr hProcess, uint uExitCode); static public void ExitProcess() { if (Platform.IsWindowsCE) TerminateProcess(new IntPtr(-1), 0); Application.Exit(); } There are also supposed to be ExitProcess() and GetCurrentProcess() APIs like the following, but if I try to call them, I get EntryPointNotFoundException. Therefore I am using TerminateProcess(-1, 0) because the documentation for the desktop version of GetCurrentProcess claims that it simply returns -1. [DllImport("coredll.dll")] static extern int ExitProcess(IntPtr hProcess); [DllImport("coredll.dll")] static extern IntPtr GetCurrentProcess(); Even if I do this: static public void ExitProcess() { if (Platform.IsWindowsCE) TerminateProcess(new IntPtr(-1), 0); Application.Exit(); throw new Exception("Trying to force quit."); } A fatal error dialog appears with a helpful "Quit" button, but pushing the button still does not cause the process to terminate on either machine!

    Read the article

  • Beat Detection on iPhone with wav files and openal

    - by Dmacpro
    Using this website i have tried to make a beat detection engine. http://www.gamedev.net/reference/articles/article1952.asp { ALfloat energy = 0; ALfloat aEnergy = 0; ALint beats = 0; bool init = false; ALfloat Ei[42]; ALfloat V = 0; ALfloat C = 0; ALshort *hold; hold = new ALshort[[myDat length]/2]; [myDat getBytes:hold length:[myDat length]]; ALuint uiNumSamples; uiNumSamples = [myDat length]/4; if(alDatal == NULL) alDatal = (ALshort *) malloc(uiNumSamples*2); if(alDatar == NULL) alDatar = (ALshort *) malloc(uiNumSamples*2); for (int i = 0; i < uiNumSamples; i++) { alDatal[i] = hold[i*2]; alDatar[i] = hold[i*2+1]; } energy = 0; for(int start = 0; start<(22050*10); start+=512){ //detect for 10 seconds of data for(int i = start; i<(start+512); i++){ energy+= fabs(alDatal[i]) + fabs(alDatar[i]); } aEnergy = 0; for(int i = 41; i>=0; i--){ if(i ==0){ Ei[0] = energy; } else { Ei[i] = Ei[i-1]; } if(start >= 21504){ aEnergy+=Ei[i]; } } aEnergy = aEnergy/43.f; if (start >= 21504) { for(int i = 0; i<42; i++){ V += (Ei[i]-aEnergy); } V = V/43.f; C = (-0.0025714*V)+1.5142857; init = true; if(energy >(C*aEnergy)) beats++; } } } alDatal and alDatar are (short*) type; myDat is NSdata that holds the actual audio data of a wav file formatted to 22050 khz and 16 bit stereo. This doesn't seem to work correctly. If anyone could help me out that would be amazing. I've been stuck on this for 3 days.

    Read the article

  • How to launch an external application on BN_CLICKED?

    - by Alienexist
    I'm fairly new to Windows programming. I'm doing a simple launcher app for WinCE using VC++ (not MFC). So far I've created the basic interface and buttons and stuff. I just wanted to know the best way to launch an external application when the user clicks the button (on BN_CLICKED). I found some methods such as ShellExecute, CreateProcess and others. But I couldn't get it to work (yet?). Any suitable reference or simple example on this?

    Read the article

  • What is the best way to keep a folder synchronized with my USB drive?

    - by Ivo Flipse
    I know there is a similar topic on syncing between computers, but I'm looking for an application to run on one computer that will sync a "document/file" folder with a folder on my secondary/external USB drive. What would be the best solution? I know I could use Dropbox & Live Mesh, but they use up bandwith which isn't very good when I drop in a lot of large files. I'm running Windows 7, but I assume any solution for Windows Vista would work just fine.

    Read the article

  • Use Windows Briefcase from the command line

    - by Daniel
    I have a thumb drive on which I take many of my files with me. I would like to synchronize it with my computer automatically when I connect it. I currently have a script run every time I connect it so that I can do the many things that need to be done when it connects (check for updates to the portable applications, etc.). I want my synchronization utility to: Detect conflicts work correctly when I move files or change the folder structure tell the difference between a file that was deleted on one side and a file that was added on the other work from the command line or at least have a command that will open up a window provide a confirmation screen before doing anything The Windows Briefcase does all of these except the command line. Is there any program that does all of these, or is there a way to synchronize the briefcase from the command line?

    Read the article

  • jquery .add() is weird

    - by phil
    Hi folks. Why all elements turn red? I only intend to turn <p> red. <ul> <li>list item 1</li> <li>list item 2</li> <li>list item 3</li> </ul> <p>a paragraph</p> <script> $('li').add('p').css('background-color', 'red'); </script>

    Read the article

  • Activesync wont connect to my Windows CE 6 device

    - by Presidenten
    Hi! When I connect my Windows CE 6 device to my development machine I get Microsoft USB Sync to register in Windows Device manager. But I cant connect with ActiveSync for some reason. Any ideas on how to fix this? It worked with Windows CE 5, but when we upgraded ActiveSync-functionality disappeared.

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >