class applicationAdminSerializer(serializers.ModelSerializer): module = moduleSerializer(read_only = True , many = False) owners = userSearchSerializer(read_only = True , many = True) class Meta: model = application fields = ( 'pk', 'name', 'module' , 'owners' , 'description' , 'created' , 'icon', 'canConfigure') def create(self , validated_data): app = application(**validated_data) app.module = module.objects.get(pk = self.context['request'].data['module']); app.save() return app def update (self, instance, validated_data): instance.owners.clear() for pk in self.context['request'].data['owners']: instance.owners.add(User.objects.get(pk = pk)) instance.save() return instance
class applicationAdminSerializer(serializers.ModelSerializer): module = moduleSerializer(read_only=True, many=False) owners = userSearchSerializer(read_only=True, many=True) class Meta: model = application fields = ('pk', 'name', 'module', 'owners', 'description', 'created', 'icon', 'canConfigure', 'haveJs', 'haveCss', 'inMenu') def create(self, validated_data): app = application(**validated_data) app.module = module.objects.get( pk=self.context['request'].data['module']) # create the folder too as well as the folowing structure # app # ---static # -----js # -----css # -----ngTemplates parts = app.name.split('.') appName = parts[1] if len(parts) >= 3: app.save() return app app.save() if len(app.name.split('.')) == 2: with lcd(globalSettings.BASE_DIR): cmd = 'python manage.py startapp %s' % (appName) local(cmd) # adding the new app definition in the settings.py and creating the folders and files fileName = os.path.join(globalSettings.BASE_DIR, 'libreERP', 'settings.py') # filepath for settings.py f = open(fileName, 'r') search = False lines = f.readlines() for l in lines: if l.find('INSTALLED_APPS') != -1: search = True if search: if l.find(')') != -1: index = lines.index(l) break lines.insert(index, ("\t'%s',# %s\n" % (appName, app.description))) f = open(fileName, "w") f.writelines(lines) f.close() os.makedirs(os.path.join(globalSettings.BASE_DIR, appName, 'static')) os.makedirs( os.path.join(globalSettings.BASE_DIR, appName, 'static', 'js')) os.makedirs( os.path.join(globalSettings.BASE_DIR, appName, 'static', 'css')) os.makedirs( os.path.join(globalSettings.BASE_DIR, appName, 'static', 'ngTemplates')) if app.haveJs: # create a JS file jsPath = os.path.join(globalSettings.BASE_DIR, appName, 'static', 'js', ('%s.js' % (app.name))) f = open(jsPath, 'w') f.write('// you need to first configure the states for this app') f.close() if app.haveCss: #create a css file too jsPath = os.path.join(globalSettings.BASE_DIR, appName, 'static', 'css', ('%s.css' % (app.name))) f = open(jsPath, 'w') f.write('/*here you can place all your app specific css class*/') f.close() app.save() return app def update(self, instance, validated_data): instance.owners.clear() for pk in self.context['request'].data['owners']: instance.owners.add(User.objects.get(pk=pk)) instance.save() return instance
class StoreSerializer(serializers.ModelSerializer): owner = userSearchSerializer(many=False, read_only=True) moderators = userSearchSerializer(many=True, read_only=True) editMode = serializers.SerializerMethodField() class Meta: model = Store fields = ('pk', 'created', 'company', 'name', 'address', 'pincode', 'mobile', 'email', 'gstin', 'gstincert', 'cin', 'personelid', 'owner', 'logo', 'copyrightHolder', 'fbLink', 'twitterLink', 'linkedinLink', 'playstoreLink', 'appstoreLink', 'pinterestLink', 'city', 'state', 'country', 'pos', 'cod', 'rating', 'filter', 'categoryBrowser', 'searchfieldplaceholder', 'codLimit', 'bankaccountNumber', 'ifsc', 'bankName', 'bankType', 'moderators', 'themeColor', 'payPal', 'paytm', 'payU', 'ccAvenue', 'googlePay', 'cartImage', 'paymentImage', 'paymentPotraitImage', 'searchBackgroundImg', 'blogBackgroundImg', 'logoinverted', 'editMode') read_only_fields = ('moderators', ) def get_editMode(self, obj): if Store.objects.filter(pk__lt=obj.pk).count() == 0: return 'full' else: if globalSettings.STORE_TYPE == 'MULTI-VENDOR': return 'companyDetails' elif globalSettings.STORE_TYPE == 'MULTI-PLATFORM': return 'full' else: return 'basic' def create(self, validated_data): s = Store(**validated_data) if 'owner' in self.context['request'].data and self.context[ 'request'].data['owner'] != 'undefined': s.owner = User.objects.get( pk=self.context['request'].data['owner']) s.save() if 'moderators' in self.context['request'].data: # objData = self.request['request'].data['moderators'] objData = str( self.context['request'].data['moderators']).split(',') for value in objData: s.moderators.add(User.objects.get(pk=value)) s.save() return s def update(self, instance, validated_data): for key in [ 'name', 'company', 'address', 'pincode', 'mobile', 'email', 'gstin', 'gstincert', 'cin', 'personelid', 'logo', 'copyrightHolder', 'fbLink', 'twitterLink', 'linkedinLink', 'playstoreLink', 'appstoreLink', 'pinterestLink', 'city', 'state', 'country', 'pos', 'cod', 'rating', 'filter', 'categoryBrowser', 'searchfieldplaceholder', 'codLimit', 'bankaccountNumber', 'ifsc', 'bankName', 'bankType', 'themeColor', 'payPal', 'paytm', 'payU', 'ccAvenue', 'googlePay', 'cartImage', 'paymentImage', 'paymentPotraitImage', 'searchBackgroundImg', 'blogBackgroundImg', 'logoinverted' ]: try: setattr(instance, key, validated_data[key]) except: pass if 'owner' in self.context['request'].data: instance.owner = User.objects.get( pk=self.context['request'].data['owner']) instance.save() if 'moderators' in self.context['request'].data: instance.moderators.clear() # objData = str(self.context['request'].data['moderators']) objData = str( self.context['request'].data['moderators']).split(',') for value in objData: instance.moderators.add(User.objects.get(pk=value)) instance.save() return instance
class StoreSerializer(serializers.ModelSerializer): owner = userSearchSerializer(many=False, read_only=True) moderators = userSearchSerializer(many=True, read_only=True) class Meta: model = Store fields = ('pk', 'created', 'company', 'name', 'address', 'pincode', 'mobile', 'email', 'gstin', 'gstincert', 'cin', 'personelid', 'owner', 'logo', 'copyrightHolder', 'fbLink', 'twitterLink', 'linkedinLink', 'playstoreLink', 'appstoreLink', 'pinterestLink', 'city', 'state', 'country', 'pos', 'cod', 'rating', 'filter', 'categoryBrowser', 'searchfieldplaceholder', 'codLimit', 'bankaccountNumber', 'ifsc', 'bankName', 'bankType', 'moderators', 'themeColor', 'payPal', 'paytm', 'payU', 'ccAvenue', 'googlePay', 'cartImage', 'paymentImage', 'paymentPotraitImage', 'searchBackgroundImg', 'blogBackgroundImg') read_only_fields = ('moderators', ) def create(self, validated_data): s = Store(**validated_data) if 'owner' in self.context['request'].data: s.owner = User.objects.get( pk=self.context['request'].data['owner']) s.save() if 'moderators' in self.context['request'].data: # objData = self.request['request'].data['moderators'] objData = str( self.context['request'].data['moderators']).split(',') for value in objData: s.moderators.add(User.objects.get(pk=value)) s.save() return s def update(self, instance, validated_data): for key in [ 'name', 'company', 'address', 'pincode', 'mobile', 'email', 'gstin', 'gstincert', 'cin', 'personelid', 'logo', 'copyrightHolder', 'fbLink', 'twitterLink', 'linkedinLink', 'playstoreLink', 'appstoreLink', 'pinterestLink', 'city', 'state', 'country', 'pos', 'cod', 'rating', 'filter', 'categoryBrowser', 'searchfieldplaceholder', 'codLimit', 'bankaccountNumber', 'ifsc', 'bankName', 'bankType', 'themeColor', 'payPal', 'paytm', 'payU', 'ccAvenue', 'googlePay', 'cartImage', 'paymentImage', 'paymentPotraitImage', 'searchBackgroundImg', 'blogBackgroundImg' ]: try: setattr(instance, key, validated_data[key]) except: pass if 'owner' in self.context['request'].data: instance.owner = User.objects.get( pk=self.context['request'].data['owner']) instance.save() if 'moderators' in self.context['request'].data: instance.moderators.clear() # objData = str(self.context['request'].data['moderators']) objData = str( self.context['request'].data['moderators']).split(',') for value in objData: instance.moderators.add(User.objects.get(pk=value)) instance.save() return instance