def create_wammu(request): ''' Compatibility interface for Wammu. ''' INVALID = 'Invalid values: %s' OKAY = 'Entry created, id=%d, url=/gammu/phonedb/%s/%d' OKAY_V2 = 'Entry created, id=%d, url=%s' invalid = [] version = 1 response = HttpResponse(content_type='text/plain') if 'irobot' not in request.POST or request.POST['irobot'] != 'wammu': invalid.append('irobot') if 'version' in request.POST: version = int(request.POST['version']) phone = Phone() try: phone.vendor = Vendor.objects.get(pk=int(request.POST['manufacturer'])) except: invalid.append('vendor') try: phone.name = request.POST['name'] if len(phone.name) == 0: invalid.append('name') except: invalid.append('name') try: phone.connection = Connection.objects.get( name=request.POST['connection']) except: invalid.append('connection') try: phone.model = request.POST['model'] if phone.model == 'auto': phone.model = '' except: invalid.append('model') try: phone.note = request.POST['note'] except: invalid.append('note') try: phone.author_name = request.POST['author_name'] except: invalid.append('author_name') try: phone.author_email = request.POST['author_email'] except: invalid.append('author_email') try: phone.email_garble = request.POST['email_garble'] if not phone.email_garble in [x[0] for x in GARBLE_CHOICES]: invalid.append('email_garble') except: invalid.append('email_garble') try: phone.gammu_version = request.POST['gammu_version'] except: invalid.append('gammu_version') try: phone.full_clean() except ValidationError as e: invalid.extend(e.message_dict.keys()) invalid = list(set(invalid)) if len(invalid) > 0: response.write(INVALID % ','.join(invalid)) return response features = [] for feature in Feature.objects.all(): key = 'fts[%s]' % feature.name if key in request.POST and request.POST[key] == '1': features.append(feature) phone.save() for feature in features: phone.features.add(feature) if version == 2: response.write(OKAY_V2 % (phone.id, phone.get_absolute_url())) else: response.write(OKAY % (phone.id, phone.vendor.slug, phone.id)) return response
def create_wammu(request): ''' Compatibility interface for Wammu. ''' INVALID = 'Invalid values: %s' OKAY = 'Entry created, id=%d, url=/gammu/phonedb/%s/%d' OKAY_V2 = 'Entry created, id=%d, url=%s' invalid = [] version = 1 response = HttpResponse(content_type='text/plain') if not request.POST.has_key('irobot') or request.POST['irobot'] != 'wammu': invalid.append('irobot') if request.POST.has_key('version'): version = int(request.POST['version']) phone = Phone() try: phone.vendor = Vendor.objects.get(pk=int(request.POST['manufacturer'])) except: invalid.append('vendor') try: phone.name = request.POST['name'] if len(phone.name) == 0: invalid.append('name') except: invalid.append('name') try: phone.connection = Connection.objects.get( name=request.POST['connection']) except: invalid.append('connection') try: phone.model = request.POST['model'] if phone.model == 'auto': phone.model = '' except: invalid.append('model') try: phone.note = request.POST['note'] except: invalid.append('note') try: phone.author_name = request.POST['author_name'] except: invalid.append('author_name') try: phone.author_email = request.POST['author_email'] except: invalid.append('author_email') try: phone.email_garble = request.POST['email_garble'] if not phone.email_garble in [x[0] for x in GARBLE_CHOICES]: invalid.append('email_garble') except: invalid.append('email_garble') try: phone.gammu_version = request.POST['gammu_version'] except: invalid.append('gammu_version') try: phone.full_clean() except ValidationError, e: invalid.extend(e.message_dict.keys()) invalid = list(set(invalid))
def create_wammu(request): ''' Compatibility interface for Wammu. ''' INVALID = 'Invalid values: %s' OKAY = 'Entry created, id=%d, url=/gammu/phonedb/%s/%d' OKAY_V2 = 'Entry created, id=%d, url=%s' invalid = [] version = 1 response = HttpResponse(content_type='text/plain') if 'irobot' not in request.POST or request.POST['irobot'] != 'wammu': invalid.append('irobot') if 'version' in request.POST: version = int(request.POST['version']) phone = Phone() try: phone.vendor = Vendor.objects.get(pk = int(request.POST['manufacturer'])) except: invalid.append('vendor') try: phone.name = request.POST['name'] if len(phone.name) == 0: invalid.append('name') except: invalid.append('name') try: phone.connection = Connection.objects.get(name = request.POST['connection']) except: invalid.append('connection') try: phone.model = request.POST['model'] if phone.model == 'auto': phone.model = '' except: invalid.append('model') try: phone.note = request.POST['note'] except: invalid.append('note') try: phone.author_name = request.POST['author_name'] except: invalid.append('author_name') try: phone.author_email = request.POST['author_email'] except: invalid.append('author_email') try: phone.email_garble = request.POST['email_garble'] if not phone.email_garble in [x[0] for x in GARBLE_CHOICES]: invalid.append('email_garble') except: invalid.append('email_garble') try: phone.gammu_version = request.POST['gammu_version'] except: invalid.append('gammu_version') try: phone.full_clean() except ValidationError as e: invalid.extend(e.message_dict.keys()) invalid = list(set(invalid)) if len(invalid) > 0: response.write(INVALID % ','.join(invalid)) return response features = [] for feature in Feature.objects.all(): key = 'fts[%s]' % feature.name if key in request.POST and request.POST[key] == '1': features.append(feature) phone.save() for feature in features: phone.features.add(feature) if version == 2: response.write(OKAY_V2 % (phone.id, phone.get_absolute_url())) else: response.write(OKAY % (phone.id, phone.vendor.slug, phone.id)) return response
def create_wammu(request): ''' Compatibility interface for Wammu. ''' INVALID = 'Invalid values: %s' OKAY = 'Entry created, id=%d, url=/gammu/phonedb/%s/%d' OKAY_V2 = 'Entry created, id=%d, url=%s' invalid = [] version = 1 response = HttpResponse(mimetype='text/plain') if not request.POST.has_key('irobot') or request.POST['irobot'] != 'wammu': invalid.append('irobot') if request.POST.has_key('version'): version = int(request.POST['version']) phone = Phone() try: phone.vendor = Vendor.objects.get(pk = int(request.POST['manufacturer'])) except: invalid.append('vendor') try: phone.name = request.POST['name'] if len(phone.name) == 0: invalid.append('name') except: invalid.append('name') try: phone.connection = Connection.objects.get(name = request.POST['connection']) except: invalid.append('connection') try: phone.model = request.POST['model'] if phone.model == 'auto': phone.model = '' except: invalid.append('model') try: phone.note = request.POST['note'] except: invalid.append('note') try: phone.author_name = request.POST['author_name'] except: invalid.append('author_name') try: phone.author_email = request.POST['author_email'] except: invalid.append('author_email') try: phone.email_garble = request.POST['email_garble'] if not phone.email_garble in [x[0] for x in GARBLE_CHOICES]: invalid.append('email_garble') except: invalid.append('email_garble') try: phone.gammu_version = request.POST['gammu_version'] except: invalid.append('gammu_version') try: phone.full_clean() except ValidationError, e: invalid.extend(e.message_dict.keys()) invalid = list(set(invalid))
def create_wammu(request): # noqa: C901 """ Compatibility interface for Wammu. """ invalid = [] version = 1 response = HttpResponse(content_type="text/plain") if "irobot" not in request.POST or request.POST["irobot"] != "wammu": invalid.append("irobot") if "version" in request.POST: version = int(request.POST["version"]) phone = Phone() try: phone.vendor = Vendor.objects.get(pk=int(request.POST["manufacturer"])) except Exception: invalid.append("vendor") try: phone.name = request.POST["name"] if len(phone.name) == 0: invalid.append("name") except Exception: invalid.append("name") try: phone.connection = Connection.objects.get( name=request.POST["connection"]) except Exception: invalid.append("connection") try: phone.model = request.POST["model"] if phone.model == "auto": phone.model = "" except Exception: invalid.append("model") try: phone.note = request.POST["note"] except Exception: invalid.append("note") try: phone.author_name = request.POST["author_name"] except Exception: invalid.append("author_name") try: phone.author_email = request.POST["author_email"] except Exception: invalid.append("author_email") try: phone.email_garble = request.POST["email_garble"] if phone.email_garble not in (x[0] for x in GARBLE_CHOICES): invalid.append("email_garble") except Exception: invalid.append("email_garble") try: phone.gammu_version = request.POST["gammu_version"] except Exception: invalid.append("gammu_version") try: phone.full_clean() except ValidationError as e: invalid.extend(e.message_dict.keys()) invalid = list(set(invalid)) if len(invalid) > 0: response.write(INVALID % ",".join(invalid)) return response features = [] for feature in Feature.objects.all(): key = "fts[%s]" % feature.name if key in request.POST and request.POST[key] == "1": features.append(feature) phone.save() for feature in features: phone.features.add(feature) if version == 2: response.write(OKAY_V2 % (phone.id, phone.get_absolute_url())) else: response.write(OKAY % (phone.id, phone.vendor.slug, phone.id)) return response