summaryrefslogtreecommitdiff
path: root/arduino_blog/models.py
blob: 97e60decf1a6095dd9b41a77c41e02d5b1b1c025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from django.db import models
from django.contrib.auth.models import User
from social.apps.django_app.default.models import UserSocialAuth
from django.core.validators import RegexValidator
import os
from datetime import datetime
from arduino_projects_website import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericRelation

position_choices = (
    ("student", "Student"),
    ("faculty", "Faculty")
)

gender = (
    ('Male', 'Male'),
    ('Female', 'Female'),
    ('Other', 'Other'),
)

source = (
    ("Poster", "Poster"),
    ("FOSSEE website", "FOSSEE website"),
    ("Google", "Google"),
    ("Social Media", "Social Media"),
    ("NMEICT Blended Workshop", "NMEICT Blended Workshop"),
    ("From other College", "From other College"),
)

title = (
    ("Mr", "Mr."),
    ("Miss", "Ms."),
    ("Professor", "Prof."),
    ("Doctor", "Dr."),
)
states = (
    ("IN-AP",    "Andhra Pradesh"),
    ("IN-AR",    "Arunachal Pradesh"),
    ("IN-AS",    "Assam"),
    ("IN-BR",    "Bihar"),
    ("IN-CT",    "Chhattisgarh"),
    ("IN-GA",    "Goa"),
    ("IN-GJ",    "Gujarat"),
    ("IN-HR",    "Haryana"),
    ("IN-HP",    "Himachal Pradesh"),
    ("IN-JK",    "Jammu and Kashmir"),
    ("IN-JH",    "Jharkhand"),
    ("IN-KA",    "Karnataka"),
    ("IN-KL",    "Kerala"),
    ("IN-MP",    "Madhya Pradesh"),
    ("IN-MH",    "Maharashtra"),
    ("IN-MN",    "Manipur"),
    ("IN-ML",    "Meghalaya"),
    ("IN-MZ",    "Mizoram"),
    ("IN-NL",    "Nagaland"),
    ("IN-OR",    "Odisha"),
    ("IN-PB",    "Punjab"),
    ("IN-RJ",    "Rajasthan"),
    ("IN-SK",    "Sikkim"),
    ("IN-TN",    "Tamil Nadu"),
    ("IN-TG",    "Telangana"),
    ("IN-TR",    "Tripura"),
    ("IN-UT",    "Uttarakhand"),
    ("IN-UP",    "Uttar Pradesh"),
    ("IN-WB",    "West Bengal"),
    ("IN-AN",    "Andaman and Nicobar Islands"),
    ("IN-CH",    "Chandigarh"),
    ("IN-DN",    "Dadra and Nagar Haveli"),
    ("IN-DD",    "Daman and Diu"),
    ("IN-DL",    "Delhi"),
    ("IN-LD",    "Lakshadweep"),
    ("IN-PY",    "Puducherry")
)


""" Base class created to collect creation date and modified date. Can be inherited in the other models """
class BaseClass(models.Model):
    date_created = models.DateTimeField(auto_now_add=True)
    date_modified = models.DateTimeField(auto_now=True)

    class Meta:
        abstract = True

class Profile(BaseClass):
    """Profile for users"""
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    #title = models.CharField(max_length=32, blank=True, choices=title)
    institute = models.CharField(max_length=150)
    #phone = models.CharField(max_length=10)
    position = models.CharField(max_length=32, choices=position_choices)
    how_did_you_hear_about_us = models.CharField(
        max_length=255, blank=True, choices=source)
    state = models.CharField(max_length=50, choices = states, blank=True)
    city = models.CharField(max_length=50, blank= True)
    pincode = models.CharField(max_length=6, blank =True)
    is_email_verified = models.BooleanField(default=False)
    activation_key = models.CharField(max_length=255, blank=True, null=True)
    key_expiry_time = models.DateTimeField(blank=True, null=True)

    def __str__(self):
        return u"id: {0}| {1} {2} | {3} ".format(
            self.user.id,
            self.user.first_name,
            self.user.last_name,
            self.user.email
        )

def get_document_dir(instance, filename):
    # ename, eext = instance.user.email.split("@")
    fname, fext = os.path.splitext(filename)
    # print "----------------->",instance.user
    return '%s/attachment/%s/%s.%s' % (instance.user, instance.proposal_type, fname+'_'+str(instance.user), fext)


class Comment(BaseClass):
    user = models.ForeignKey(User, on_delete=models.CASCADE,)
    body = models.CharField(max_length=500)
    is_public = models.BooleanField(default = False)
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey()

class Proposal(BaseClass):
    user = models.ForeignKey(User, on_delete=models.CASCADE,)
    name_of_author = models.CharField(max_length=200, default='None')
    about_the_author = models.TextField(max_length=500)
    email = models.CharField(max_length=128)
    title_of_the_project = models.CharField(max_length=250)
    abstract = models.TextField(max_length=700)
    references = models.CharField(max_length = 200, default = 'None')
    #attachment = models.FileField(upload_to=get_document_dir)
    status = models.CharField(max_length=100, default='Pending', editable=True)
    completion_date = models.DateTimeField(null=True, blank=True)
    approval_date = models.DateTimeField(null=True, blank=True)
    proposal_status = models.IntegerField(default=0, editable=True)
    #tags = models.CharField(max_length=250)
    terms_and_conditions = models.BooleanField(default= True)
    comment = GenericRelation(Comment)