Search Results

Search found 8 results on 1 pages for 'prairiedogg'.

Page 1/1 | 1 

  • [NSLocale currentLocale] always returns "en_US" not user's current language

    - by Prairiedogg
    I'm in the processes of internationalizing an iPhone app - I need to make programmatic changes to certain views based on what the user's current locale is. I'm going nuts because no matter what the language preference on the iPhone simulator or actual hardware are, locale always evaluates to "en_US": NSString *locale = [[NSLocale currentLocale] localeIdentifier]; NSLog(@"current locale: %@", locale); The crazy thing is that the rest of the application behaves as expected. The correct strings are selected from the Localization.strings file and used in the interface, and the correct .xib files for the selected locale are used. I have also tried the following, to no avail and with the same result: NSString *locale = [[NSLocale autoupdatingCurrentLocale] localeIdentifier]; NSLog(@"current locale: %@", locale); Is there something simple I'm missing? A preference or an import perhaps? Update: As Darren's answer suggests, the preference I'm looking for is not in NSLocale, rather it is here: NSUserDefaults* defs = [NSUserDefaults standardUserDefaults]; NSArray* languages = [defs objectForKey:@"AppleLanguages"]; NSString* preferredLang = [languages objectAtIndex:0]; NSLog(@"preferredLang: %@", preferredLang);

    Read the article

  • Adding a generic image field onto a ModelForm in django

    - by Prairiedogg
    I have two models, Room and Image. Image is a generic model that can tack onto any other model. I want to give users a form to upload an image when they post information about a room. I've written code that works, but I'm afraid I've done it the hard way, and specifically in a way that violates DRY. Was hoping someone who's a little more familiar with django forms could point out where I've gone wrong. Update: I've tried to clarify why I chose this design in comments to the current answers. To summarize: I didn't simply put an ImageField on the Room model because I wanted more than one image associated with the Room model. I chose a generic Image model because I wanted to add images to several different models. The alternatives I considered were were multiple foreign keys on a single Image class, which seemed messy, or multiple Image classes, which I thought would clutter my schema. I didn't make this clear in my first post, so sorry about that. Seeing as none of the answers so far has addressed how to make this a little more DRY I did come up with my own solution which was to add the upload path as a class attribute on the image model and reference that every time it's needed. # Models class Image(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') image = models.ImageField(_('Image'), height_field='', width_field='', upload_to='uploads/images', max_length=200) class Room(models.Model): name = models.CharField(max_length=50) image_set = generic.GenericRelation('Image') # The form class AddRoomForm(forms.ModelForm): image_1 = forms.ImageField() class Meta: model = Room # The view def handle_uploaded_file(f): # DRY violation, I've already specified the upload path in the image model upload_suffix = join('uploads/images', f.name) upload_path = join(settings.MEDIA_ROOT, upload_suffix) destination = open(upload_path, 'wb+') for chunk in f.chunks(): destination.write(chunk) destination.close() return upload_suffix def add_room(request, apartment_id, form_class=AddRoomForm, template='apartments/add_room.html'): apartment = Apartment.objects.get(id=apartment_id) if request.method == 'POST': form = form_class(request.POST, request.FILES) if form.is_valid(): room = form.save() image_1 = form.cleaned_data['image_1'] # Instead of writing a special function to handle the image, # shouldn't I just be able to pass it straight into Image.objects.create # ...but it doesn't seem to work for some reason, wrong syntax perhaps? upload_path = handle_uploaded_file(image_1) image = Image.objects.create(content_object=room, image=upload_path) return HttpResponseRedirect(room.get_absolute_url()) else: form = form_class() context = {'form': form, } return direct_to_template(request, template, extra_context=context)

    Read the article

  • iTunes Connect rejects my binary because I used a pre-release version of the SDK, what should I do?

    - by Prairiedogg
    NOTE - I'm posting this question to answer myself as a service to the community. Stay tuned for the answer. I downloaded a pre-release version of the iPhone SDK and tried to update one of my existing apps using a binary I built with it. Obviously you are not supposed to do this but I had forgotten about the warning when I installed the pre-release SDK. Anyway - I have two questions: Can I simply set the base SDK to an earlier version in the build settings and get around this problem? If not, then what should I do?

    Read the article

  • What's the standard convention for creating a new NSArray from an existing NSArray?

    - by Prairiedogg
    Let's say I have an NSArray of NSDictionaries that is 10 elements long. I want to create a second NSArray with the values for a single key on each dictionary. The best way I can figure to do this is: NSMutableArray *nameArray = [[NSMutableArray alloc] initWithCapacity:[array count]]; for (NSDictionary *p in array) { [nameArray addObject:[p objectForKey:@"name"]]; } self.my_new_array = array; [array release]; [nameArray release]; } But in theory, I should be able to get away with not using a mutable array and using a counter in conjunction with [nameArray addObjectAtIndex:count], because the new list should be exactly as long as the old list. Please note that I am NOT trying to filter for a subset of the original array, but make a new array with exactly the same number of elements, just with values dredged up from the some arbitrary attribute of each element in the array. In python one could solve this problem like this: new_list = [p['name'] for p in old_list] or if you were a masochist, like this: new_list = map(lambda p: p['name'], old_list) Having to be slightly more explicit in objective-c makes me wonder if there is an accepted common way of handling these situations.

    Read the article

  • How do I return the entire set / array using NSPredicate?

    - by Prairiedogg
    I'm building a carArray and want to filter the contents conditionally, using an NSPredicate, like so: NSPredicate *pred; switch (carType) { case FreeCar: pred = [NSPredicate predicateWithFormat:@"premium = NO"]; break; case PremiumCar: pred = [NSPredicate predicateWithFormat:@"premium = YES"]; break; default: pred = [NSPredicate predicateWithFormat:@"SOME PREDICATE THAT RETURNS EVERYTHING"]; break; } self.carArray = [aCarArrayIGotFromSomewhere filteredArrayUsingPredicate:pred]; My question is, what is the correct syntax for the value I've stubbed in as SOME PREDICATE THAT RETURNS EVERYTHING which returns all of the instances in the array / set? PS - I know the answer and will post it immediately, just sharing it for everyone's reference as an earlier search on SO did not yield the result.

    Read the article

  • Firefox handles xxx.submit(), Safari doesn't ... what can be done?

    - by Prairiedogg
    I'm trying to make a pull down menu post a form when the user selects (releases the mouse) on one of the options from the menu. This code works fine in FF but Safari, for some reason, doesn't submit the form. I re-wrote the code using jquery to see if jquery's .submit() implementation handled the browser quirks better. Same result, works in FF doesn't work in safari. The following snippets are from the same page, which has some django template language mixed in. Here's the vanilla js attempt: function formSubmit(lang) { if (lang != '{{ LANGUAGE_CODE }}') { document.getElementById("setlang_form").submit(); } } Here's the jquery attempt: $(document).ready(function() { $('#lang_submit').hide() $('#setlang_form option').mouseup(function () { if ($(this).attr('value') != '{{ LANGUAGE_CODE }}') { $('#setlang_form').submit() } }); }); and here's the form: <form id="setlang_form" method="post" action="{% url django.views.i18n.set_language %}"> <fieldset> <select name="language"> {% for lang in interface_languages %} <option value="{{ lang.code }}" onmouseup="formSubmit('{{ lang.name }}')" {% ifequal lang.code LANGUAGE_CODE %}selected="selected"{% endifequal %}>{{ lang.name }}</option> {% endfor %} </select> </fieldset> </form> My question is, how can I get this working in Safari?

    Read the article

  • Re-usable Obj-C classes with custom values: The right way

    - by Prairiedogg
    I'm trying to reuse a group of Obj-C clases between iPhone applications. The values that differ from app to app have been isolated and I'm trying to figure out the best way to apply these custom values to the classes on an app-to-app basis. Should I hold them in code? // I might have 10 customizable values for each class, that's a long signature! CarController *controller = [[CarController alloc] initWithFontName:@"Vroom" engine:@"Diesel" color:@"Red" number:11]; Should I store them in a big settings.plist? // Wasteful! I sometimes only use 2-3 of 50 settings! AllMyAppSettings *settings = [[AllMyAppSettings alloc] initFromDisk:@"settings.plist"]; MyCustomController *controller = [[MyCustomController alloc] initWithSettings:settings]; [settings release]; Should I have little, optional n_settings.plists for each class? // Sometimes I customize CarControllerSettings *carSettings = [[CarControllerSettings alloc] initFromDisk:@"car_settings.plist"]; CarController *controller = [[CarController alloc] initWithSettings:carSettings]; [carSettings release]; // Sometimes I don't, and CarController falls back to internally stored, reasonable defaults. CarController *controller = [[CarController alloc] initWithSettings:nil]; Or is there an OO solution that I'm not thinking of at all that would be better?

    Read the article

1