def cluster_by_platform(qs, app, feeling): # We need to create corpii for each platform and manually inspect each # opinion and put it in the right platform bucket. for platform in OS_USAGE: result = cluster_queryset(qs.filter(os=platform.short)) if result: dimensions = { 'product': app.id, 'feeling': feeling, 'platform': platform.short, } # Store the clusters into groups for group in result: if len(group.similars) < 5: continue topic = Theme(**dimensions) topic.num_opinions = len(group.similars) + 1 topic.pivot = group.primary topic.save() for s in group.similars: Item(theme=topic, opinion=s['object'], score=s['similarity']).save()
def save_result(result, dimensions): if result: for group in result: if (group.similars) < 5: continue topic = Theme(**dimensions) topic.num_opinions = len(group.similars) + 1 topic.pivot = group.primary topic.save() for s in group.similars: Item(theme=topic, opinion=s['object'], score=s['similarity']).save()
def upload_image(request): _, data = request.POST['image'].split(',') try: theme_id = request.POST['theme_id'] except: theme_id = -1 user = request.user.myuser if theme_id == -1: theme_name = request.POST['theme_name'] theme_content = request.POST['theme'] theme_description = request.POST['theme_description'] theme_private = request.POST['theme_private'] theme = Theme() theme.name = theme_name theme.operation = theme_content theme.owner = user theme.save() else: theme = get_object_or_404(Theme, id=theme_id) theme_private = "0" theme_description = "" post = ImagePost() post.user = user post.theme = theme post.description = theme_description if theme_private == "1": post.is_private = True else: post.is_private = False data = b64decode(data) image_name = str(uuid.uuid4()) + ".png" post.image = ContentFile(data, image_name) post.save() return HttpResponse("OK")
class ShopManager(models.Manager): def create(self, marketplace, name, admin, name_store): from geopy import geocoders from themes.models import Theme from preferences.models import Preference, DnsShop from blog_pages.models import Home, About, Menu, DynamicPageContent from themes.models import PAGES shop = Shop(marketplace=marketplace, name=name, admin=admin) profile = admin.get_profile() try: #get the geoposition according to the shop address g = geocoders.Google(settings.GOOGLE_KEY) place = "%s, %s, %s, %s" % (profile.street_address, profile.city, profile.state, profile.country) place, point = g.geocode(place) shop.location = "%s,%s" % point except Exception, e: logging.critical(e) shop.save() Theme.create_default(shop) """ Create Static Pages for this shop """ Home(shop=shop).save() About(shop=shop).save() """ Create Content for Dynamic Pages for this shop """ for page in PAGES: DynamicPageContent(shop=shop, page=page, meta_content=page).save() """ Create Default MENU """ Menu.create_default(shop) """ Create DNS default """ dns = DnsShop(shop=shop, dns="%s.%s" % (shop.name, settings.DEFAULT_DNS), default=True) dns.save() """ Create preference to shop """ preference = Preference(shop=shop, name_store=name_store) preference.save() return shop
def create(): body = request.get_json() if not 'invoice' in body: return '"invoice" parameter is missing', 400 if not 'customer' in body['invoice']: return '"customer" parameter is missing', 400 project = None if 'project' in body: project = Project.find_by_id(body['project']) customer = None if 'email' in body['invoice']['customer']: customer = Customer.find_by_email(body['invoice']['customer']['email']) if not customer and 'name' not in body['invoice']['customer']: return '"customer" not found', 404 elif 'id' in body['invoice']['customer']: customer = Customer.find_by_id(body['invoice']['customer']['id']) if not customer: return '"customer" not found', 404 if not customer: if not 'name' in body['invoice']['customer']: return '"customer.name" is required when creating one', 400 customer = Customer.create(body['invoice']['customer']) invoice = Invoice('INVOICE', customer, project) invoice.currency = body['invoice']['currency'] if 'currency' in body['invoice'] else invoice.project.default_currency invoice.message = body['invoice']['message'] if 'message' in body['invoice'] else None invoice.due = body['invoice']['due'] if 'due' in body['invoice'] else None if 'reference' in body['invoice']: invoice.reference = body['invoice']['reference'] else: try: invoice.set_reference() except IntegrityError: return 'Invalid Reference number given', 400 if 'theme' in body: theme = Theme.find_by_id(body['theme']) if not theme: return "Invalid Theme ID : Theme not found", 404 invoice.theme_id = theme.id invoice.theme = theme invoice.save() # Adding meta data for item in body['invoice']: if item in ['customer', 'currency', 'message', 'due', 'reference', 'entries', 'discounts', 'payments','refunds','notes','paid']: continue; InvoiceMeta.create(invoice, item, body['invoice'][item]) if 'entries' in body['invoice']: entry_index = 1 for entry in body['invoice']['entries']: if not 'description' in entry: return abort(400) if not 'amount' in entry: return abort(400) InvoiceEntry.create(invoice, entry, body['invoice']['tax'] if 'tax' in body['invoice'] else None, entry_index) entry_index += 1 if 'discounts' in body['invoice']: for discount in body['invoice']['discounts']: if not 'amount' in discount: return abort(400) if not 'mode' in discount or discount['mode'] not in ['PERCENTAGE', 'FIXED']: return abort(400) if not 'option' in discount or discount['option'] not in ['SUBTOTAL', 'TOTAL']: discount['option'] = 'SUBTOTAL' InvoiceDiscount.create(invoice, discount) if 'payments' in body['invoice']: for payment in body['invoice']['payments']: if not 'amount' in payment: return abort(400) InvoicePayment.create(invoice, payment['amount']) if 'refunds' in body['invoice']: for refund in body['invoice']['refunds']: if not 'amount' in refund: return abort(400) InvoiceRefund.create(invoice, refund) if 'notes' in body['invoice']: for note in body['invoice']['notes']: if not 'description' in note: return abort(400) InvoiceNote.create(invoice, note['description']) if 'send' in body: # TODO later pass return jsonify(invoice.to_json()), 200